Author: david
Date: 2008-09-12 15:45:01 -0700 (Fri, 12 Sep 2008)
New Revision: 1378

Modified:
   trunk/apps/qubit/modules/informationobject/actions/listAction.class.php
   trunk/apps/qubit/modules/informationobject/templates/listSuccess.php
   trunk/lib/model/QubitInformationObject.php
Log:
Move all Propel Criteria calls from informationobject/listAction.class.php into 
the QubitInformationObject::getList() model class. Return a QubitPager object 
from QubitInformation::getList() method - making paging as unobtrusive as 
possible. Update informationobject/list template to work with new pager 
paradigm.

Modified: 
trunk/apps/qubit/modules/informationobject/actions/listAction.class.php
===================================================================
--- trunk/apps/qubit/modules/informationobject/actions/listAction.class.php     
2008-09-12 22:37:52 UTC (rev 1377)
+++ trunk/apps/qubit/modules/informationobject/actions/listAction.class.php     
2008-09-12 22:45:01 UTC (rev 1378)
@@ -19,8 +19,6 @@
  * Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-require_once('apps/qubit/lib/QubitPager.class.php');
-
 /**
  * @package    qubit
  * @subpackage repository
@@ -37,51 +35,47 @@
    */
   public function execute($request)
   {
-    $this->culture = $this->getUser()->getCulture();
-    $this->sort = $this->getRequestParameter('sort', 'titleUp');
-    $this->page = $this->getRequestParameter('page', 1);
+    $options = array();
+    $this->repositoryId = 0;
     
     // HACK: Get root information object for _contextMenu partial
     $criteria = new Criteria;
     $criteria->add(QubitInformationObject::PARENT_ID);
     $root = QubitInformationObject::getOne($criteria);
     $request->setAttribute('informationObject', $root);
-   
-    // Only get the top-level info object (collections and orphans)
-    $criteria = new Criteria;
-    $criteria->add(QubitInformationObject::PARENT_ID, $root->getID(), 
Criteria::EQUAL);
     
-    //establish list filters
+    // Set parent id to the root node id
+    $options['parentId'] = $root->getId();
+    
+    // Set culture and cultural fallback flag
+    $this->culture = $this->getUser()->getCulture();
+    $options['cultureFallback'] = true; // Do cultural fallback
+    
+    // Set sort
+    $this->sort = $this->getRequestParameter('sort', 'titleUp');
+    $options['sort'] = $this->sort;
+    
+    // Set current page
+    $this->page = $this->getRequestParameter('page', 1);
+    $options['page'] = $this->page;
+    
+    // Filter by repository
     if ($this->getRequestParameter('repository'))
     {
       $this->repositoryId = $this->getRequestParameter('repository');
-      $criteria->add(QubitInformationObject::REPOSITORY_ID,  
$this->getRequestParameter('repository'));
+      $options['repositoryId'] = $this->repositoryId;
     }
-    else
-    {
-      $this->repositoryId = 0;
-    }
-  
+    
+    // Filter by collection type
     if ($this->getRequestParameter('collectionType'))
     {
-      $criteria->add(QubitInformationObject::COLLECTION_TYPE_ID,  
$this->getRequestParameter('collectionType'));
+      $this->collectionType = $this->getRequestParameter('collectionType');
+      $options['collectionType'] = $this->collectionType;
     }
     
-    // Page results
-    $pager = new QubitPager('QubitInformationObject');
-    $pager->setCriteria($criteria);
-    $pager->setPage($this->page);
-    $pager->init();
-    $this->pager = $pager;
+    // Get QubitQuery collection of information objects (with pagination, 
fallback and sorting)
+    $this->informationObjects = 
QubitInformationObject::getList($this->culture, new Criteria, $options);
     
-    // Set offset and limit for hitlist criteria with values from pager
-    $criteria->setOffset($pager->getOffset());
-    $criteria->setLimit($pager->getLimit());
-    
-    // Get array of information objects (with fallback and sorting)
-    $this->informationObjects = QubitInformationObject::getList($criteria, 
$this->culture,  
-      array('cultureFallback'=>true, 
'sort'=>$this->getRequestParameter('sort')));
-    
     //determine if user has edit priviliges
     $this->editCredentials = false;
     if (SecurityPriviliges::editCredentials($this->getUser(), 
'informationObject'))

Modified: trunk/apps/qubit/modules/informationobject/templates/listSuccess.php
===================================================================
--- trunk/apps/qubit/modules/informationobject/templates/listSuccess.php        
2008-09-12 22:37:52 UTC (rev 1377)
+++ trunk/apps/qubit/modules/informationobject/templates/listSuccess.php        
2008-09-12 22:45:01 UTC (rev 1378)
@@ -1,7 +1,7 @@
 <div class="pageTitle"><?php echo __('list %1%', array('%1%' => 
sfConfig::get('app_ui_label_informationobject'))); ?></div>
 
