Development

#3287: sfPropelFinderPlugin.php.diff

You must first sign up to be able to contribute.

Ticket #3287: sfPropelFinderPlugin.php.diff

File sfPropelFinderPlugin.php.diff, 4.6 kB (added by jug, 9 months ago)
  • sfPropelFinderPlugin/lib/sfPropelFinder.php

    old new  
    1717  protected $relations = null; 
    1818  protected $latestQuery = ''; 
    1919   
     20  /*! 
     21   * Array of conditions... 
     22   */ 
     23  protected $criterions = array(); //JG 
     24 
    2025  public function __construct($class = '') 
    2126  { 
    2227    $this->criteria = new Criteria(); 
     
    5156   
    5257  public function getCriteria() 
    5358  { 
    54     return $this->criteria; 
     59    return $this->buildCriteria(); //JG 
     60//     return $this->criteria; 
    5561  } 
    5662   
    5763  public function setCriteria($criteria) 
    5864  { 
    5965    $this->criteria = $criteria; 
     66    $this->criterions = array(); //JG: Sould we do that ? 
    6067    return $this; 
    6168  } 
    6269 
    6370  public function reinitCriteria() 
    6471  { 
    65     $this->criteria = new Criteria(); 
    66     return $this; 
     72    return $this->setCriteria(new Criteria); //JG: Sould we do that ? 
     73//     $this->criteria = new Criteria(); 
     74//     return $this; 
    6775  } 
    6876   
    6977  public function getLatestQuery() 
     
    102110   
    103111  public function count($con = null, $reinitCriteria = true) 
    104112  { 
    105     $ret = call_user_func(array($this->getPeerClass(), 'doCount'), $this->criteria, $con); 
     113    $ret = call_user_func(array($this->getPeerClass(), 'doCount'), $this->getCriteria(), $con); //JG 
    106114    $this->updateLatestQuery(); 
    107115    if($reinitCriteria) 
    108116    { 
     
    118126    { 
    119127      $this->criteria->setLimit($limit); 
    120128    } 
    121     $ret = call_user_func(array($this->getPeerClass(), 'doSelect'), $this->criteria, $con); 
     129    $ret = call_user_func(array($this->getPeerClass(), 'doSelect'), $this->getCriteria(), $con); //JG 
    122130    $this->updateLatestQuery(); 
    123131    if($reinitCriteria) 
    124132    { 
     
    130138   
    131139  public function findOne($con = null, $reinitCriteria = true) 
    132140  { 
    133     $ret = call_user_func(array($this->getPeerClass(), 'doSelectOne'), $this->criteria, $con); 
     141    $ret = call_user_func(array($this->getPeerClass(), 'doSelectOne'), $this->getCriteria(), $con); //JG 
    134142    $this->updateLatestQuery(); 
    135143    if($reinitCriteria) 
    136144    { 
     
    157165   
    158166  public function delete($con = null, $reinitCriteria = true) 
    159167  { 
    160     $deleteCriteria = clone $this->criteria; 
     168    $deleteCriteria = $this->getCriteria(); //JG 
    161169    if($deleteCriteria->equals(new Criteria())) 
    162170    { 
    163171      // delete will delete nothing when passed an empty criteria 
     
    213221      array_shift($arguments); 
    214222    }  
    215223    list($value, $comparison) = $this->getValueAndComparisonFromArguments($arguments); 
    216     $this->criteria->add($column, $value, $comparison); 
     224 
     225    $this->addcondition('and', $column, $value, $comparison ); //JG 
     226//     $this->criteria->add($column, $value, $comparison); 
    217227     
    218228    return $this; 
    219229  } 
     
    239249      array_shift($arguments); 
    240250    }  
    241251    list($value, $comparison) = $this->getValueAndComparisonFromArguments($arguments); 
    242     $this->criteria->addAnd($column, $value, $comparison); 
     252 
     253    $this->addcondition('and', $column, $value, $comparison ); //JG 
     254//     $this->criteria->addAnd($column, $value, $comparison); 
    243255     
    244256    return $this; 
    245257  } 
    246258 
     259 
     260  /*!JG 
     261   * Conditions have to be stocked before being really used 
     262   * cf. sfPropelFinder::buildCriteria() 
     263   */ 
     264  protected function addcondition( $cond, $column, $value, $comparison ) 
     265  { 
     266    $criterion = $this->criteria->getNewCriterion($column,$value,$comparison); 
     267    $criterion->func = "add$cond"; 
     268    $this->criterions[] = $criterion; 
     269  } 
     270 
     271 
     272  /*!JG 
     273   * We want that the Finder fuild Interface works like : 
     274   *   PHP : whereA()->_andB->_orC()->_orD()->_andE() 
     275   *   SQL : where A=? AND (B=? OR (C=? OR (D=? AND E=?))) 
     276   * So we have to add condition starting by the last one! 
     277   */ 
     278  protected function buildCriteria() 
     279  { 
     280    $criteria = clone $this->criteria; 
     281    $criterions = $this->criterions; 
     282 
     283    while( $criterion = array_pop($criterions) ) 
     284    { 
     285      $c = count($criterions); 
     286      $func = $criterion->func; 
     287      if ( $c ) 
     288      { 
     289        $criterions[$c-1]->$func( $criterion ); 
     290      } 
     291      else 
     292      { 
     293        $criteria->$func($criterion); 
     294      } 
     295    } 
     296    return $criteria; 
     297  } 
     298 
    247299  /** 
    248300   * Finder Fluid Interface for Criteria::addOr() 
    249301   * Infers $column, $value, $comparison from $columnName and some optional arguments 
     
    265317      array_shift($arguments); 
    266318    }  
    267319    list($value, $comparison) = $this->getValueAndComparisonFromArguments($arguments); 
    268     $this->criteria->addOr($column, $value, $comparison); 
     320    $this->addcondition('or', $column, $value, $comparison ); 
     321//     $this->criteria->addOr($column, $value, $comparison); 
    269322     
    270323    return $this; 
    271324  }