Changeset 7566
- Timestamp:
- 02/21/08 12:03:19 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelImpersonatorPlugin/trunk/lib/sfPropelObjectImpersonator.class.php
r7218 r7566 17 17 public function __construct($columns) 18 18 { 19 foreach($columns as $index=>$column) 20 { 21 if (count($column) == 2) 22 { 23 $columns[$index][2] = trim(strtolower(preg_replace('/[^a-z]/i', '_', $column[1])), '_'); 24 } 25 } 26 19 27 $this->columns = $columns; 20 28 } … … 31 39 foreach($this->columns as $_array) 32 40 { 33 list($type, $ name) = $_array;41 list($type, $field, $name) = $_array; 34 42 $this->$name = $rs->{'get'.ucfirst($type)}($startcol); 35 43 $startcol++; … … 64 72 } 65 73 74 public function addSelectColumns(Criteria &$c) 75 { 76 foreach ($this->columns as $index => $column) 77 { 78 $c->addAsColumn($column[2], $column[1]); 79 } 80 } 81 66 82 public function getPeer() 67 83 { 68 84 return null; 85 } 86 87 public function getColumns() 88 { 89 return $this->columns; 69 90 } 70 91 plugins/sfPropelImpersonatorPlugin/trunk/lib/sfPropelObjectPeerImpersonator.class.php
r7559 r7566 36 36 $query, 37 37 $connection, 38 $objects, 39 $objectsParameters, 40 $objectsStartColumns, 38 $objects = array(), 39 $objectsParameters = array(), 40 $objectsStartColumns = array(), 41 $currentStartColumnForPropelObjects = 1, 42 $currentStartColumnForImpersonatedObjects = 0, 41 43 $classToIndex, 42 44 $relations, … … 56 58 { 57 59 $args = func_get_args(); 58 $this->objects = array();59 $this->objectsParameters = array();60 60 61 61 if (count($args)) … … 109 109 foreach($this->objects as $object) 110 110 { 111 $peer = get_class($object).'Peer'; 112 113 call_user_func(array($peer, 'addSelectColumns'), $c); 111 if (self::isPropelObject($object)) 112 { 113 call_user_func(array(get_class($object).'Peer', 'addSelectColumns'), $c); 114 } 115 else 116 { 117 $object->addSelectColumns($c); 118 } 114 119 } 115 120 } … … 310 315 { 311 316 $this->initializeRelations(); 312 $this->objectsStartColumns = array(); 313 317 318 // debug block 314 319 if (self::DEBUG && self::DEBUG_POPULATE) 315 320 { … … 344 349 } 345 350 346 $startcol = 1;347 351 $rowObjects = array(); 352 $currentImpersonatedObjectsStartColumn = 0; 348 353 349 354 // for each subcomponent we have to hydrate in each record.... … … 356 361 357 362 $rowObjects[$index] = clone $object; 358 $startcol = $rowObjects[$index]->hydrate($resultset, $startcol); 363 364 if (self::isPropelObject($object)) 365 { 366 $rowObjects[$index]->hydrate($resultset, $this->objectsStartColumns[$index]); 367 } 368 else 369 { 370 $rowObjects[$index]->hydrate($resultset, $this->currentStartColumnForPropelObjects + $currentImpersonatedObjectsStartColumn); 371 $currentImpersonatedObjectsStartColumn += $this->objectsStartColumns[$index]; 372 } 359 373 360 374 /* // if the object was only made of null values, we consider it's inconsistent and forget it. … … 381 395 $isNewObject = true; 382 396 383 if ( get_class($this->objects[$index])!='sfPropelObjectImpersonator')397 if (self::isPropelObject($this->objects[$index])) 384 398 { 385 399 foreach ($allObjects[$index] as $otherObject) … … 404 418 { 405 419 // normal relation fetching (ie Propel BaseObjcet children) 406 if ( get_class($this->objects[$index])!='sfPropelObjectImpersonator')420 if (self::isPropelObject($this->objects[$index])) 407 421 { 408 422 $linkedRelationsCounter = 0; … … 527 541 { 528 542 assert($index-1>=0); 529 $rowObject [$index-1]->extra = $rowObject[$index];543 $rowObjects[$index-1]->extra = $rowObjects[$index]; 530 544 } 531 545 } … … 626 640 } 627 641 642 static public function isPropelObject($object) 643 { 644 return $object instanceof BaseObject; 645 } 646 628 647 /** 629 648 * Adds an object instance to the current objects array … … 631 650 protected function addObject($instance, $parameters=null) 632 651 { 633 $this->objects[] = $instance; 652 $index = count($this->objects); 653 654 $this->objects[$index] = $instance; 655 656 if (self::isPropelObject($instance)) 657 { 658 $this->objectsStartColumns[$index] = $this->currentStartColumnForPropelObjects; 659 $this->currentStartColumnForPropelObjects += count($instance->toArray()); 660 } 661 else 662 { 663 $this->objectsStartColumns[$index] = $this->currentStartColumnForImpersonatedObjects; 664 $this->currentStartColumnForImpersonatedObjects += count($instance->getColumns()); 665 } 634 666 635 667 if (null!==$parameters) 636 668 { 637 $this->setParameters( count($this->objects)-1, $parameters);669 $this->setParameters($index, $parameters); 638 670 } 639 671 } … … 680 712 else 681 713 { 682 throw new Exception( 'sfPropelObjectPeerImpersonator::initialize(): Unknown object class given "'.$className.'"');714 throw new Exception(__CLASS__.'::initialize(): Unknown object class given "'.$className.'"'); 683 715 } 684 716 }