Author: david
Date: 2008-09-16 15:46:07 -0700 (Tue, 16 Sep 2008)
New Revision: 1385

Modified:
   trunk/apps/qubit/modules/term/actions/browseAction.class.php
   trunk/apps/qubit/modules/term/templates/browseTermSuccess.php
   trunk/lib/model/QubitObjectTermRelation.php
Log:
Implement paging for term/browse list.

Modified: trunk/apps/qubit/modules/term/actions/browseAction.class.php
===================================================================
--- trunk/apps/qubit/modules/term/actions/browseAction.class.php        
2008-09-16 18:58:10 UTC (rev 1384)
+++ trunk/apps/qubit/modules/term/actions/browseAction.class.php        
2008-09-16 22:46:07 UTC (rev 1385)
@@ -26,16 +26,27 @@
     //determine if user has edit priviliges
     $this->editCredentials = 
SecurityPriviliges::editCredentials($this->getUser(), 'term');
 
-    if (null !== $termId = $this->getRequestParameter('termId'))
+    if (null !== $this->getRequestParameter('termId'))
     {
-      $this->term = QubitTerm::getById($termId);
-
+      $options = array();
+      
+      $this->termId = $this->getRequestParameter('termId');
+      $this->term = QubitTerm::getById($this->termId);
       $this->forward404Unless(isset($this->term));
+      
+      $this->culture = $this->getUser()->getCulture();
+      $options['culture'] = $this->culture;
 
-      $this->sortColumn = $this->getRequestParameter('sortColumn');
-      $this->sortDirection = $this->getRequestParameter('sortDirection');
+      $this->sortColumn = $this->getRequestParameter('sortColumn', 'title');
+      $options['sortColumn'] = $this->sortColumn;
+      
+      $this->sortDirection = $this->getRequestParameter('sortDirection', 
'ascending');
+      $options['sortDirection'] = $this->sortDirection;
+      
+      $this->page = $this->getRequestParameter('page', 1);
+      $options['page'] = $this->page;
 
-      $this->informationObjects = 
QubitObjectTermRelation::getTermBrowseList($termId, $className = 
'QubitInformationObject', $this->sortColumn, $this->sortDirection);
+      $this->informationObjects = 
QubitObjectTermRelation::getTermBrowseList($this->termId, 
'QubitInformationObject', $options);
 
       $this->setTemplate('browseTerm');
     }

Modified: trunk/apps/qubit/modules/term/templates/browseTermSuccess.php
===================================================================
--- trunk/apps/qubit/modules/term/templates/browseTermSuccess.php       
2008-09-16 18:58:10 UTC (rev 1384)
+++ trunk/apps/qubit/modules/term/templates/browseTermSuccess.php       
2008-09-16 22:46:07 UTC (rev 1385)
@@ -5,19 +5,19 @@
 <?php echo $termName ?>
 </div>
 
+<?php echo __('Displaying results %1% to %2%',
+    array('%1%' => $informationObjects->getFirstIndice(), '%2%' => 
$informationObjects->getLastIndice())) ?>
 <table class="list">
 <thead>
 
 <tr>
-
   <th>
-  <?php echo __("Browse for '%1%' in '%2%' returned %3% results", array('%1%' 
=> $termName, '%2%' => $taxonomyName, '%3%' => count($informationObjects))) ?>
+  <?php echo __("Browse for '%1%' in '%2%' returned %3% results", array('%1%' 
=> $termName, '%2%' => $taxonomyName, '%3%' => 
$informationObjects->getNbResults())) ?><br />
   </th>
-
 </tr>
 </thead>
 <tbody>
-<?php foreach ($informationObjects as $informationObject): ?>
+<?php foreach ($informationObjects->getResults() as $informationObject): ?>
 <tr><td>
 <?php echo link_to($informationObject->getLabel(), 
'informationobject/show?id='.$informationObject->getId()) ?>
 
@@ -33,6 +33,25 @@
 </tbody>
 </table>
 
+<?php if ($informationObjects->haveToPaginate()): ?>
+<p><div class="pager" style="text-align: center; font-size: 12px">
+  Pages:<br />
+  <?php $links = $informationObjects->getLinks(); ?>
+  <?php if ($informationObjects->getFirstPage() < 
$informationObjects->getfirstPageLink()): ?>
+    <?php echo link_to($informationObjects->getFirstPage(), 
'term/browse?termId='.$termId.'&sortColumn='.$sortColumn.'&sortDirection='.$sortDirection.'&page='.$informationObjects->getFirstPage())
 ?>
+    ...
+  <?php endif; ?>
+  <?php foreach ($links as $page): ?>
+    <?php echo ($page == $informationObjects->getPage()) ? $page : 
link_to($page, 
'term/browse?termId='.$termId.'&sortColumn='.$sortColumn.'&sortDirection='.$sortDirection.'&page='.$page)
 ?>
+    <?php if ($page != $informationObjects->getCurrentMaxLink()): ?> <?php 
endif ?>
+  <?php endforeach ?>
+  <?php if ($informationObjects->getLastPage() > 
$informationObjects->getLastPageLink()): ?>
+    ...
+    <?php echo link_to($informationObjects->getLastPage(), 
'term/browse?termId='.$termId.'&sortColumn='.$sortColumn.'&sortDirection='.$sortDirection.'&page='.$informationObjects->getLastPage())
 ?>
