| 406 | | /** |
|---|
| 407 | | * RELATION_REVERSE |
|---|
| 408 | | */ |
|---|
| 409 | | case self::RELATION_REVERSE: |
|---|
| 410 | | if (self::DEBUG && self::DEBUG_POPULATE) |
|---|
| 411 | | { |
|---|
| 412 | | echo ' <u>REVERSE</u>: '.$relation['classFrom'].' <-- '.$relation['classTo']; |
|---|
| 413 | | } |
|---|
| 414 | | |
|---|
| 415 | | $foreignClass = $relation['classFrom']; |
|---|
| 416 | | $foreignObject = $rowObjects[$this->getIndexByClass($foreignClass)]; |
|---|
| 417 | | $relatedBy = (null === ($_relatedBy=$this->getParameter($index, 'related_by')))?'':'RelatedBy'.sfInflector::camelize($_relatedBy); |
|---|
| 418 | | |
|---|
| 419 | | if ($isNewObject) |
|---|
| 420 | | { |
|---|
| | 412 | $currentObject = $rowObjects[$index]; |
|---|
| | 413 | |
|---|
| | 414 | switch ($relation['type']) |
|---|
| | 415 | { |
|---|
| | 416 | /** |
|---|
| | 417 | * RELATION_REVERSE |
|---|
| | 418 | */ |
|---|
| | 419 | case self::RELATION_REVERSE: |
|---|
| 423 | | echo ' (new)'; |
|---|
| 424 | | } |
|---|
| 425 | | |
|---|
| 426 | | |
|---|
| 427 | | $currentObject->{'init'.$foreignClass.'s'.$relatedBy}(); |
|---|
| 428 | | } |
|---|
| 429 | | |
|---|
| 430 | | $currentObject->{'add'.$foreignClass.$relatedBy}($foreignObject); |
|---|
| 431 | | $foreignObject->{'set'.$relation['classTo'].$relatedBy}($currentObject); |
|---|
| 432 | | |
|---|
| 433 | | $linkedRelationsCounter++; |
|---|
| 434 | | break; |
|---|
| 435 | | |
|---|
| 436 | | /** |
|---|
| 437 | | * RELATION_I18N |
|---|
| 438 | | */ |
|---|
| 439 | | case self::RELATION_I18N: |
|---|
| 440 | | if (self::DEBUG && self::DEBUG_POPULATE) |
|---|
| 441 | | { |
|---|
| 442 | | echo ' <u>I18N</u>: '.$relation['classTo'].' <-- '.$relation['classFrom']; |
|---|
| 443 | | } |
|---|
| 444 | | |
|---|
| 445 | | if (null !== ($objectIndex = $this->getIndexByClass($relation['classTo']))) |
|---|
| 446 | | { |
|---|
| | 422 | echo ' <u>REVERSE</u>: '.$relation['classFrom'].' <-- '.$relation['classTo']; |
|---|
| | 423 | } |
|---|
| | 424 | |
|---|
| | 425 | $foreignClass = $relation['classFrom']; |
|---|
| | 426 | $foreignObject = $rowObjects[$this->getIndexByClass($foreignClass)]; |
|---|
| | 427 | $relatedBy = (null === ($_relatedBy=$this->getParameter($index, 'related_by')))?'':'RelatedBy'.sfInflector::camelize($_relatedBy); |
|---|
| | 428 | |
|---|
| | 429 | if ($isNewObject) |
|---|
| | 430 | { |
|---|
| | 431 | if (self::DEBUG && self::DEBUG_POPULATE) |
|---|
| | 432 | { |
|---|
| | 433 | echo ' (new)'; |
|---|
| | 434 | } |
|---|
| | 435 | |
|---|
| | 436 | |
|---|
| | 437 | $currentObject->{'init'.$foreignClass.'s'.$relatedBy}(); |
|---|
| | 438 | } |
|---|
| | 439 | |
|---|
| | 440 | $currentObject->{'add'.$foreignClass.$relatedBy}($foreignObject); |
|---|
| | 441 | $foreignObject->{'set'.$relation['classTo'].$relatedBy}($currentObject); |
|---|
| | 442 | |
|---|
| | 443 | $linkedRelationsCounter++; |
|---|
| | 444 | break; |
|---|
| | 445 | |
|---|
| | 446 | /** |
|---|
| | 447 | * RELATION_I18N |
|---|
| | 448 | */ |
|---|
| | 449 | case self::RELATION_I18N: |
|---|
| 449 | | echo ' (exists)'; |
|---|
| 450 | | } |
|---|
| 451 | | |
|---|
| 452 | | $object = $rowObjects[$objectIndex]; |
|---|
| 453 | | $i18nObject = $rowObjects[$index]; |
|---|
| 454 | | |
|---|
| 455 | | $i18nObject->{'set'.$relation['classTo']}($object); |
|---|
| 456 | | $object->{'set'.$relation['classTo'].'I18nForCulture'}($i18nObject, $this->getCulture()); |
|---|
| 457 | | |
|---|
| 458 | | $linkedRelationsCounter++; |
|---|
| 459 | | } |
|---|
| 460 | | break; |
|---|
| 461 | | |
|---|
| 462 | | /** |
|---|
| 463 | | * RELATION_NORMAL |
|---|
| 464 | | */ |
|---|
| 465 | | case self::RELATION_NORMAL: |
|---|
| 466 | | if (self::DEBUG && self::DEBUG_POPULATE) |
|---|
| 467 | | { |
|---|
| 468 | | echo ' <u>NORMAL</u>: '.$relation['classFrom'].' --> '.$relation['classTo']; |
|---|
| 469 | | } |
|---|
| 470 | | |
|---|
| 471 | | if (null !== ($classToIndex = $this->getIndexByClass($relation['classTo']))) |
|---|
| 472 | | { |
|---|
| | 452 | echo ' <u>I18N</u>: '.$relation['classTo'].' <-- '.$relation['classFrom']; |
|---|
| | 453 | } |
|---|
| | 454 | |
|---|
| | 455 | if (null !== ($objectIndex = $this->getIndexByClass($relation['classTo']))) |
|---|
| | 456 | { |
|---|
| | 457 | if (self::DEBUG && self::DEBUG_POPULATE) |
|---|
| | 458 | { |
|---|
| | 459 | echo ' (exists)'; |
|---|
| | 460 | } |
|---|
| | 461 | |
|---|
| | 462 | $object = $rowObjects[$objectIndex]; |
|---|
| | 463 | $i18nObject = $rowObjects[$index]; |
|---|
| | 464 | |
|---|
| | 465 | $i18nObject->{'set'.$relation['classTo']}($object); |
|---|
| | 466 | $object->{'set'.$relation['classTo'].'I18nForCulture'}($i18nObject, $this->getCulture()); |
|---|
| | 467 | |
|---|
| | 468 | $linkedRelationsCounter++; |
|---|
| | 469 | } |
|---|
| | 470 | break; |
|---|
| | 471 | |
|---|
| | 472 | /** |
|---|
| | 473 | * RELATION_NORMAL |
|---|
| | 474 | */ |
|---|
| | 475 | case self::RELATION_NORMAL: |
|---|
| 475 | | echo ' (exists)'; |
|---|
| 476 | | } |
|---|
| 477 | | $foreignObject = $rowObjects[$classToIndex]; |
|---|
| 478 | | |
|---|
| 479 | | $relatedBy = (null === ($_relatedBy=$this->getParameter($classToIndex, 'related_by')))?'':'RelatedBy'.sfInflector::camelize($_relatedBy); |
|---|
| 480 | | // @todo: bug correction, this does not work if related_by is used this way, it tries to call setFieldRelatedByFieldId |
|---|
| 481 | | // instead of setClassNameRelatedByFieldId, and sometimes (depending on order) it uses the wrong Field, as second one |
|---|
| 482 | | // override first one in relations |
|---|
| 483 | | |
|---|
| 484 | | // local *---- foreign (local object has one foreign object) |
|---|
| 485 | | $rowObjects[$index]->{'set'.str_replace('Id','',$relation['local']).$relatedBy}($foreignObject); |
|---|
| 486 | | |
|---|
| 487 | | // foreign ----* local (foreign object has many local objects) |
|---|
| 488 | | // we have to check if there are already other objects, or if this is the first. |
|---|
| 489 | | // @todo: find a way not to call initXxxXxxs() on every passes, but only on first addition for each object. |
|---|
| 490 | | |
|---|
| 491 | | $foreignObject->{'init'.$relation['classFrom'].'s'.$relatedBy}($rowObjects[$index]); |
|---|
| 492 | | $foreignObject->{'add'.$relation['classFrom'].$relatedBy}($rowObjects[$index]); |
|---|
| 493 | | |
|---|
| 494 | | $linkedRelationsCounter++; |
|---|
| 495 | | } |
|---|
| 496 | | break; |
|---|
| 497 | | |
|---|
| 498 | | case self::RELATION_SELF: |
|---|
| 499 | | throw new sfException('Self relations not yet implemented'); |
|---|
| 500 | | break; |
|---|
| | 478 | echo ' <u>NORMAL</u>: '.$relation['classFrom'].' --> '.$relation['classTo']; |
|---|
| | 479 | } |
|---|
| | 480 | |
|---|
| | 481 | if (null !== ($classToIndex = $this->getIndexByClass($relation['classTo']))) |
|---|
| | 482 | { |
|---|
| | 483 | if (self::DEBUG && self::DEBUG_POPULATE) |
|---|
| | 484 | { |
|---|
| | 485 | echo ' (exists)'; |
|---|
| | 486 | } |
|---|
| | 487 | $foreignObject = $rowObjects[$classToIndex]; |
|---|
| | 488 | |
|---|
| | 489 | $relatedBy = (null === ($_relatedBy=$this->getParameter($classToIndex, 'related_by')))?'':'RelatedBy'.sfInflector::camelize($_relatedBy); |
|---|
| | 490 | // @todo: bug correction, this does not work if related_by is used this way, it tries to call setFieldRelatedByFieldId |
|---|
| | 491 | // instead of setClassNameRelatedByFieldId, and sometimes (depending on order) it uses the wrong Field, as second one |
|---|
| | 492 | // override first one in relations |
|---|
| | 493 | |
|---|
| | 494 | // local *---- foreign (local object has one foreign object) |
|---|
| | 495 | $rowObjects[$index]->{'set'.str_replace('Id','',$relation['local']).$relatedBy}($foreignObject); |
|---|
| | 496 | |
|---|
| | 497 | // foreign ----* local (foreign object has many local objects) |
|---|
| | 498 | // we have to check if there are already other objects, or if this is the first. |
|---|
| | 499 | // @todo: find a way not to call initXxxXxxs() on every passes, but only on first addition for each object. |
|---|
| | 500 | |
|---|
| | 501 | $foreignObject->{'init'.$relation['classFrom'].'s'.$relatedBy}($rowObjects[$index]); |
|---|
| | 502 | $foreignObject->{'add'.$relation['classFrom'].$relatedBy}($rowObjects[$index]); |
|---|
| | 503 | |
|---|
| | 504 | $linkedRelationsCounter++; |
|---|
| | 505 | } |
|---|
| | 506 | break; |
|---|
| | 507 | |
|---|
| | 508 | case self::RELATION_SELF: |
|---|
| | 509 | throw new sfException('Self relations not yet implemented'); |
|---|
| | 510 | break; |
|---|
| | 511 | } |
|---|
| | 512 | |
|---|
| | 513 | if (self::DEBUG && self::DEBUG_POPULATE) |
|---|
| | 514 | { |
|---|
| | 515 | echo "\n"; |
|---|
| | 516 | } |
|---|