/[cvs]/nfo/php/libs/org.netfrag.elib/lib_variables.php.inc
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.elib/lib_variables.php.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Wed Jan 23 17:40:34 2002 UTC (22 years, 5 months ago) by cvsjoko
Branch: nfo, MAIN
CVS Tags: v003, HEAD
Changes since 1.1: +0 -0 lines
initial

1 cvsjoko 1.1 <?
2    
3     class MetaItem {
4    
5     var $isMetaItem;
6     var $attributes;
7    
8     function MetaItem($got_attributes) {
9     global $glbl_MetaItem_refs;
10     $glbl_MetaItem_refs[$got_attributes['name']] = &$this;
11     $this->isMetaItem = 1;
12     $this->attributes = $got_attributes;
13     }
14    
15     function getAttribute($name) {
16     if ( isset($this->attributes[$name]) ) {
17     return $this->attributes[$name];
18     }
19     }
20    
21     function getAttributes() {
22     global $glbl_MetaItem_refs;
23     return $glbl_MetaItem_refs[$this->attributes['name']]->attributes;
24     }
25    
26     function setAttribute($name, $value) {
27     global $glbl_MetaItem_refs;
28     $glbl_MetaItem_refs[$this->attributes['name']]->attributes[$name] = $value;
29     }
30    
31     }
32    
33     class ItemIterator {
34     var $items;
35     var $index;
36    
37     function ItemIterator($got_items) {
38     $this->items = $got_items;
39     reset($this->items);
40     $this->index = 0;
41     }
42    
43     function getItem() {
44     return $this->items[$this->index];
45     }
46    
47     function EOF() {
48     if ( $this->index >= count($this->items) ) {
49     return 1;
50     } else {
51     return 0;
52     }
53     }
54    
55     function MoveNext() {
56     $this->index++;
57     }
58    
59     }
60    
61     class InformationCluster {
62    
63     var $Attribs;
64     var $MetaItems_idxHash;
65    
66     function InformationCluster($attribs) {
67     $this->Attribs = $attribs;
68     $this->updateIndex();
69     }
70    
71     function updateIndex() {
72     // build index
73     $miai = $this->getMetaItemsIterator();
74     while( !$miai->EOF() ) {
75     $mi = $miai->getItem();
76     //print $mi->getAttribute('name') . "<br>";
77     $this->MetaItems_idxHash[$mi->getAttribute('name')] = $mi;
78     $miai->MoveNext();
79     }
80     }
81    
82     function getAttributes() {
83     return $this->Attribs;
84     }
85    
86     function getMetaItem($name) {
87     if ( isset($this->MetaItems_idxHash[$name]) ) {
88     return $this->MetaItems_idxHash[$name];
89     }
90     }
91    
92     function getMetaItems() {
93     return $this->Attribs['meta'];
94     }
95    
96     function getMetaItemsIterator() {
97     return new ItemIterator( $this->getMetaItems() );
98     }
99    
100     function getValuesToHash() {
101     $hash = array();
102     $ici = $this->getMetaItemsIterator();
103     while( !$ici->EOF() ) {
104     $curItem = $ici->getItem();
105     $attribs = $curItem->getAttributes();
106     $hash[$attribs['name']] = $attribs['value'];
107     $ici->MoveNext();
108     }
109     return $hash;
110     }
111    
112     function setValuesFromHash($hash) {
113     if ( is_array($hash) ) {
114     $ici = $this->getMetaItemsIterator();
115     while( !$ici->EOF() ) {
116     $curItem = $ici->getItem();
117     $attribs = $curItem->getAttributes();
118     $value = $hash[$attribs['name']];
119     $curItem->setAttribute('value', $value);
120     $ici->MoveNext();
121     }
122     }
123     }
124    
125     function save($data) {
126     $this->Attribs['persistency_handler']->save($data);
127     }
128    
129     function load() {
130     return $this->Attribs['persistency_handler']->load();
131     }
132    
133     }
134    
135    
136    
137    
138    
139     // todo: "hashes"
140     function getValueByVarname($varname) {
141     $evstring = 'global $' . $varname . ';';
142     eval($evstring);
143     $evstring = 'return $' . $varname . ';';
144     return eval($evstring);
145     }
146    
147     // todo: "hashes"
148     function setValueByVarname($varname, $value) {
149     $evstring = 'global $' . $varname . ';';
150     eval($evstring);
151     $$varname = $value;
152     }
153    
154     function NameSpaceVarname2PhpVarnameHashPart($varname_ns = 'dummy') {
155    
156     // split variable-name by namespace-delimiter
157     $varname_parts = split('::', $varname_ns);
158    
159     // initialize return-value
160     $varname_php = '';
161    
162     // build return-value
163     for ($i = 0; $i < count($varname_parts); $i++) {
164     $varname_php .= "['$varname_parts[$i]']";
165     }
166    
167     return $varname_php;
168    
169     }
170    
171    
172     function getAttribStringFromHash($hash, $ItemDelimiter, $ItemValueDelimiter, $FieldEncapsulation) {
173     $retval = '';
174     if (is_array($hash)) {
175     while( list($key, $value) = each($hash) ) {
176     $retval .= $key . $ItemValueDelimiter . $FieldEncapsulation . $value . $FieldEncapsulation . $ItemDelimiter;
177     }
178     $retval = substr($retval, 0, strlen($retval) - strlen($ItemDelimiter));
179     }
180     return $retval;
181     }
182    
183     function HashValuesToHashKeys($hash) {
184     $retval = array();
185     while(list($key, $value) = each($hash)) {
186     $retval[$value] = $value;
187     }
188     return $retval;
189     }
190    
191    
192    
193    
194    
195    
196    
197    
198     function nestedHash2simpleHash_getKeyString($array_keys, $bool_strip_first = 0) {
199    
200     $retval = '';
201    
202     $item_first = array_shift($array_keys);
203     if (!$bool_strip_first) {
204     $retval = $item_first;
205     }
206    
207     reset($array_keys);
208     while($item = current($array_keys)) {
209     if ($bool_strip_first) {
210     $retval .= "[$item]";
211     } else {
212     $retval .= "$item";
213     }
214     next($array_keys);
215     }
216     return $retval;
217    
218     }
219    
220    
221     function nestedHash2simpleHash($complexHash, $bool_recursive, &$subkeys) {
222    
223     $simpleHash = array();
224    
225     while( list($key, $value) = each($complexHash) ) {
226     if (is_array($value)) {
227     array_push($subkeys, $key);
228     $hash_simple = nestedHash2simpleHash($value, 1, &$subkeys);
229    
230     while(list($key2, $value2) = each($hash_simple)) {
231     array_push($subkeys, $key2);
232     $subkeys_string = nestedHash2simpleHash_getKeyString($subkeys, $bool_recursive);
233     $key_built = $subkeys_string;
234     $simpleHash[$key_built] = $value2;
235     array_pop($subkeys);
236     }
237    
238     array_pop($subkeys);
239    
240     } else {
241     $simpleHash[$key] = $value;
242     }
243     }
244    
245     return $simpleHash;
246    
247     }
248    
249    
250    
251    
252    
253     function dumpVar_get($variable, $variablename = '', $outputType = 'html') {
254    
255     // get variable-dump to string
256     ob_start();
257     print $variablename . ' = ';
258     print_r($variable);
259     print "\n";
260     $retval = ob_get_contents();
261     ob_end_clean();
262    
263     switch($outputType) {
264     case 'html':
265     $retval = nl2br( str_replace(' ', '&nbsp;', htmlentities($retval)) );
266     break;
267     default:
268     break;
269     }
270    
271     return $retval;
272    
273     }
274    
275     function dumpVar($variable, $variablename = '', $outputType = 'html') {
276     print dumpVar_get($variable, $variablename, $outputType);
277     }
278    
279    
280     function createHash($keys = array(), $values = array()) {
281    
282     if (!is_array($keys) || !is_array($values)) { return; }
283    
284     $hash = array();
285     reset($keys);
286     $i = 0;
287     while($key = current($keys)) {
288     $hash[$key] = '';
289     if (isset($values[$i])) { $hash[$key] = $values[$i]; }
290     next($keys);
291     $i++;
292     }
293     return $hash;
294     }
295    
296    
297     function modifyItem_prefix(&$item, $key, $prefix) {
298     $item = "$prefix$item";
299     }
300     function modifyItem_postfix(&$item, $key, $postfix) {
301     $item = "$item$postfix";
302     }
303    
304     function modifyArray(&$array, $args = array()) {
305     if (isset($args['prefix'])) {
306     array_walk($array, 'modifyItem_prefix', $args['prefix']);
307     }
308     if (isset($args['postfix'])) {
309     array_walk($array, 'modifyItem_postfix', $args['postfix']);
310     }
311     return $array;
312     }
313    
314     function valueSmartComplete($value, $vartype) {
315    
316     $retval = $value;
317    
318     switch($vartype) {
319     case "Date":
320    
321     // date-format seems to be okay
322     // noop!
323    
324     // just four digits, assume year
325     if (strlen($retval) == 4) {
326     $retval .= "-01-01";
327     }
328    
329     // just two digits, assume year
330     if (strlen($retval) == 2) {
331     // assume "19xx"
332     if ($retval > 50) {
333     $retval = "19" . $retval;
334     } else {
335     $retval = "20" . $retval;
336     }
337     $retval .= "-01-01";
338     }
339    
340     break;
341     }
342    
343     return $retval;
344    
345     }
346    
347     function expandVariant(&$variant, $appendValue) {
348     if (is_array($variant)) {
349     array_push($variant, $appendValue);
350     } else {
351     $scalarvalue = $variant;
352     $variant = array($scalarvalue, $appendValue);
353     }
354     }
355    
356     function shortenDisplayString($string, $length = 0) {
357     if ( ($length) && (strlen($string) > $length) ) {
358     $string = substr($string, 0, $length - 3) . " ...";
359     }
360     return $string;
361     }
362    
363     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed