Changeset 7385
- Timestamp:
- 02/06/08 21:20:47 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelImpersonatorPlugin/trunk/lib/sfPropelObjectPeerImpersonator.class.php
r7218 r7385 18 18 class sfPropelObjectPeerImpersonator 19 19 { 20 const DEBUG = false; 21 const DEBUG_POPULATE = false; 22 20 23 /** 21 24 * Relation type constants … … 279 282 $this->initializeRelations(); 280 283 284 if (self::DEBUG && self::DEBUG_POPULATE) 285 { 286 $debugRelations = array(); 287 288 foreach ($this->relations as $from => $fromData) 289 { 290 $fromClass = get_class($this->objects[$from]); 291 292 $debugRelations[$fromClass] = array(); 293 foreach ($fromData as $to => $relationsData) 294 { 295 $toClass = get_class($this->objects[$to]); 296 297 $debugRelations[$fromClass][$toClass] = $relationsData; 298 } 299 } 300 301 echo '<script>console.dir('.json_encode(array('sfPropelObjectPeerImpersonator'=>$debugRelations)).');</script>'; 302 echo '<pre>'; 303 } 304 281 305 $result = array(); 282 306 $allObjects = array(); … … 285 309 while ($resultset->next()) 286 310 { 311 if (self::DEBUG && self::DEBUG_POPULATE) 312 { 313 echo '-------------------- fetch a record --------------------'."\n"; 314 } 315 287 316 $startcol = 1; 288 317 $rowObjects = array(); … … 291 320 foreach ($this->objects as $index => $object) 292 321 { 322 if (self::DEBUG && self::DEBUG_POPULATE) 323 { 324 echo '<b>'.get_class($object).'</b>'."\n"; 325 } 326 293 327 $rowObjects[$index] = clone $object; 294 328 $startcol = $rowObjects[$index]->hydrate($resultset, $startcol); 295 329 296 330 // if the object was only made of null values, we consider it's inconsistent and forget it. 297 if (!$this->testConsistence($rowObjects[$index]->getPrimaryKey()))331 /* if (!$this->testConsistence($rowObjects[$index]->getPrimaryKey())) 298 332 { 299 333 unset($rowObjects[$index]); 300 334 continue; 301 335 } 336 for now, let's say we keep it 337 */ 302 338 303 339 // initialize our object directory … … 330 366 // If we're not in our "main" object context but in a sub-object, we're going to 331 367 // fetch the available relations. 332 if ($index &&$isNewObject)368 if ($index/*&&$isNewObject*/) 333 369 { 334 370 foreach ($this->getRelationsFor($index) as $relation) 335 371 { 372 $currentObject = $rowObjects[$index]; 373 336 374 switch ($relation['type']) 337 375 { … … 340 378 */ 341 379 case self::RELATION_REVERSE: 380 if (self::DEBUG && self::DEBUG_POPULATE) 381 { 382 echo ' <u>REVERSE</u>: '.$relation['classFrom'].' <-- '.$relation['classTo']."\n"; 383 } 384 385 $foreignClass = $relation['classFrom']; 386 $foreignObject = $rowObjects[$this->getIndexByClass($foreignClass)]; 387 342 388 if ($isNewObject) 343 389 { 344 $ rowObjects[$index]->{'init'.$relation['classFrom'].'s'}();345 } 346 347 $ rowObjects[$index]->{'add'.$relation['classFrom']}($rowObjects[$this->getIndexByClass($relation['classFrom'])]);348 $ rowObjects[$this->getIndexByClass($relation['classFrom'])]->{'set'.$relation['classTo']}($rowObjects[$index]);390 $currentObject->{'init'.$foreignClass.'s'}(); 391 } 392 393 $currentObject->{'add'.$foreignClass}($foreignObject); 394 $foreignObject->{'set'.$relation['classTo']}($currentObject); 349 395 break; 350 396 351 /**352 * RELATION_I18N353 */397 /** 398 * RELATION_I18N 399 */ 354 400 case self::RELATION_I18N: 401 if (self::DEBUG && self::DEBUG_POPULATE) 402 { 403 echo ' <u>I18N</u>: '.$relation['classTo'].' <-- '.$relation['classFrom']."\n"; 404 } 405 355 406 if (null !== ($classToIndex = $this->getIndexByClass($relation['classTo']))) 356 407 { … … 362 413 break; 363 414 364 /**365 * RELATION_NORMAL366 */415 /** 416 * RELATION_NORMAL 417 */ 367 418 case self::RELATION_NORMAL: 419 if (self::DEBUG && self::DEBUG_POPULATE) 420 { 421 echo ' <u>NORMAL</u>: '.$relation['classFrom'].' --> '.$relation['classTo']."\n"; 422 } 423 424 368 425 if (null !== ($classToIndex = $this->getIndexByClass($relation['classTo']))) 369 426 { 370 $foreignObject = &$rowObjects[$classToIndex];427 $foreignObject = $rowObjects[$classToIndex]; 371 428 372 429 // local *---- foreign (local object has one foreign object) … … 391 448 } 392 449 } 450 } 451 452 if (self::DEBUG && self::DEBUG_POPULATE) 453 { 454 echo '</pre>'; 393 455 } 394 456