Author: david
Date: 2008-09-16 11:58:10 -0700 (Tue, 16 Sep 2008)
New Revision: 1384

Modified:
   trunk/apps/qubit/modules/actor/actions/listAction.class.php
   trunk/apps/qubit/modules/actor/templates/listSuccess.php
   trunk/lib/model/QubitActor.php
   trunk/lib/model/QubitRepository.php
Log:
Update actor/list page to new fallback + pagination method. Make 
QubitRepository::getList() and QubitActor::getList() method parameter 
"options=array()" match to avoid errors from PHP from extending class.

Modified: trunk/apps/qubit/modules/actor/actions/listAction.class.php
===================================================================
--- trunk/apps/qubit/modules/actor/actions/listAction.class.php 2008-09-16 
17:49:16 UTC (rev 1383)
+++ trunk/apps/qubit/modules/actor/actions/listAction.class.php 2008-09-16 
18:58:10 UTC (rev 1384)
@@ -19,58 +19,41 @@
  * Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-require_once('apps/qubit/lib/QubitPager.class.php');
-
+/**
+ * Show paginated list of actors.
+ *
+ * @package    qubit
+ * @subpackage actor
+ * @author     Peter Van Garderen <[EMAIL PROTECTED]>
+ * @author     David Juhasz <[EMAIL PROTECTED]>
+ * @version    svn:$Id$
+ */
 class ActorListAction extends sfAction
 {
   public function execute($request)
   {
-    $this->role = $this->getRequestParameter('role', 'all');
-    $this->sort = $this->getRequestParameter('sort', 'nameUp');
-    $this->page = $this->getRequestParameter('page', 1);
+    $options = array();
     
-    $criteria = new Criteria;
+    // Set culture and cultural fallback flag
+    $this->culture = $this->getUser()->getCulture();
+    $options['cultureFallback'] = true; // Do cultural fallback
     
-    // Add criteria to allow sorting by i18n values (authorized_form_of_name, 
term:name)
-    // And only return values for current culture
-    $criteria->add(QubitActorI18n::CULTURE, $this->getUser()->getCulture());
-    $criteria->add(QubitTermI18n::CULTURE, $this->getUser()->getCulture());
-    $criteria->addJoin(QubitActor::ID, QubitActorI18n::ID, 
Criteria::LEFT_JOIN);
-    $criteria->addJoin(QubitActor::ENTITY_TYPE_ID, QubitTermI18n::ID, 
Criteria::LEFT_JOIN);
+    // Set sort
+    $this->sort = $this->getRequestParameter('sort', 'nameUp');
+    $options['sort'] = $this->sort;
     
-    // Add sort criteria
-    switch($this->sort)
-    {
-      case 'nameDown':
-        
$criteria->addDescendingOrderByColumn(QubitActorI18n::AUTHORIZED_FORM_OF_NAME);
-        break;
-      case 'typeUp':
-        $criteria->addAscendingOrderByColumn(QubitTermI18n::NAME);
-        break;
-      case 'typeDown':
-        $criteria->addDescendingOrderByColumn(QubitTermI18n::NAME);
-        break;
-      case 'nameUp':
-      default:
-        
$criteria->addAscendingOrderByColumn(QubitActorI18n::AUTHORIZED_FORM_OF_NAME);
-    }
+    // Set current page
+    $this->page = $this->getRequestParameter('page', 1);
+    $options['page'] = $this->page;
     
-    // Add criteria to exclude actors that are users or repository objects
-    $criteria = QubitActor::addGetOnlyActorsCriteria($criteria);
+    // Set role
+    $this->role = $this->getRequestParameter('role', 'all');
+    $options['role'] = $this->role;
     
-    // Page results
-    $pager = new QubitPager('QubitActor');
-    $pager->setCriteria($criteria);
-    $pager->setPage($this->page);
-    $pager->init();
-    $this->pager = $pager;
+    $criteria = new Criteria;
     
-    // Set offset and limit for hitlist criteria with values from pager
-    $criteria->setOffset($pager->getOffset());
-    $criteria->setLimit($pager->getLimit());
-    
     // Get results
-    $this->actors = QubitActor::get($criteria);
+    $this->actors = QubitActor::getList($this->culture, new Criteria, 
$options);
 
     //determine if user has edit priviliges
     $this->editCredentials = false;

Modified: trunk/apps/qubit/modules/actor/templates/listSuccess.php
===================================================================
--- trunk/apps/qubit/modules/actor/templates/listSuccess.php    2008-09-16 
17:49:16 UTC (rev 1383)
+++ trunk/apps/qubit/modules/actor/templates/listSuccess.php    2008-09-16 
18:58:10 UTC (rev 1384)
@@ -1,7 +1,7 @@
 <div class="pageTitle"><?php echo __('list %1%', array('%1%' => 
sfConfig::get('app_ui_label_actor'))) ?></div>
 
-<?php echo $pager->getNbResults() ?> results found.<br />
-Displaying results <?php echo $pager->getFirstIndice() ?> to  <?php echo 
$pager->getLastIndice() ?>
+<?php echo $actors->getNbResults() ?> results found.<br />
+Displaying results <?php echo $actors->getFirstIndice() ?> to  <?php echo 
$actors->getLastIndice() ?>
 <table class="list"><thead><tr>
   <th>
     <?php if ($sort == 'nameUp'): ?>
@@ -27,7 +27,7 @@
       <?php echo image_tag('up.gif', array('style' => 'padding-bottom: 3px'), 
'sort up') ?>
     <?php endif; ?>
   </th>
-</tr></thead><tbody><?php foreach ($actors as $actor): ?><tr>
+</tr></thead><tbody><?php foreach ($actors->getResults() as $actor): ?><tr>
   <td>
 
     <div>
@@ -44,23 +44,21 @@
     </td>
 </tr><?php endforeach; ?></tbody></table>
 
-<?php if ($pager->haveToPaginate()): ?>
+<?php if ($actors->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(), 
'actor/list?sort='.$sort.'&page='.$pager->getFirstPage()) ?>
-    <?php //echo link_to('&lt;', 
'informationobject/list?page='.$pager->getPreviousPage()) ?>
+  <?php $links = $actors->getLinks(); ?>
+  <?php if ($actors->getFirstPage() < $actors->getfirstPageLink()): ?>
+    <?php echo link_to($actors->getFirstPage(), 
'actor/list?sort='.$sort.'&page='.$actors->getFirstPage()) ?>
     ...
   <?php endif; ?>
   <?php foreach ($links as $page): ?>
