Development

Changeset 8160

You must first sign up to be able to contribute.

Changeset 8160

Show
Ignore:
Timestamp:
03/30/08 21:54:21 (5 months ago)
Author:
francois
Message:

sfPropelFinderPlugin Small internal refactoring

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php

    r8132 r8160  
    179179  /** 
    180180   * Finder Fluid Interface for Criteria::add() 
    181    * 
    182    * @param      string $critOrColumn The column to run the comparison on, or Criterion object. 
    183    * @param      mixed  $value The value to be matched 
    184    * @param      string $comparison Comparison operator (leave empty for equal) 
    185    * 
    186    * @return     sfPropelFinder the current finder object 
    187    */ 
    188   public function where($critOrColumn, $value = null, $comparison = null) 
    189   { 
    190     $this->criteria->add($critOrColumn, $value, $comparison); 
    191      
    192     return $this; 
    193   } 
    194    
    195   /** 
    196    * Magic version of where() 
    197181   * Infers $column, $value, $comparison from $columnName and some optional arguments 
    198182   * Examples: 
    199    *   $articleFinder->_where('IsPublished') 
     183   *   $articleFinder->where('IsPublished') 
    200184   *    => $c->add(ArticlePeer::IS_PUBLISHED, true) 
    201    *   $articleFinder->_where('CommentId', 3) 
     185   *   $articleFinder->where('CommentId', 3) 
    202186   *    => $c->add(ArticlePeer::COMMENT_ID, 3) 
    203    *   $articleFinder->_where('Title', 'like', '%foo') 
     187   *   $articleFinder->where('Title', 'like', '%foo') 
    204188   *    => $c->add(ArticlePeer::TITLE, '%foo', Criteria::LIKE) 
    205189   * 
     
    209193   * @return     sfPropelFinder the current finder object 
    210194   */ 
    211   public function _where($columnName, $arguments = array()) 
     195  public function where($columnName, $arguments = array()) 
    212196  { 
    213197    $column = $this->getColName($columnName); 
     
    233217        throw new Exception('{sfPropelFinder} whereXXX can only be called with one or two arguments'); 
    234218    } 
    235      
    236     return $this->where($column, $value, $comparison); 
     219    $this->criteria->add($column, $value, $comparison); 
     220     
     221    return $this; 
     222 
    237223  } 
    238224 
     
    240226   * Finder Fluid Interface for Criteria::addAscendingOrderByColumn() 
    241227   * and Criteria::addDescendingOrderByColumn() 
    242    */ 
    243   public function orderBy($column, $order = Criteria::ASC) 
    244   { 
    245     switch ($order) 
    246     { 
    247       case Criteria::ASC: 
    248         $this->criteria->addAscendingOrderByColumn($column); 
    249         break; 
    250       case Criteria::DESC: 
    251         $this->criteria->addDescendingOrderByColumn($column); 
    252         break; 
    253       default: 
    254         throw new Exception('{sfPropelFinder} orderBy only accepts "asc" or "desc" as argument'); 
    255     } 
    256      
    257     return $this; 
    258   } 
    259    
    260   /** 
    261    * Magic version of orderBy() 
    262228   * Infers $column and $order from $columnName and some optional arguments 
    263229   * Examples: 
    264    *   $articleFinder->_orderBy('CreatedAt') 
     230   *   $articleFinder->orderBy('CreatedAt') 
    265231   *    => $c->addAscendingOrderByColumn(ArticlePeer::CREATED_AT) 
    266    *   $articlefinder->_orderBy('CategoryId', 'desc') 
     232   *   $articlefinder->orderBy('CategoryId', 'desc') 
    267233   *    => $c->addDescendingOrderByColumn(ArticlePeer::CATEGORY_ID) 
    268234   */ 
    269   public function _orderBy($columnName, $arguments = array()) 
     235  public function orderBy($columnName, $arguments = array()) 
    270236  { 
    271237    $column = $this->getColName($columnName); 
     
    276242    } 
    277243     
    278     return $this->orderBy($column, $order); 
     244    switch ($order) 
     245    { 
     246      case Criteria::ASC: 
     247        $this->criteria->addAscendingOrderByColumn($column); 
     248        break; 
     249      case Criteria::DESC: 
     250        $this->criteria->addDescendingOrderByColumn($column); 
     251        break; 
     252      default: 
     253        throw new Exception('{sfPropelFinder} orderBy only accepts "asc" or "desc" as argument'); 
     254    } 
     255     
     256    return $this; 
    279257  } 
    280258   
    281259  /** 
    282260   * Finder Fluid Interface for Criteria::addJoin() 
    283    */ 
    284   public function join($column1, $column2, $operator = null) 
    285   { 
    286     $this->criteria->addJoin($column1, $column2, $operator); 
    287      
    288     return $this; 
    289   } 
    290    
    291   /** 
    292    * Magic version of join() 
    293261   * Infers $column1, $column2 and $operator from $relatedClass and some optional arguments 
    294262   * Uses the Propel column maps, based on the schema, to guess the related columns 
    295263   * Examples: 
    296    *   $articleFinder->_join('Comment') 
     264   *   $articleFinder->join('Comment') 
    297265   *    => $c->addJoin(ArticlePeer::ID, CommentPeer::ARTICLE_ID) 
    298    *   $articleFinder->_join('Category', 'RIGHT JOIN') 
     266   *   $articleFinder->join('Category', 'RIGHT JOIN') 
    299267   *    => $c->addJoin(ArticlePeer::CATEGORY_ID, CategoryPeer::ID, Criteria::RIGHT_JOIN) 
    300268   */ 
    301   public function _join($relatedClass, $arguments = array()) 
     269  public function join($relatedClass, $arguments = array()) 
    302270  { 
    303271    list($column1, $column2) = $this->getRelation($relatedClass); 
     
    308276      $operator = null; 
    309277    } 
    310      
    311     return $this->join($column1, $column2, $operator); 
     278    $this->criteria->addJoin($column1, $column2, $operator); 
     279     
     280    return $this; 
    312281  } 
    313282 
     
    385354    if(strpos($name, 'where') === 0) 
    386355    { 
    387       return $this->_where(substr($name, 5), $arguments); 
     356      return $this->where(substr($name, 5), $arguments); 
    388357    } 
    389358    if(strpos($name, 'orderBy') === 0) 
    390359    { 
    391       return $this->_orderBy(substr($name, 7), $arguments); 
     360      return $this->orderBy(substr($name, 7), $arguments); 
    392361    } 
    393362    if(strpos($name, 'join') === 0) 
    394363    { 
    395       return $this->_join(substr($name, 4), $arguments); 
     364      return $this->join(substr($name, 4), $arguments); 
    396365    } 
    397366    if(method_exists($this->criteria, $name)) 
  • plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php

    r8132 r8160  
    357357$article3->setCategory($category2); 
    358358$article3->save(); 
    359 $nbArticles = sfPropelFinder::from('Article')->joinCategory()->where(CategoryPeer::NAME, 'cat1')->count(); 
     359$nbArticles = sfPropelFinder::from('Article')->joinCategory()->whereCategory_Name('cat1')->count(); 
    360360$t->is($nbArticles, 2, 'joinXXX() allows to join to another table (many-to-one)'); 
    361 $nbArticles = sfPropelFinder::from('Article')->joinCategory()->where(CategoryPeer::NAME, 'cat2')->count(); 
     361$nbArticles = sfPropelFinder::from('Article')->joinCategory()->whereCategory_Name('cat2')->count(); 
    362362$t->is($nbArticles, 1, 'joinXXX() allows to join to another table (many-to-one)'); 
    363 $article = sfPropelFinder::from('Article')->joinCategory()->where(CategoryPeer::NAME, 'cat2')->findOne(); 
     363$article = sfPropelFinder::from('Article')->joinCategory()->whereCategory_Name('cat2')->findOne(); 
    364364$t->is($article->getTitle(), 'ccccc', 'joinXXX() allows to join to another table (many-to-one)'); 
    365365ArticlePeer::doDeleteAll(); 
     
    377377$comment->setArticle($article2); 
    378378$comment->save(); 
    379 $nbArticles = sfPropelFinder::from('Article')->joinComment()->where(CommentPeer::CONTENT, 'foo')->count(); 
     379$nbArticles = sfPropelFinder::from('Article')->joinComment()->whereComment_Content('foo')->count(); 
    380380$t->is($nbArticles, 1, 'joinXXX() allows to join to another table (one-to-many)'); 
    381 $article = sfPropelFinder::from('Article')->joinComment()->where(CommentPeer::CONTENT, 'foo')->findOne(); 
     381$article = sfPropelFinder::from('Article')->joinComment()->whereComment_Content('foo')->findOne(); 
    382382$t->is($article->getTitle(), 'bbbbb', 'joinXXX() allows to join to another table (one-to-many)'); 
    383383 
     
    397397$comment->setAuthor($author1); 
    398398$comment->save(); 
    399 $article = sfPropelFinder::from('Article')->joinComment()->joinAuthor()->where(AuthorPeer::NAME, 'John')->findOne(); 
     399$article = sfPropelFinder::from('Article')->joinComment()->joinAuthor()->whereAuthor_Name('John')->findOne(); 
    400400$t->is($article->getTitle(), 'aaaaa', 'you can chain several joinXXX() statements'); 
    401401