Development

Changeset 7391

You must first sign up to be able to contribute.

Changeset 7391

Show
Ignore:
Timestamp:
02/07/08 17:05:13 (5 years ago)
Author:
hartym
Message:

sfPropelImpersonator: added culture options for i18n

Files:

Legend:

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

    r7385 r7391  
    3939    $classToIndex, 
    4040    $relations, 
    41     $currentIndex; 
     41    $currentIndex, 
     42    $culture = null; 
    4243 
    4344  /** 
     
    275276  } 
    276277 
     278  public function setCulture($culture) 
     279  { 
     280    $this->culture = mysql_real_escape_string($culture); 
     281  } 
     282 
     283  public function getCulture() 
     284  { 
     285    if (null === $this->culture) 
     286    { 
     287      $this->setCulture(sfContext::getInstance()->getUser()->getCulture()); 
     288    } 
     289 
     290    return $this->culture; 
     291  } 
     292 
     293  public function getJoinForCulture($class, $idField) 
     294  { 
     295    return constant($class.'::'.$idField).' AND '.constant($class.'::CULTURE').'=\''.$this->getCulture().'\''; 
     296  } 
     297 
    277298  /** 
    278299   * Object population 
     
    299320      } 
    300321 
    301       echo '<script>console.dir('.json_encode(array('sfPropelObjectPeerImpersonator'=>$debugRelations)).');</script>'; 
     322      echo '<script>console.dir('.json_encode(array('Propel Impersonator Debug'=>$debugRelations)).');</script>'; 
    302323      echo '<pre>'; 
    303324    } 
     
    335356        } 
    336357        for now, let's say we keep it 
     358 
     359          reason is: if we dont populate an empty propel object, propel will think we don't know it does not exists, and 
     360          will fetch it again from database. 
     361 
     362          maybe this could be implemented with a minimal NULL object (ok i know it looks like Doctrine_Null) 
    337363        */ 
    338364 
     
    380406                if (self::DEBUG && self::DEBUG_POPULATE) 
    381407                { 
    382                   echo '  <u>REVERSE</u>: '.$relation['classFrom'].' <-- '.$relation['classTo']."\n"
     408                  echo '  <u>REVERSE</u>: '.$relation['classFrom'].' <-- '.$relation['classTo']
    383409                } 
    384410 
     
    388414                if ($isNewObject) 
    389415                { 
     416                  if (self::DEBUG && self::DEBUG_POPULATE) 
     417                  { 
     418                    echo ' (new)'; 
     419                  } 
     420 
    390421                  $currentObject->{'init'.$foreignClass.'s'}(); 
    391422                } 
     
    401432                if (self::DEBUG && self::DEBUG_POPULATE) 
    402433                { 
    403                   echo '  <u>I18N</u>: '.$relation['classTo'].' <-- '.$relation['classFrom']."\n"; 
    404                 } 
    405  
    406                 if (null !== ($classToIndex = $this->getIndexByClass($relation['classTo']))) 
    407                 { 
    408                   $foreignObject =& $rowObjects[$classToIndex]; 
    409  
    410                   $rowObjects[$index]->{'set'.$relation['classTo']}($foreignObject); 
    411                   $foreignObject->{'set'.$relation['classTo'].'I18nForCulture'}($rowObjects[$index], $rowObjects[$index]->getCulture()); 
     434                  echo '  <u>I18N</u>: '.$relation['classTo'].' <-- '.$relation['classFrom']; 
     435                } 
     436 
     437                if (null !== ($objectIndex = $this->getIndexByClass($relation['classTo']))) 
     438                { 
     439                  if (self::DEBUG && self::DEBUG_POPULATE) 
     440                  { 
     441                    echo ' (exists)'; 
     442                  } 
     443 
     444                  $object = $rowObjects[$objectIndex]; 
     445                  $i18nObject = $rowObjects[$index]; 
     446 
     447                  $i18nObject->{'set'.$relation['classTo']}($object); 
     448                  $object->{'set'.$relation['classTo'].'I18nForCulture'}($i18nObject, $this->getCulture()); 
     449 
    412450                } 
    413451                break; 
     
    419457                if (self::DEBUG && self::DEBUG_POPULATE) 
    420458                { 
    421                   echo '  <u>NORMAL</u>: '.$relation['classFrom'].' --> '.$relation['classTo']."\n"; 
    422                 } 
    423  
     459                  echo '  <u>NORMAL</u>: '.$relation['classFrom'].' --> '.$relation['classTo']; 
     460                } 
    424461 
    425462                if (null !== ($classToIndex = $this->getIndexByClass($relation['classTo']))) 
    426463                { 
     464                  if (self::DEBUG && self::DEBUG_POPULATE) 
     465                  { 
     466                    echo ' (exists)'; 
     467                  } 
    427468                  $foreignObject = $rowObjects[$classToIndex]; 
    428469 
     
    438479                } 
    439480                break; 
     481            } 
     482 
     483            if (self::DEBUG && self::DEBUG_POPULATE) 
     484            { 
     485              echo "\n"; 
    440486            } 
    441487          }