-<?php echo $pager->getNbResults() ?> results found.<br />
-Displaying results <?php echo $pager->getFirstIndice() ?> to  <?php echo 
$pager->getLastIndice() ?>
+<?php echo $informationObjects->getNbResults() ?> results found.<br />
+Displaying results <?php echo $informationObjects->getFirstIndice() ?> to  
<?php echo $informationObjects->getLastIndice() ?>
 
 <table class="list">
 <thead>
@@ -36,7 +36,7 @@
 </tr>
 </thead>
 <tbody>
-<?php foreach ($informationObjects as $informationObject): ?>
+<?php foreach ($informationObjects->getResults() as $informationObject): ?>
 <tr><td>
 <div>
 <?php if (strlen($title = $informationObject->getTitle(array('cultureFallback' 
=> true))) > 0); ?>
@@ -50,21 +50,21 @@
 </tbody>
 </table>
 
-<?php if ($pager->haveToPaginate()): ?>
+<?php if ($informationObjects->haveToPaginate()): ?>
 <p><div class="pager" style="text-align: center; font-size: 12px">
   Pages:<br />
-  <?php $links = $pager->getLinks(); ?>
-  <?php if ($pager->getFirstPage() < $pager->getfirstPageLink()): ?>
-    <?php echo link_to($pager->getFirstPage(), 
'informationobject/list?sort='.$sort.'&page='.$pager->getFirstPage()) ?>
+  <?php $links = $informationObjects->getLinks(); ?>
+  <?php if ($informationObjects->getFirstPage() < 
$informationObjects->getfirstPageLink()): ?>
+    <?php echo link_to($informationObjects->getFirstPage(), 
'informationobject/list?sort='.$sort.'&page='.$informationObjects->getFirstPage())
 ?>
     ...
   <?php endif; ?>
   <?php foreach ($links as $page): ?>
-    <?php echo ($page == $pager->getPage()) ? $page : link_to($page, 
'informationobject/list?sort='.$sort.'&page='.$page) ?>
-    <?php if ($page != $pager->getCurrentMaxLink()): ?> <?php endif ?>
+    <?php echo ($page == $informationObjects->getPage()) ? $page : 
link_to($page, 'informationobject/list?sort='.$sort.'&page='.$page) ?>
+    <?php if ($page != $informationObjects->getCurrentMaxLink()): ?> <?php 
endif ?>
   <?php endforeach ?>
-  <?php if ($pager->getLastPage() > $pager->getLastPageLink()): ?>
+  <?php if ($informationObjects->getLastPage() > 
$informationObjects->getLastPageLink()): ?>
     ...
-    <?php echo link_to($pager->getLastPage(), 
'informationobject/list?sort='.$sort.'&page='.$pager->getLastPage()) ?>
+    <?php echo link_to($informationObjects->getLastPage(), 
'informationobject/list?sort='.$sort.'&page='.$informationObjects->getLastPage())
 ?>
   <?php endif; ?>
 </div></p>
 <?php endif ?><br />

Modified: trunk/lib/model/QubitInformationObject.php
===================================================================
--- trunk/lib/model/QubitInformationObject.php  2008-09-12 22:37:52 UTC (rev 
1377)
+++ trunk/lib/model/QubitInformationObject.php  2008-09-12 22:45:01 UTC (rev 
1378)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  * This file is part of the Qubit Toolkit.
  * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]>
@@ -27,7 +26,7 @@
  * @author Jack Bates
  * @author Peter Van Garderen
  * @author David Juhasz <[EMAIL PROTECTED]>
- * @version svn:$Id
+ * @version svn:$Id$
  */
 class QubitInformationObject extends BaseInformationObject
 {
@@ -81,70 +80,82 @@
       $relation->delete();
     }
   }