+  <?php endif; ?>
+</div></p>
+<?php endif ?><br />
+
 <div class="menu-extra">
   <?php echo link_to(__('browse all %1%', array('%1%' => $taxonomyName)), 
'term/browse?taxonomyId='.$term->getTaxonomyId()); ?>
 </div>

Modified: trunk/lib/model/QubitObjectTermRelation.php
===================================================================
--- trunk/lib/model/QubitObjectTermRelation.php 2008-09-16 18:58:10 UTC (rev 
1384)
+++ trunk/lib/model/QubitObjectTermRelation.php 2008-09-16 22:46:07 UTC (rev 
1385)
@@ -48,58 +48,85 @@
       SearchIndex::updateTranslatedLanguages($this->getObject());
     }
   }
-
-  public static function getTermBrowseList($termId = null, $className = 
'QubitInformationObject', $sortColumn = null, $sortDirection = 'ascending')
+  
+  /**
+   * Get a list of objects related to the given $termId
+   *
+   * @param integer $termId Primary key of specified term
+   * @param string  $className type of class to return
+   * @param array   $options array of optional parameters
+   * @return sfPager paginated list of objects
+   *
+   * @todo Figure out sorting - it's a NASTY problem!
+   */
+  public static function getTermBrowseList($termId=null, 
$className='QubitInformationObject', $options=array())
   {
     $criteria = new Criteria;
     $criteria->add(QubitObject::CLASS_NAME, $className);
     $criteria->addJoin(QubitObject::ID, QubitObjectTermRelation::OBJECT_ID);
     $criteria->add(QubitObjectTermRelation::TERM_ID, $termId);
+    
+    $page = isset($options['page']) ? $options['page'] : 1;
+    
     switch($className)
+    {
+      case 'QubitInformationObject':
       {
-        case 'QubitInformationObject':
-         {
-           $criteria->addJoin(QubitObject::ID, QubitInformationObject::ID);
-           if ($sortColumn)
-             {
-               if ($sortDirection == 'ascending')
-                 {
-                 //TODO: figure out how to dynamically add SORT_COLUMNS (will 
also require a join to _i18n)
-                 
//$criteria->addAscendingOrderByColumn(QubitInformationObject::$sortColumn);
-                 }
-               else
-                 {
-                 //TODO: figure out how to dynamically add SORT_COLUMNS (will 
also require a join to _i18n)
-                 
//$criteria->addDescendingOrderByColumn(QubitInformationObject::$sortColumn);
-                 }
-             }
-      return QubitInformationObject::get($criteria);
-      break;
+        $criteria->addJoin(QubitObject::ID, QubitInformationObject::ID);
+        if ($options['sortColumn'])
+        {
+          if ($options['sortDirection'] == 'ascending')
+          {
+            //TODO: figure out how to dynamically add SORT_COLUMNS (will also 
require a join to _i18n)
+            /*
+            $criteria->addAscendingOrderByColumn('name');
+            */
+          }
+          else
+          {
+            //TODO: figure out how to dynamically add SORT_COLUMNS (will also 
require a join to _i18n)
+            /*
+            $criteria->addDescendingOrderByColumn('name');
+            */
+          }
+        }   
+        
+        // Page results
+        $pager = new QubitPager('QubitInformationObject');
+      
+        break;
       }
-    case 'QubitActor':
+      case 'QubitActor':
       {
-      $criteria->addJoin(QubitObject::ID, QubitActor::ID);
-      return QubitActor::get($criteria);
-      break;
+        $criteria->addJoin(QubitObject::ID, QubitActor::ID);
+        $pager = new QubitPager('QubitActor');
+        break;
       }
-    case 'QubitRepository':
+      case 'QubitRepository':
       {
-      $criteria->addJoin(QubitObject::ID, QubitRepository::ID);
-      return QubitRepository::get($criteria);
-      break;
+        $criteria->addJoin(QubitObject::ID, QubitRepository::ID);
+        $pager = new QubitPager('QubitRepository');
+        break;
       }
-    case 'QubitDigitalObject':
+      case 'QubitDigitalObject':
       {
-      $criteria->addJoin(QubitObject::ID, QubitDigitalObject::ID);
-      return QubitDigitalObject::get($criteria);
-      break;
+        $criteria->addJoin(QubitObject::ID, QubitDigitalObject::ID);
+        $pager = new QubitPager('QubitDigitalObject');
+        break;
       }
-    case 'QubitPhysicalObject':
+      case 'QubitPhysicalObject':
       {
-      $criteria->addJoin(QubitObject::ID, QubitPhysicalObject::ID);
-      return QubitPhysicalObject::get($criteria);
-      break;
+        $criteria->addJoin(QubitObject::ID, QubitPhysicalObject::ID);
+        $pager = new QubitPager('QubitPhysicalObject');
+        break;
       }
     }
+    
+    // Return paged results
+    $pager->setCriteria($criteria);
+    $pager->setPage($page);
+    $pager->init();
+    
+    return $pager;
   }
 }


--~--~---------~--~----~------------~-------~--~----~
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