Development

Changeset 10085

You must first sign up to be able to contribute.

Changeset 10085

Show
Ignore:
Timestamp:
07/03/08 14:05:07 (2 months ago)
Author:
francois
Message:

sfPropelFinderPlugin Made the plugin Propel 1.3 compatible

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelFinderPlugin/README

    r10074 r10085  
    1515$c->add(ArticlePeer::IS_PUBLISHED, true); 
    1616$c->addAscendingOrderByColumn(ArticlePeer::CREATED_AT); 
    17 $articles = ArticlePeer::doSelect($c); 
     17$articles = ArticlePeer::doSelectJoinCategory($c); 
    1818 
    1919// with sfPropelFinder 
    20 $articles = sfPropelFinder::from('Article')->whereTitle('like', '%world')->whereIsPublished(true)->orderByCreatedAt()->find(); 
    21 }}} 
    22  
    23 `sfPropelFinder` uses the same fluid interface as the `sfFinder`, so you won't be lost. 
     20$articles = sfPropelFinder::from('Article')-> 
     21  where('Title', 'like', '%world')-> 
     22  where('IsPublished', true)-> 
     23  order('ByCreatedAt')-> 
     24  with('Category')-> 
     25  find(); 
     26}}} 
     27 
     28`sfPropelFinder` uses the same fluid interface as the `sfFinder`, so you won't be lost. It is compatible with symfony 1.0 and 1.1, and with Propel 1.2 and 1.3. 
    2429 
    2530You can also implement your own business logic to encapsulate complex queries, so that your queries look like real language: 
     
    476481== Changelog == 
    477482 
    478 === 2008-07-02 | Trunk === 
    479  
     483=== 2008-07-03 | Trunk === 
     484 
     485 * francois: Added Propel 1.3 compatibility 
    480486 * francois: Added `sfPropelFinder::set()` method (based on a patch by jug) 
    481487 * francois: Added `sfPropelFinder::withI18n()` method 
  • plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php

    r10074 r10085  
    430430    { 
    431431      $c = $this->prepareCompositeCriteria($criteria); 
    432       $resultSet = call_user_func(array($this->getPeerClass(), 'doSelectRS'), $c, $con); 
     432      if(method_exists($this->getPeerClass(), 'doSelectRS')) 
     433      { 
     434        $resultSet = call_user_func(array($this->getPeerClass(), 'doSelectRS'), $c, $con); 
     435        $propelVersion = '1.2'; 
     436        $nextFunction = 'next'; 
     437        $nextParam = null; 
     438      } 
     439      else 
     440      { 
     441        $resultSet = call_user_func(array($this->getPeerClass(), 'doSelectStmt'), $c, $con); 
     442        $propelVersion = '1.3'; 
     443        $nextFunction = 'fetch'; 
     444        $nextParam = PDO::FETCH_NUM; 
     445      } 
    433446       
    434447      // Hydrate the objects based on the resultset 
    435448      $omClass = call_user_func(array($this->getPeerClass(), 'getOMClass')); 
    436       $cls = Propel::import($omClass); 
     449      $cls = substr('.'.$omClass, strrpos('.'.$omClass, '.') + 1); 
    437450      $objects = array(); 
    438451      $withObjs = array(); 
    439       while ($resultSet->next()) 
     452      while ($row = $resultSet->$nextFunction($nextParam)) 
    440453      { 
    441454        // First come the columns of the main class 
    442455        $obj = new $cls(); 
    443         $startCol = $obj->hydrate($resultSet, 1); 
     456        if($propelVersion == '1.2') 
     457        { 
     458          $startCol = $obj->hydrate($resultSet, 1); 
     459        } 
     460        else 
     461        { 
     462          $startCol = $obj->hydrate($row, 0); 
     463        } 
    444464        if($this->culture) 
    445465        { 
     
    451471        { 
    452472          $withObj = new $className(); 
    453           $startCol = $withObj->hydrate($resultSet, $startCol); 
     473          if($propelVersion == '1.2') 
     474          { 
     475            $startCol = $withObj->hydrate($resultSet, $startCol); 
     476          } 
     477          else 
     478          { 
     479            $startCol = $withObj->hydrate($row, $startCol); 
     480          } 
    454481           
    455482          // initialize our object directory 
     
    485512          // Using the third parameter of withColumn() as a type. defaults to $rs->get() (= $rs->getString()) 
    486513          $typedGetter = 'get'.ucfirst($column['type']); 
    487           $obj->$asName = $resultSet->$typedGetter($startCol); 
     514          if($propelVersion == '1.2') 
     515          { 
     516            $obj->$asName = $resultSet->$typedGetter($startCol); 
     517          } 
     518          else 
     519          { 
     520            $obj->$asName = $row[$startCol]; 
     521          } 
    488522          $startCol++; 
    489523        } 
  • plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php

    r10074 r10085  
    6565ArticlePeer::doDeleteAll(); 
    6666 
    67 $t = new lime_test(142, new lime_output_color()); 
     67$t = new lime_test(141, new lime_output_color()); 
    6868 
    6969$t->diag('find()'); 
     
    830830$article = sfPropelFinder::from('Article')-> 
    831831  join('Comment')-> 
     832  groupBy('Article_Id')-> 
    832833  withColumn('COUNT(comment.ID)', 'NbComments')-> 
    833834  findOne(); 
     
    836837$finder = sfPropelFinder::from('Article')-> 
    837838  join('Comment')-> 
     839  groupBy('Article_Id')-> 
    838840  withColumn('COUNT(comment.ID)', 'NbComments')-> 
    839841  orderBy('NbComments'); 
    840842$article = $finder->findOne(); 
    841 $t->is($finder->getLatestQuery(), 'SELECT article.ID, article.VERSION, article.TITLE, article.CATEGORY_ID, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID ORDER BY NbComments ASC LIMIT 1', 'Columns added with withColumn() can be used for sorting'); 
    842  
    843 $finder = sfPropelFinder::from('Article')-> 
    844   join('Comment')-> 
    845   withColumn('COUNT(comment.ID)', 'NbComments')-> 
    846   addGroupByColumn('NbComments'); 
    847 $article = $finder->findOne(); 
    848 $t->is($finder->getLatestQuery(), 'SELECT article.ID, article.VERSION, article.TITLE, article.CATEGORY_ID, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID GROUP BY NbComments LIMIT 1', 'Columns added with withColumn() can be used for grouping'); 
     843$t->is($finder->getLatestQuery(), 'SELECT article.ID, article.VERSION, article.TITLE, article.CATEGORY_ID, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID GROUP BY article.ID ORDER BY NbComments ASC LIMIT 1', 'Columns added with withColumn() can be used for sorting'); 
    849844 
    850845$t->diag('set()');