Development

Changeset 8884

You must first sign up to be able to contribute.

Changeset 8884

Show
Ignore:
Timestamp:
05/09/08 16:17:27 (3 days ago)
Author:
hartym
Message:

sfPropelImpersonatorPlugin: added doSelectRS impersonating, to ->addSelectcolumns() if user did not and to use propels behaviors. this wont be merged in branch 1.0

Files:

Legend:

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

    r8621 r8884  
    431431  public function doSelect(Criteria $c, $con=null) 
    432432  { 
     433    if ($this->securityFieldCountFlag && ($_acceptable=($this->currentStartColumnForPropelObjects + $this->currentStartColumnForImpersonatedObjects - 1)) != ($_got = count($c->getSelectColumns())+count($c->getAsColumns()))) 
     434    { 
     435      throw new sfException('Criteria selects '.$_got.' fields while the Holy sfPropelImpersonator waits for '.$_acceptable.' fields to populate objects. Exactly. Not more, not less. So '.$_acceptable.' will be the field count your Criteria will ask for. You won\'t give it '.($_acceptable-1).', neither '.($_acceptable+1).', but '.$_acceptable.'.'); 
     436    } 
     437 
     438    return $this->populateObjects($this->doSelectRS($c, $con)); 
     439  } 
     440 
     441  /** 
     442   * Impersonates doSelectRS, to call behaviours callables 
     443   */ 
     444  public function doSelectRS(Criteria $criteria, $con = null) 
     445  { 
     446    $basePeer = 'Base'.get_class($this->objects[0]).'Peer'; 
     447 
     448    foreach (sfMixer::getCallables($basePeer.':doSelectRS:doSelectRS') as $callable) 
     449    { 
     450      call_user_func($callable, $basePeer, $criteria, $con); 
     451    } 
     452 
    433453    if ($con||!$this->connection) 
    434454    { 
     
    436456    } 
    437457 
    438     if ($this->securityFieldCountFlag && ($_acceptable=($this->currentStartColumnForPropelObjects + $this->currentStartColumnForImpersonatedObjects - 1)) != ($_got = count($c->getSelectColumns())+count($c->getAsColumns()))) 
    439     { 
    440       throw new sfException('Criteria selects '.$_got.' fields while the Holy sfPropelImpersonator waits for '.$_acceptable.' fields to populate objects. Exactly. Not more, not less. So '.$_acceptable.' will be the field count your Criteria will ask for. You won\'t give it '.($_acceptable-1).', neither '.($_acceptable+1).', but '.$_acceptable.'.'); 
    441     } 
    442  
    443     return $this->populateObjects(BasePeer::doSelect($c, $con)); 
     458    if (!$criteria->getSelectColumns()) 
     459    { 
     460      $criteria = clone $criteria; 
     461      $this->addSelectColumns($criteria); 
     462    } 
     463 
     464    return BasePeer::doSelect($criteria, $con); 
    444465  } 
    445466 
     
    608629 
    609630  /** 
    610    * Checks whether a primary key is consistent or not. Used to know if an object retrieved via a 
    611    * left/right join (or equivalent) was null or not. 
    612    * 
    613    * @param mixed $key 
    614    * 
    615    * @return boolean 
    616    */ 
    617   protected function testConsistence($key) 
    618   { 
    619     $isConsistent = true; 
    620  
    621     if (is_array($key)) 
    622     { 
    623       foreach ($key as $key_part) 
    624       { 
    625         $isConsistent = $isConsistent && $this->testConsistence($key_part); 
    626       } 
    627     } 
    628     elseif ($key === null) 
    629     { 
    630       $isConsistent = false; 
    631     } 
    632  
    633     return $isConsistent; 
    634   } 
    635  
    636   protected function getRelationsFor($index) 
    637   { 
    638     return isset($this->relations[$index]) ? $this->relations[$index] : array(); 
    639   } 
    640  
    641   /** 
    642    * Merge a new parameters set with existing one for object indexed by $objectIndex 
    643    * 
    644    * @param integer $objectIndex 
    645    * @param array   $parameters 
    646    */ 
    647   protected function setParameters($objectIndex, array $parameters) 
    648   { 
    649     if (!isset($this->objectsParameters[$objectIndex])) 
    650     { 
    651       $this->objectsParameters[$objectIndex] = array(); 
    652     } 
    653  
    654     $this->objectsParameters[$objectIndex] = array_merge($this->objectsParameters[$objectIndex], $parameters); 
    655   } 
    656  
    657   /** 
    658631   * Retrieve a parameter for an object 
    659632   * 
     
    722695 
    723696  /** 
     697   * Checks whether a primary key is consistent or not. Used to know if an object retrieved via a 
     698   * left/right join (or equivalent) was null or not. 
     699   * 
     700   * @param mixed $key 
     701   * 
     702   * @return boolean 
     703   */ 
     704  protected function testConsistence($key) 
     705  { 
     706    $isConsistent = true; 
     707 
     708    if (is_array($key)) 
     709    { 
     710      foreach ($key as $key_part) 
     711      { 
     712        $isConsistent = $isConsistent && $this->testConsistence($key_part); 
     713      } 
     714    } 
     715    elseif ($key === null) 
     716    { 
     717      $isConsistent = false; 
     718    } 
     719 
     720    return $isConsistent; 
     721  } 
     722 
     723  protected function getRelationsFor($index) 
     724  { 
     725    return isset($this->relations[$index]) ? $this->relations[$index] : array(); 
     726  } 
     727 
     728  /** 
     729   * Merge a new parameters set with existing one for object indexed by $objectIndex 
     730   * 
     731   * @param integer $objectIndex 
     732   * @param array   $parameters 
     733   */ 
     734  protected function setParameters($objectIndex, array $parameters) 
     735  { 
     736    if (!isset($this->objectsParameters[$objectIndex])) 
     737    { 
     738      $this->objectsParameters[$objectIndex] = array(); 
     739    } 
     740 
     741    $this->objectsParameters[$objectIndex] = array_merge($this->objectsParameters[$objectIndex], $parameters); 
     742  } 
     743 
     744  /** 
    724745   * Adds an object instance to the current objects array 
    725746   */ 
     
    748769    } 
    749770  } 
    750  
    751771 
    752772  protected function addObjectByClassName($className)