-    <?php echo ($page == $pager->getPage()) ? $page : link_to($page, 
'actor/list?sort='.$sort.'&page='.$page) ?>
-    <?php if ($page != $pager->getCurrentMaxLink()): ?> <?php endif ?>
+    <?php echo ($page == $actors->getPage()) ? $page : link_to($page, 
'actor/list?sort='.$sort.'&page='.$page) ?>
+    <?php if ($page != $actors->getCurrentMaxLink()): ?> <?php endif ?>
   <?php endforeach ?>
-  <?php //echo link_to('&gt;', 
'informationobject/list?page='.$pager->getNextPage()) ?>
-  <?php if ($pager->getLastPage() > $pager->getLastPageLink()): ?>
+  <?php if ($actors->getLastPage() > $actors->getLastPageLink()): ?>
     ...
-    <?php echo link_to($pager->getLastPage(), 
'actor/list?sort='.$sort.'&page='.$pager->getLastPage()) ?>
+    <?php echo link_to($actors->getLastPage(), 
'actor/list?sort='.$sort.'&page='.$actors->getLastPage()) ?>
   <?php endif; ?>
 </div></p>
 <?php endif ?><br />

Modified: trunk/lib/model/QubitActor.php
===================================================================
--- trunk/lib/model/QubitActor.php      2008-09-16 17:49:16 UTC (rev 1383)
+++ trunk/lib/model/QubitActor.php      2008-09-16 18:58:10 UTC (rev 1384)
@@ -44,6 +44,81 @@
   }
   
   /**
+   * Get a paginated hitlist of actors
+   *
+   * @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())
+  {
+    $cultureFallback = (isset($options['cultureFallback'])) ? 
$options['cultureFallback'] : false;
+    $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']);
+    }
+    
+    // Add criteria to exclude actors that are users or repository objects
+    $criteria = QubitActor::addGetOnlyActorsCriteria($criteria);
+    
+    // Add sort criteria
+    switch($sort)
+    {
+      case 'typeDown':
+        $fallbackTable = 'QubitTerm';
+        $criteria->addJoin(QubitActor::ENTITY_TYPE_ID, QubitTerm::ID, 
Criteria::LEFT_JOIN);
+        $criteria->addDescendingOrderByColumn('name');
+        break;
+      case 'typeUp':
+        $fallbackTable = 'QubitTerm';
+        $criteria->addJoin(QubitActor::ENTITY_TYPE_ID, QubitTerm::ID, 
Criteria::LEFT_JOIN);
+        $criteria->addAscendingOrderByColumn('name');
+        break;
+      case 'nameDown':
+        $fallbackTable = 'QubitActor';
+        $criteria->addDescendingOrderByColumn('authorized_form_of_name');
+        break;
+      case 'nameUp':
+      default:
+        $fallbackTable = 'QubitActor';
+        $criteria->addAscendingOrderByColumn('authorized_form_of_name');
+    }
+      
+    // Do source culture fallback
+    if ($cultureFallback === true)
+    {
+      // Return a QubitQuery object
+      $options = array('returnClass'=>'QubitActor');
+      $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 
$fallbackTable, $culture, $options);
+    }
+    else
+    {
+      // Do straight joins without fallback
+      $criteria->addJoin(QubitActor::ID, QubitActorI18n::ID);
+      $criteria->addJoin(QubitActor::ENTITY_TYPE_ID, QubitTermI18n::ID, 
Criteria::LEFT_JOIN);
+      $criteria->add(QubitActorI18n::CULTURE, $culture);
+      $criteria->add(QubitTermI18n::CULTURE, $culture);
+    }
+    
+    // Page results
+    $pager = new QubitPager('QubitActor');
+    $pager->setCriteria($criteria);
+    $pager->setPage($page);
+    $pager->init();
+    
+    return $pager;
+  }
+  
+  /**
    * Append criteria to get only Actor objects that are NOT
    * a users or repository.
    *

Modified: trunk/lib/model/QubitRepository.php
===================================================================
--- trunk/lib/model/QubitRepository.php 2008-09-16 17:49:16 UTC (rev 1383)
+++ trunk/lib/model/QubitRepository.php 2008-09-16 18:58:10 UTC (rev 1384)
@@ -197,7 +197,7 @@
   }
   
   
-  public static function getList($culture, $criteria, $options)
+  public static function getList($culture, $criteria, $options=array())
   {
     $criteria = new Criteria;
     


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