Development

Changeset 7559

You must first sign up to be able to contribute.

Changeset 7559

Show
Ignore:
Timestamp:
02/20/08 20:45:25 (9 months ago)
Author:
hartym
Message:

pre-support for mixing normal and extra impersonating fields in propel objects

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelImpersonatorPlugin/trunk/lib/sfPropelObjectPeerImpersonator.class.php

    r7555 r7559  
    3838    $objects, 
    3939    $objectsParameters, 
     40    $objectsStartColumns, 
    4041    $classToIndex, 
    4142    $relations, 
     
    292293    return $this->culture; 
    293294  } 
    294  
     295/* 
     296  public function getJoinExtension($field, $field2, $linkOperator, $comparisonOperator) 
     297  { 
     298    return ' '.$linkOperator.' ('.$field.' '.$comparisonOperator.' '.$field2.') '; 
     299  } 
     300*/ 
    295301  public function getJoinForCulture($class, $idField) 
    296302  { 
     
    304310  { 
    305311    $this->initializeRelations(); 
     312    $this->objectsStartColumns = array(); 
    306313 
    307314    if (self::DEBUG && self::DEBUG_POPULATE) 
     
    396403        if ($index/*&&$isNewObject*/) 
    397404        { 
    398           $linkedRelationsCounter = 0; 
    399  
    400           foreach ($this->getRelationsFor($index) as $relation) 
     405          // normal relation fetching (ie Propel BaseObjcet children) 
     406          if (get_class($this->objects[$index])!='sfPropelObjectImpersonator') 
    401407          { 
    402             $currentObject = $rowObjects[$index]
    403  
    404             switch ($relation['type']
     408            $linkedRelationsCounter = 0
     409 
     410            foreach ($this->getRelationsFor($index) as $relation
    405411            { 
    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: 
    421420                  if (self::DEBUG && self::DEBUG_POPULATE) 
    422421                  { 
    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: 
    447450                  if (self::DEBUG && self::DEBUG_POPULATE) 
    448451                  { 
    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: 
    473476                  if (self::DEBUG && self::DEBUG_POPULATE) 
    474477                  { 
    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              } 
    501517            } 
    502518 
    503             if (self::DEBUG && self::DEBUG_POPULATE
     519            if (!$linkedRelationsCounter
    504520            { 
    505               echo "\n"; 
     521              // this should not happen. An object which is not our main object has not been linked to any other 
     522              // fetched object. 
     523              throw new sfException('Orphan object fetched of type '.get_class($rowObjects[$index])); 
    506524            } 
    507525          } 
    508  
    509           if (!$linkedRelationsCounter) 
     526          else 
    510527          { 
    511             // this should not happen. An object which is not our main object has not been linked to any other 
    512             // fetched object. 
    513             throw new sfException('Orphan object fetched of type '.get_class($rowObjects[$index])); 
     528            assert($index-1>=0); 
     529            $rowObject[$index-1]->extra = $rowObject[$index]; 
    514530          } 
    515531        }