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

Contents of /nfo/php/libs/org.netfrag.elib/vops/objects.php.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Wed Jan 23 17:40:37 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 <?
2
3 // ==============================================================
4 class DSAbstractObject {
5
6 // the type of this object
7 var $type;
8
9 // the name of the object-key
10 var $objectkey_name;
11
12 // the (virtual) attributes
13 var $attributes;
14
15 // references to other/new objects
16 // a reference to a "DSSession"-object which will be passed in "from outside" by the "DSEngine"
17 var $ref_session;
18 // a "DataQuery"-object instantiated in the constructor later
19 var $ref_dataquery;
20 // a reference to a "PDLModelObject"-object, which will be initialized in the constructor from "$ref_session"
21 var $ref_pdlModelObject;
22 // a reference to a list (array) of "PDLModelObject"-attributes ("PDLModelObjectAttribute"s)
23 var $ref_pdlModelObjectAttributes;
24
25 // miscellanious other variables
26
27 // some state-information
28 var $bool_unbound; // no binding to database yet
29 var $bool_created; // created for being a new object
30
31 var $pdlEventName;
32 var $pdlEventName_CurrentObjectOperation;
33 var $dsType;
34
35 // metainfo about this object
36 //var $metainfo;
37
38 // ---------------------------------------------------------------------------------------
39 function DSAbstractObject($type, $eventIdentifier, &$ref_session) {
40
41 // initialize most important information for an object :-)
42 $this->type = $type;
43 $this->ref_session =& $ref_session;
44 $this->ref_pdlModelObject =& $this->ref_session->pdlengine->getPDLObject($type);
45 $this->ref_pdlModelObjectAttributes =& $this->ref_pdlModelObject->attributes;
46 $this->objectkey_name = $this->ref_pdlModelObject->objectkey;
47
48 $this->_initAttributes();
49
50 // initialize object-state (-> "this is a new object")
51 $this->bool_unbound = 1;
52 $this->bool_created = 1;
53
54 $this->pdlEventName = 'retrieve ' . $eventIdentifier;
55 $this->pdlEventName_CurrentObjectOperation = '';
56 if ($eventIdentifier == 'all') {
57 $this->dsType = 'DSDataCollection';
58 } else {
59 $this->dsType = 'DSDataObject';
60 }
61
62 // create a new "DataQuery"-object and store reference
63 $this->ref_dataquery =& new DataQuery();
64
65 }
66
67
68
69 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70 // PROTOTYPES?
71 // TODO: silly idea with the prototypes in here, in fact most of these are
72 // very specialized methods of "DSDataObject" which have nothing lost in "DSDataCollection"
73
74 // attribute-operations
75 //function get() { }
76 //function set() { }
77
78 // object-key-operations
79 function getObjectKeyName() { return $this->_getObjectKeyName(); }
80 function getObjectKey() { return $this->_getObjectKey(); }
81 function setObjectKey($value) { return $this->_setObjectKey($value); }
82 function hasObjectKey() { return $this->_hasObjectKey(); }
83
84 // object-operations
85 //function load() { }
86 //function save() { }
87 //function delete() { }
88 function fill($attributes_new) { $this->_fill($attributes_new); }
89 function reset() { $this->_reset(); }
90 function unbind() { $this->_unbind(); }
91
92
93 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
94 // ATTRIBUTE-OPERATIONS (get/set)
95
96 // ---------------------------------------------------------------------------------------
97 function _getAttribute($attribute_name) {
98 if (isset($this->attributes[$attribute_name])) {
99 $value = $this->attributes[$attribute_name];
100
101 if (isset($this->ref_pdlModelObjectAttributes)) {
102 switch ($this->ref_pdlModelObjectAttributes[$attribute_name]->type) {
103 case 'Date':
104 // modify date from english/american format to german one
105 //$value = join('-', array_reverse( split('.', $value) ));
106 $value = convertDate($value, 'german');
107 break;
108 }
109 }
110
111 return $value;
112 }
113 }
114
115 function _setAttribute($attribute_name, $value) {
116
117 if (isset($this->ref_pdlModelObjectAttributes)) {
118 switch ($this->ref_pdlModelObjectAttributes[$attribute_name]->type) {
119 case 'Date':
120 // modify date from english/american format to german one
121 //$value = join('-', array_reverse( split('.', $value) ));
122 $value = convertDate($value, 'english');
123 break;
124 }
125 }
126
127 $this->attributes[$attribute_name] = $value;
128 }
129
130 function _existsAttribute($attribute_name) {
131 return isset($this->attributes[$attribute_name]);
132 }
133
134 // ---------------------------------------------------------------------------------------
135 function _initAttributes() {
136 $attribute_names = array_keys($this->ref_pdlModelObjectAttributes);
137 $this->attributes = createHash($attribute_names);
138 }
139
140 // ---------------------------------------------------------------------------------------
141 function _checkAttributeAccess($attribute_name, $access_mode) {
142
143 /*
144 remarks for attribute-access-checking: is the following mechanism okay?
145 - always (maybe first): check for attribute-existance
146 - read-mode:
147 - if the object is new (objectkey == '<new>'), return no value
148 - write-mode:
149 - if the object has no object-key: continue work
150 - if the object has got one or more object-key(s):
151 - if the object is bound: continue work
152 - if the object is not bound: check if all object-keys are set first before accessing other attributes
153 */
154
155 if (!$this->_existsAttribute($attribute_name)) {
156 print "<font color=\"red\">Could not access attribute \"$attribute_name\" (operation: \"$access_mode\") in object \"{$this->type}\". Attribute does not exist.</font><br>";
157 return 0;
158 }
159
160
161 switch ($access_mode) {
162
163 // - - - - - - - - - - - -
164 case 'read':
165 // is this a new object?
166 if ( $this->getObjectKey() == '<new>' ) {
167 //return $this->_getAttribute($attribute_name);
168 return 0;
169 }
170 break;
171
172 // - - - - - - - - - - - -
173 case 'write':
174 // if this object is unbound, just allow access to the object-key(s)
175 // this is needed to load a single object in order to set the object-id for loading
176
177 // check for object-key
178 if ($this->objectkey_name) {
179 if ($this->bool_unbound) {
180 if ($attribute_name != $this->objectkey_name) {
181 print "<font color=\"red\">Could not access attribute \"$attribute_name\" for setting in object-type \"{$this->type}\", because the object is unbound, not new, ";
182 print "and \"$attribute_name\" is not the object-key.</font><br>";
183 return 0;
184 }
185 }
186 } else {
187 // object has got no object-key: continue work
188 }
189
190 break;
191 }
192
193 return 1;
194 }
195
196
197
198 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
199 // OBJECT-KEY-OPERATIONS
200
201 // ---------------------------------------------------------------------------------------
202 // returns the attribute-name of the object-key
203 function _getObjectKeyName() {
204 // get name of key
205 return $this->objectkey_name;
206 }
207
208 // ---------------------------------------------------------------------------------------
209 // returns the attribute-value of the object-key
210 function _getObjectKey() {
211
212 // get value of key
213 $objectkey = $this->_getAttribute($this->objectkey_name);
214
215 if ($objectkey) {
216 return $objectkey;
217 } else {
218 // HACK: !?
219 //return "<new>";
220 return "<undefined>";
221 }
222 }
223
224 // ---------------------------------------------------------------------------------------
225 // sets the attribute-value of the object-key
226 function _setObjectKey($value) {
227 // set value of key
228 $this->_setAttribute($this->objectkey_name, $value);
229 }
230
231 // ---------------------------------------------------------------------------------------
232 // has this object an object-key?
233 function _hasObjectKey() {
234 if ($this->objectkey_name) { return 1; }
235 }
236
237
238
239 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
240 // OBJECT-OPERATIONS (load/save/delete/reset/fill)
241
242 // ---------------------------------------------------------------------------------------
243 function _setupDataQuery($eventname) {
244
245 if (!$eventname) {
246 print "<font color=\"red\">Could not initiate any action on object \"{$this->type}\", because the eventname specified was empty. This is needed for getting the proper metadata to execute the object-operation.</font><br>";
247 return;
248 }
249
250 // set class-variables
251 $this->pdlEventName_CurrentObjectOperation = $eventname;
252
253 // get pdl for current event from "PDLModelObject"
254 if (!isset($this->ref_pdlModelObject->events[$eventname])) {
255 trigger_error("DSDataObject->_validateOperation_Object(): Could not find PDLModelEvent \"$eventname\" for object-type \"$this->type\"", E_USER_ERROR);
256 }
257 $unreadySql = $this->ref_pdlModelObject->events[$eventname]->get_unreadySql();
258
259 // initialize "DataQuery"s map-part with mapping-informations
260 $this->ref_dataquery->setMap($this->ref_pdlModelObjectAttributes);
261
262 // initialize "DataQuery"s sql-part with the "unready" sql-statement
263 $this->ref_dataquery->setQuery($unreadySql);
264
265 return 1;
266
267 }
268
269 // ---------------------------------------------------------------------------------------
270 function _validateOperation_Object($operation_mode) {
271
272 // first, distinguish between "DSDataObject" and "DSDataCollection"
273 switch($this->dsType) {
274 case 'DSDataObject':
275 if (!$this->hasObjectKey()) {
276 // TODO: CHECK THIS!!!
277 //print "<font color=\"red\">Could not initiate object-operation \"$operation_mode\" on object \"{$this->type}\", because \"{$this->type}\" seems to have no object-key.</font><br>";
278 //return;
279 }
280 break;
281 case 'DSDataCollection':
282 break;
283 }
284
285 return 1;
286
287 }
288
289 // ---------------------------------------------------------------------------------------
290 function _validateOperation_Attributes($operation_mode) {
291
292 /*
293 object-key-juggling, we must handle a few things:
294 - does this object has got object-keys or not?
295 - and if it has - are they valid and stuff?
296 */
297
298 switch($operation_mode) {
299
300 // - - - - - - - - - - - -
301 case 'load':
302 if ($this->hasObjectKey()) {
303 $objectkey = $this->getObjectKey();
304 // define here what shall happen if an object with key "<undefined>" gets a load-request
305 if ($objectkey == '<undefined>') {
306 print "<font color=\"red\">Could not load object with object-type \"{$this->type}\", because the object-key \"{$this->objectkey_name}\" was \"undefined\".</font><br>";
307 return;
308 }
309 // define here what shall happen if an object with key "<new>" gets a load-request
310 if ($objectkey == '<new>') {
311 print "<font color=\"red\">Could not load object with object-type \"{$this->type}\", because the object-key \"{$this->objectkey_name}\" was \"new\".</font><br>";
312 return;
313 }
314 }
315 break;
316
317 // - - - - - - - - - - - -
318 case 'save':
319
320 if ($this->hasObjectKey()) {
321 $objectkey = $this->getObjectKey();
322 // define here what shall happen if an object with key "<undefined>" gets a save-request
323 if ($objectkey == '<undefined>') {
324 print "<font color=\"red\">Could not save object with object-type \"{$this->type}\", because the object-key \"{$this->objectkey_name}\" was \"undefined\".</font><br>";
325 return;
326 }
327 // define here what shall happen if an object with key "<new>" gets a save-request
328 if ($objectkey == '<new>') {
329 //print "<font color=\"red\">Could not save object with object-type \"{$this->type}\", because the object-key \"{$this->objectkey_name}\" was \"new\".</font><br>";
330 //return;
331 // overwrite the value of the objectkey-attribute
332 $this->setObjectKey('null');
333 }
334 }
335
336 break;
337
338 }
339
340 return 1;
341
342 }
343
344
345 // ---------------------------------------------------------------------------------------
346 function _load_startup() {
347
348 // if this object is already bound, we will skip loading it again
349 // TODO: if not "bool_dirty"
350 if (!$this->bool_unbound) { return; }
351
352 // set object-state
353 $this->bool_unbound = 0;
354 $this->bool_created = 0;
355
356 $bool_operation_ok = ( ($this->_validateOperation_Object('load')) && ($this->_setupDataQuery($this->pdlEventName)) );
357 return $bool_operation_ok;
358
359 }
360
361 // ---------------------------------------------------------------------------------------
362 function _save_startup() {
363
364 //print "save: " . "bu: " . $this->bool_unbound . "; " . "bc: " . $this->bool_created . "\n";
365
366 // - - - - - - - - - - - - - - - - - - - - - - - - - - -
367 // determine pdl-event
368 $eventname = '';
369 // actual insert
370 if ($this->bool_unbound && $this->bool_created) {
371 $eventname = 'add';
372 }
373 // actual update
374 if (!$this->bool_unbound && !$this->bool_created) {
375 $eventname = 'update';
376 }
377
378 // if this object is already bound, we will skip loading it again
379 // TODO: if not "bool_dirty"
380 //if (!$this->bool_unbound) { return; }
381
382 // set object-state
383 //$this->bool_unbound = 0;
384 //$this->bool_created = 0;
385
386 $bool_operation_ok = ( ($this->_validateOperation_Object('save')) && ($this->_setupDataQuery($eventname)) );
387 return $bool_operation_ok;
388
389 }
390
391 // ---------------------------------------------------------------------------------------
392 function _delete_startup() {
393 $eventname = 'remove';
394 $bool_operation_ok = ( ($this->_validateOperation_Object('delete')) && ($this->_setupDataQuery($eventname)) );
395 return $bool_operation_ok;
396 }
397
398 // ---------------------------------------------------------------------------------------
399 function _fill($attributes_new) {
400
401 // save all attribute-names in case the new ones are incomplete
402 $attribute_names = array_keys($this->attributes);
403
404 // overwrite original attributes with new ones
405 $this->attributes = array_merge(createHash($attribute_names), $attributes_new);
406
407 // set object-state
408 if ($this->hasObjectKey()) {
409 switch($this->getObjectKey()) {
410 case '<undefined>':
411 break;
412 case '<new>':
413 break;
414 case '':
415 break;
416 // yeah, the object-key is set to a valid value, so we declare this object as "bound"
417 default:
418 $this->bool_unbound = 0;
419 //print "-------------fill<br>";
420 //$this->_load_startup();
421 //$this->_setupDataQuery($this->pdlEventName);
422 //print ".-...............pdl: " . $this->pdlEventName;
423 //$this->filters = array();
424 //$this->ref_dataquery->clearCriterias();
425 //$this->reset();
426 break;
427 }
428 }
429
430 }
431
432 // ---------------------------------------------------------------------------------------
433 // declares this object as "unbound" (not loaded)
434 function _unbind() {
435 $this->bool_unbound = 1;
436 }
437
438 // ---------------------------------------------------------------------------------------
439 // declares this object as "unbound" (not loaded)
440 function _reset() {
441 $this->_unbind();
442 }
443
444 }
445
446
447
448
449
450 // ==============================================================
451 class DSDataObject extends DSAbstractObject {
452
453
454 // ---------------------------------------------------------------------------------------
455 function DSDataObject($type, &$ref_session) {
456 // debugging
457 slog("DSDataObject: new DSDataObject($type)");
458 parent::DSAbstractObject($type, 'single', &$ref_session);
459 }
460
461
462
463 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
464 // ATTRIBUTE-OPERATIONS (get/set)
465
466
467 // ---------------------------------------------------------------------------------------
468 function get($attribute_name) {
469
470 // debugging
471 slog("DSDataObject: get($attribute_name)");
472
473 // attribute-access!?
474 if (!$this->_checkAttributeAccess($attribute_name, 'read')) { return; }
475
476 // is this object unbound? if yes, try an implicit load!
477 if ( ($this->bool_unbound) && ($this->hasObjectKey()) ) {
478 // we have to pre-check here if the object we want to load implicitely has got an object key - else this wouldn't make sense ...
479 // ... the reason for this case is maybe because "DSDataCollection" did a "fill" on a "DSDataObject" so this object is "unbound", too
480 // the normal case is that a "DSDataObject" is "unbound", so it will get an implicit "load"-request when it recieved an attribute-"get"-request here
481 // the "forbidden" load of an object without object-key is also checked later in "->_validateOperation_Object()",
482 // but there the operation is cancelled with an error, here we can prevent this :-)
483 $this->load();
484 }
485
486 // TODO: other DataCollections ( for "Associations"-functionality :-) )
487
488 // TODO/HACK: this comparison doesn't ensure completely if an attribute-value is set or not ( imagine "0" (zero)!!! )
489 if ( $retval = $this->_getAttribute($attribute_name) ) {
490 return $retval;
491 }
492
493 }
494
495
496 // ---------------------------------------------------------------------------------------
497 function set($attribute_name, $value) {
498
499 // attribute-access!?
500 if (!$this->_checkAttributeAccess($attribute_name, 'write')) { return; }
501
502 slog("DSDataObject: set($attribute_name, $value)");
503 // TODO (MUST): other DataCollections
504
505 $this->_setAttribute($attribute_name, $value);
506 }
507
508 // ---------------------------------------------------------------------------------------
509 function getAll_old() {
510 slog("DSDataObject: getAll()");
511 return $this->attributes;
512 }
513
514 function setAll_old($attributes) {
515 slog("DSDataObject: setAll($attributes)");
516 $this->attributes = $attributes;
517 }
518
519
520
521 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
522 // OBJECT-OPERATIONS (load/save/delete/reset/fill)
523
524
525 // ---------------------------------------------------------------------------------------
526 function load() {
527
528 if (!$this->_load_startup()) { return; }
529
530 // validate attributes to assure a good object-operation
531 if (!$this->_validateOperation_Attributes('load')) {
532 print "<font color=\"red\">DSDataObject->_validateOperation_Attributes('load') for \"{$this->type}\" failed.</font><br>";
533 }
534
535 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
536 // add criteria-information to the "DataQuery" to limit the result to this single object/entry
537 // HACK!!! move this functionality (':') to "...->addCriteria?)
538 $this->ref_dataquery->addCriteria(':' . $this->objectkey_name . ' = ' . $this->getObjectKey());
539
540
541 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
542 // retrieve data
543
544 // execute the "DataQuery"
545 $this->ref_dataquery->query();
546
547 // get next (first) item of result(s)
548 if ($this->ref_dataquery->next()) {
549
550 // initialize attributes with loaded values
551 $attributes_loaded =& $this->ref_dataquery->getResult();
552
553 // fill ourself with attributes
554 $this->fill($attributes_loaded);
555
556 return 1;
557 }
558
559 }
560
561
562 // ---------------------------------------------------------------------------------------
563 function save() {
564
565 if (!$this->_save_startup()) { return; }
566
567 // catch all vars to save this object
568 $this->save_catchAllVars();
569
570 // validate attributes to assure a good object-operation
571 if (!$this->_validateOperation_Attributes('save')) {
572 print "<font color=\"red\">DSDataObject->_validateOperation_Attributes('save') for \"{$this->type}\" failed.</font><br>";
573 }
574
575 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
576 // add criteria-information to the "DataQuery" to limit the result to this single object/entry
577 // HACK!!! move this functionality (':') to "...->addCriteria?)
578 //$this->ref_dataquery->addCriteria(':' . $this->objectkey_name . ' = ' . $objectkey);
579
580 //print $this->ref_dataquery->getSql() . "<br>";
581 //print "save<br>";
582 //exit;
583
584 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
585 // save data
586
587 // execute the "DataQuery"
588 $this->ref_dataquery->setData($this->attributes);
589 $this->ref_dataquery->query();
590
591 // TODO: review this mechanism!
592 // patch object-key if this was a create-operation, because new object-keys are provided by the underlying rdbms here
593 if ($this->pdlEventName_CurrentObjectOperation == 'add') {
594 $this->setObjectKey($this->ref_dataquery->lastInsertId);
595 }
596
597 }
598
599
600 // ---------------------------------------------------------------------------------------
601 function delete() {
602
603 if (!$this->_delete_startup()) { return; }
604 $this->ref_dataquery->query();
605
606 /*
607 $eventname = 'remove';
608
609 if (!isset($this->pdlModelObject->events[$eventname])) {
610 trigger_error("could not find PDLModelObjectEvent \"$eventname\"", E_USER_ERROR);
611 }
612 $almost_sql = $this->pdlModelObject->events[$eventname]->getEventPdl();
613 $almost_sql .= ';';
614
615 $almost_sql = str_replace(':' . $this->getID_name(), "'" . $this->getID() . "'", $almost_sql);
616
617 $sql = $almost_sql;
618
619 if ($sql) {
620 $this->dataquery->setSQL($sql);
621 $this->dataquery->query();
622 }
623 */
624
625 }
626
627 /*
628 function setMetaInfo($metainfo) {
629 $this->metainfo = $metainfo;
630 }
631 */
632
633 function reset() {
634 parent::_reset();
635 }
636
637
638 // ---------------------------------------------------------------------------------------
639 function save_catchAllVars() {
640 global $HTTP_GET_VARS;
641 while(list($key, $value) = each($this->attributes)) {
642 if (isset($HTTP_GET_VARS[$key])) {
643 //$this->attributes[$key] = $HTTP_GET_VARS[$key];
644 $this->_setAttribute($key, $HTTP_GET_VARS[$key]);
645 }
646 }
647 }
648
649
650 }
651
652
653
654
655
656 // ==============================================================
657 // implements a collection of "DSDataObject"s interacting with a DataQuery
658 class DSDataCollection extends DSAbstractObject {
659
660 // - - - - - - - - - - - - - - - - - - - - - -
661 // data which influences the result of this "DSDataCollection"
662
663 // filters we applied to this DataCollection (a hash of "DSFilter"-objects)
664 var $filters;
665 // the default concatenator for appending the "filters" to a query with already existing criteria-information
666 var $filterConcatenator;
667
668 // sortorders we applied to this DataCollection (a hash of "DSSortOrder"-objects)
669 var $sortorders;
670
671 // - - - - - - - - - - - - - - - - - - - - - -
672 // miscellanious data
673
674 // paging?
675 var $page;
676
677 // the number of results
678 var $resultcount;
679
680 // var $data;
681 //var $metainfo;
682
683
684 // ---------------------------------------------------------------------------------------
685 function DSDataCollection($type, &$ref_session) {
686
687 // call parent-constructor
688 parent::DSAbstractObject($type, 'all', &$ref_session);
689
690 // initialize class-variables
691 $this->filters = array();
692 $this->filterConcatenator = 'AND';
693 $this->sortorders = array();
694 }
695
696
697 // ---------------------------------------------------------------------------------------
698 // creates a new "DSFilter"-object and adds reference to local "filters"-hash
699 function &addFilter($filterstring, $logicalOperator = 'AND') {
700 slog("DSDataCollection: &addFilter($filterstring)");
701 $r_filter = &new DSFilter($filterstring, $logicalOperator);
702 $this->filters[] =& $r_filter;
703 return $r_filter;
704 }
705
706 // ---------------------------------------------------------------------------------------
707 // clears all filters from local "filters"-hash
708 function clearFilters() {
709 slog("DSDataCollection: clearFilters()");
710 $this->filters = array();
711 }
712
713
714 // ---------------------------------------------------------------------------------------
715 // creates a new "DSSortOrder"-object and adds reference to local "sortorders"-hash
716 function &addSortOrder($column, $mode) {
717 slog("DSDataCollection: &addSortOrder($column, $mode)");
718 $r_order =& new DSSortOrder($column, $mode);
719 array_push($this->sortorders, &$r_order);
720 return $r_order;
721 }
722
723
724 // ---------------------------------------------------------------------------------------
725 // limits DataCollection to a certain "page" (for paging of results)
726 function &setPage($pagenumber, $pagesize) {
727 // debugging
728 slog("DSDataCollection: &setPage($pagenumber, $pagesize)");
729 $this->page['number'] = $pagenumber;
730 $this->page['size'] = $pagesize;
731 }
732
733
734 // ---------------------------------------------------------------------------------------
735 // loads data into this "DSDataCollection"
736 function load() {
737
738 //$this->_load_startup();
739 if (!$this->_load_startup()) { return; }
740
741
742 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
743 // 1. process filters
744 // $this->filterConcatenator
745 if (isset($this->filters) && count($this->filters)) {
746 reset($this->filters);
747 while($r_filter =& current($this->filters)) {
748 if ($strFilter = $r_filter->getParsed()) {
749 //$almost_sql_FilterPart .= $strParsed . $sql_concat;
750 //$this->ref_dataquery->addCriteria(':' . $this->objectkey_name . ' = ' . $this->getObjectKey());
751 $this->ref_dataquery->addCriteria($strFilter, $r_filter->logicalOperator);
752 }
753 next($this->filters);
754 }
755 // clear all filters
756 $this->filters = array();
757 }
758
759
760 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
761 // 2. process orders
762 if (isset($this->sortorders) && count($this->sortorders)) {
763 reset($this->sortorders);
764 while($r_order =& current($this->sortorders)) {
765 $this->ref_dataquery->addOrder($r_order->getAttribute(), $r_order->getOrderAscDesc());
766 next($this->sortorders);
767 }
768 }
769
770
771 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
772 // 3. limit?
773 if ( isset($this->page['number']) && isset($this->page['size']) ) {
774 $nr = $this->page['number'];
775 $size = $this->page['size'];
776 $offset = $nr * $size;
777 //$almost_sql .= " LIMIT $offset, $size";
778 $strLimit = "$offset, $size";
779 $this->ref_dataquery->addLimit($strLimit);
780 }
781
782
783 // fetch data
784 $this->ref_dataquery->query();
785 $this->resultcount = $this->ref_dataquery->getRowCount();
786 $this->ref_dataquery->retrieveMetaInfo();
787 //$this->metainfo = $this->dataquery->metainfo;
788
789 }
790
791
792 // ---------------------------------------------------------------------------------------
793 // iterates to the next "DSDataObject" in the "DSDataCollection"-result and returns it
794 function &next() {
795
796 // debugging
797 slog("DSDataCollection: &next()");
798
799 // do an implicit load if we are "unbound"
800 if ($this->bool_unbound) {
801 $this->load();
802 }
803
804 // get next item from a "DataQuery"-result
805 if ($this->ref_dataquery->next()) {
806 $result = $this->ref_dataquery->getResult();
807 //$obj =& $this->session->Map2Obj($row, $this->pdlModelObject->getObjectType() );
808 //$obj =& $this->session->Map2Obj($row, $this->objecttype_full, $this->pdlEventName, $this->metainfo );
809 //$obj->setMetaInfo($this->metainfo);
810 $obj =& $this->ref_session->getDataObject($this->type);
811 $obj->fill($result);
812 //$obj->attributes =& $result;
813 //$obj->bool_unbound = 0;
814 return $obj;
815 }
816 }
817
818
819 // ---------------------------------------------------------------------------------------
820 // returns the number of results
821 function getResultCount() {
822 return $this->resultcount;
823 }
824
825 function reset() {
826 parent::_reset();
827 $this->filters = array();
828 $this->sortorders = array();
829 //$this->ref_dataquery->clearCriterias();
830 }
831
832 }
833
834 ?>

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