-
-  public static function getList($criteria, $culture, $options = array())
+  
+  /**
+   * Get a paginated hitlist information objects
+   *
+   * @param string   $culture primary language for list
+   * @param Criteria $criteria Propel Criteria object
+   * @param array    $options array of optional function parameters
+   * @return QubitQuery collection of QubitInformationObject objects
+   */
+  public static function getList($culture, $criteria, $options = array())
   {
+    // Only get the top-level info object (collections and orphans)
+    if (isset($options['parentId']))
+    {
+      $criteria->add(QubitInformationObject::PARENT_ID, $options['parentId'], 
Criteria::EQUAL);
+    }
+    
     $cultureFallback = (isset($options['cultureFallback'])) ? 
$options['cultureFallback'] : false;
-    $sort = (isset($options['sort'])) ? $options['sort'] : null;  
+    $sort = (isset($options['sort'])) ? $options['sort'] : null;
+    $page = (isset($options['page'])) ? $options['page'] : 1;
     
+    if (isset($options['repositoryId']))
+    {
+      $criteria->add(QubitInformationObject::REPOSITORY_ID,  
$options['repositoryId']);
+    }
+    
+    if (isset($options['collectionType']))
+    {
+      $criteria->add(QubitInformationObject::COLLECTION_TYPE_ID, 
$options['collectionType']);
+    }
+    
+    // Sort results
+    switch($sort)
+    {
+      case 'titleDown':
+        $fallbackTable = 'QubitInformationObject';
+        $criteria->addDescendingOrderByColumn('title');
+        break;
+      case 'repositoryUp':
+        $fallbackTable = 'QubitActor';
+        $criteria->addJoin(QubitInformationObject::REPOSITORY_ID, 
QubitActor::ID, Criteria::LEFT_JOIN);
+        $criteria->addAscendingOrderByColumn('authorized_form_of_name');
+        break;
+      case 'repositoryDown':
+        $fallbackTable = 'QubitActor';
+        $criteria->addJoin(QubitInformationObject::REPOSITORY_ID, 
QubitActor::ID, Criteria::LEFT_JOIN);
+        $criteria->addDescendingOrderByColumn('authorized_form_of_name');
+        break;
+      case 'titleUp':
+      default:
+        $fallbackTable = 'QubitInformationObject';
+        $criteria->addAscendingOrderByColumn('title');
+    }
+      
     // Do source culture fallback
     if ($cultureFallback === true)
-    {  
-      // Sort results
-      switch($sort)
-      {
-        case 'titleDown':
-          $fallbackTable = 'QubitInformationObjectI18n';
-          $criteria->addDescendingOrderByColumn('title');
-          break;
-        case 'repositoryUp':
-          $fallbackTable = 'QubitActorI18n';
-          $criteria->addJoin(QubitInformationObject::REPOSITORY_ID, 
QubitActor::ID, Criteria::LEFT_JOIN);
-          $criteria->addAscendingOrderByColumn('authorized_form_of_name');
-          break;
-        case 'repositoryDown':
-          $fallbackTable = 'QubitActorI18n';
-          $criteria->addJoin(QubitInformationObject::REPOSITORY_ID, 
QubitActor::ID, Criteria::LEFT_JOIN);
-          $criteria->addDescendingOrderByColumn('authorized_form_of_name');
-          break;
-        case 'titleUp':
-        default:
-          $fallbackTable = 'QubitInformationObjectI18n';
-          $criteria->addAscendingOrderByColumn('title');
-      }
-      
+    {
       // Return a QubitQuery object of class-type QubitInformationObject
       $options = array('returnClass'=>'QubitInformationObject');
-      $results = call_user_func_array(array($fallbackTable, 'getFallback'), 
array($criteria, $culture, $options));
+      $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 
$fallbackTable, $culture, $options);
     }
-    else 
-    {  
-      // Get children of the root node (collection roots and orphans)
+    else
+    {
+      // Do straight joins without fallback
       $criteria->addJoin(QubitInformationObject::ID, 
QubitInformationObjectI18n::ID);
       $criteria->addJoin(QubitInformationObject::REPOSITORY_ID, 
QubitActorI18n::ID, Criteria::LEFT_JOIN);
       $criteria->add(QubitInformationObjectI18n::CULTURE, $culture);
-      
-      // Sort results
-      switch($sort)
-      {
-        case 'titleUp':
-          
$criteria->addAscendingOrderByColumn(QubitInformationObjectI18n::TITLE);
-          break;
-        case 'titleDown':
-          
$criteria->addDescendingOrderByColumn(QubitInformationObjectI18n::TITLE);
-          break;
-        case 'repositoryUp':
-          
$criteria->addAscendingOrderByColumn(QubitActorI18n::AUTHORIZED_FORM_OF_NAME);
-          break;
-        case 'repositoryDown':
-          
$criteria->addDescendingOrderByColumn(QubitActorI18n::AUTHORIZED_FORM_OF_NAME);
-          break;
-      }
-  
-      $results = QubitInformationObject::get($criteria);
     }
     
-    return $results;
+    // Page results
+    $pager = new QubitPager('QubitInformationObject');
+    $pager->setCriteria($criteria);
+    $pager->setPage($page);
+    $pager->init();
+    
+    return $pager;
   }
 
   public function getLabel($truncate = null)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to