Author: david
Date: Mon Oct 10 17:26:06 2011
New Revision: 10007

Log:
Put results in php array to allow sorting by arbitrary columns

Modified:
   trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php
   trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php

Modified: 
trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php 
Mon Oct 10 15:18:35 2011        (r10006)
+++ trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php 
Mon Oct 10 17:26:06 2011        (r10007)
@@ -41,10 +41,6 @@
       $request->limit = sfConfig::get('app_hits_per_page');
     }
 
-    $criteria = new Criteria;
-    $criteria->add(QubitInformationObject::LFT, $this->resource->lft, 
Criteria::GREATER_EQUAL);
-    $criteria->add(QubitInformationObject::RGT, $this->resource->rgt, 
Criteria::LESS_EQUAL);
-
     // Get "file" term in "level of description" taxonomy
     $c2 = new Criteria;
     $c2->addJoin(QubitTerm::ID, QubitTermI18n::ID, Criteria::INNER_JOIN);
@@ -59,41 +55,70 @@
       throw new sfException('Can\'t find "file" level of description in term 
table');
     }
 
-    $criteria->add(QubitInformationObject::LEVEL_OF_DESCRIPTION_ID, $lod->id);
-
-    switch ($request->sort)
-    {
-      case 'titleDown':
-        $criteria->addDescendingOrderByColumn('title');
-
-        break;
-
-      case 'titleUp':
-        $criteria->addAscendingOrderByColumn('title');
-
-        break;
-
-      case 'updatedDown':
-        $criteria->addDescendingOrderByColumn(QubitObject::UPDATED_AT);
-
-        break;
+    $criteria = new Criteria;
+    $criteria->add(QubitInformationObject::LFT, $this->resource->lft, 
Criteria::GREATER_EQUAL);
+    $criteria->add(QubitInformationObject::RGT, $this->resource->rgt, 
Criteria::LESS_EQUAL);
+    $criteria->addAscendingOrderByColumn(QubitInformationObject::LFT);
 
-      case 'updatedUp':
-        $criteria->addAscendingOrderByColumn(QubitObject::UPDATED_AT);
+    // Filter drafts
+    $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
 
-        break;
+    $this->results = array();
+    if (null !== ($results = QubitInformationObject::get($criteria)))
+    {
+      foreach($results as $item)
+      {
+        if ($lod->id == $item->levelOfDescriptionId)
+        {
+          $parentIsad = new sfIsadPlugin($item->parent);
+          $isad = new sfIsadPlugin($item);
+          $creationEvent = self::getCreationEvent($item);
+
+          $this->results[$parentIsad->__toString()][] = array(
+            'resource' => $item,
+            'referenceCode' => $isad->referenceCode,
+            'title' => $item->getTitle(array('cultureFallback' => true)),
+            'dates' => 
Qubit::renderDateStartEnd($creationEvent->getDate(array('cultureFallback' => 
true)), $creationEvent->startDate, $creationEvent->endDate),
+            'startDate' => $creationEvent->startDate,
+            'accessConditions' => 
$item->getAccessConditions(array('cultureFallback' => true)),
+            'locations' => self::getLocationString($item)
+          );
+        }
+      }
+    }
+  }
 
-      default:
-        $criteria->addAscendingOrderByColumn('title');
+  public function getLocationString($resource)
+  {
+    $locations = array();
+    if (null !== ($physicalObjects = $resource->getPhysicalObjects()))
+    {
+      foreach ($physicalObjects as $item)
+      {
+        $locations[] = $item->getLabel();
+      }
     }
 
-    // Do source culture fallback
-    $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 
'QubitInformationObject');
+    return implode('; ', $locations);
+  }
 
-    // Filter drafts
-    $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
+  public function getCreationEvent($resource)
+  {
+    if (0 == count($creationEvents = $resource->getCreationEvents()))
+    {
+      // Creation date will inherit down the hierarchy
+      foreach ($resource->getAncestors() as $item)
+      {
+        if (0 < count($creationEvents = $item->getCreationEvents()))
+        {
+          break;
+        }
+      }
+    }
 
-    // Page results
-    $this->informationObjects = QubitInformationObject::get($criteria);
+    if (0 < count($creationEvents))
+    {
+      return $creationEvents[0];
+    }
   }
 }

Modified: 
trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php    
Mon Oct 10 15:18:35 2011        (r10006)
+++ trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php    
Mon Oct 10 17:26:06 2011        (r10007)
@@ -4,135 +4,26 @@
 
 <h1 class="label"><?php $isad = new sfIsadPlugin($resource); echo 
$isad->__toString() ?></h1>
 
-<table class="sticky-enabled">
-  <thead>
-    <tr>
-      <th>
-        <?php echo __('Title') ?>
-        <?php if ($sf_user->isAuthenticated()): ?>
-          <?php if ('titleDown' == $sf_request->sort): ?>
-            <?php echo link_to(image_tag('up.gif'), array('sort' => 'titleUp') 
+ $sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) ?>
-          <?php elseif ('titleUp' == $sf_request->sort): ?>
-            <?php echo link_to(image_tag('down.gif'), array('sort' => 
'titleDown') + $sf_request->getParameterHolder()->getAll(), array('title' => 
__('Sort'))) ?>
-          <?php endif; ?>
-        <?php else: ?>
-          <?php if (('titleDown' != $sf_request->sort && 'updatedDown' != 
$sf_request->sort && 'updatedUp' != $sf_request->sort) || ('titleUp' == 
$sf_request->sort)): ?>
-            <?php echo link_to(image_tag('down.gif'), array('sort' => 
'titleDown') + $sf_request->getParameterHolder()->getAll(), array('title' => 
__('Sort'))) ?>
-          <?php endif; ?>
-          <?php if ('titleDown' == $sf_request->sort): ?>
-            <?php echo link_to(image_tag('up.gif'), array('sort' => 'titleUp') 
+ $sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) ?>
-          <?php endif; ?>
-        <?php endif; ?> 
-      </th><th>
-        <?php if ($sf_user->isAuthenticated()): ?>
-          <?php if ('titleUp' == $sf_request->sort || 'titleDown' == 
$sf_request->sort): ?>
-            <?php echo __('Level') ?>
-          <?php else: ?>
-            <?php if (sfConfig::get('app_multi_repository')): ?>
-              <?php echo sfConfig::get('app_ui_label_repository') ?>
-            <?php else: ?>
-              <?php echo __('Level') ?>
-            <?php endif; ?>
-          <?php endif; ?>
-        <?php else: ?>
-          <?php if ('updatedUp' == $sf_request->sort || 'updatedDown' == 
$sf_request->sort): ?>
-            <?php if (sfConfig::get('app_multi_repository')): ?>
-              <?php echo sfConfig::get('app_ui_label_repository') ?>
-            <?php else: ?>
-              <?php echo __('Level') ?>
-            <?php endif; ?>
-          <?php else: ?>
-            <?php echo __('Level') ?>
-          <?php endif; ?>
-        <?php endif; ?>
-      </th><th>
-        <?php if ('titleDown' == $sf_request->sort || 'titleUp' == 
$sf_request->sort): ?>
-          <?php if (sfConfig::get('app_multi_repository')): ?>
-            <?php echo __(sfConfig::get('app_ui_label_repository')) ?>
-          <?php else: ?>
-            <?php echo __(sfConfig::get('app_ui_label_creator')) ?>
-          <?php endif; ?>
-        <?php else: ?>
-          <?php if ('updatedDown' == $sf_request->sort || 'updatedUp' == 
$sf_request->sort || $sf_user->isAuthenticated()): ?>
-            <?php echo __('Updated') ?>
-            <?php if ('updatedUp' == $sf_request->sort): ?>
-              <?php echo link_to(image_tag('up.gif'), array('sort' => 
'updatedDown') + $sf_request->getParameterHolder()->getAll(), array('title' => 
__('Sort'))) ?>
-            <?php else: ?>
-              <?php echo link_to(image_tag('down.gif'), array('sort' => 
'updatedUp') + $sf_request->getParameterHolder()->getAll(), array('title' => 
__('Sort'))) ?>
-            <?php endif; ?>
-          <?php else: ?>
-            <?php if (sfConfig::get('app_multi_repository')): ?>
-              <?php echo __(sfConfig::get('app_ui_label_repository')) ?>
-            <?php else: ?>
-              <?php echo __(sfConfig::get('app_ui_label_creator')) ?>
-            <?php endif; ?>
-          <?php endif; ?>
-        <?php endif; ?>
-      </th>
-    </tr>
-  </thead><tbody>
-    <?php foreach ($informationObjects as $item): ?>
-      <tr class="<?php echo 0 == @++$row % 2 ? 'even' : 'odd' ?>">
-        <td>
-          <?php echo link_to(render_title($item), array($item, 'module' => 
'informationobject')) ?><?php if (QubitTerm::PUBLICATION_STATUS_DRAFT_ID == 
$item->getPublicationStatus()->status->id): ?> <span 
class="publicationStatus"><?php echo $item->getPublicationStatus()->status 
?></span><?php endif; ?>
-        </td><td>
-          <?php if ($sf_user->isAuthenticated()): ?>
-            <?php if ('titleUp' == $sf_request->sort || 'titleDown' == 
$sf_request->sort): ?>
-              <?php echo $item->levelOfDescription ?>
-            <?php else: ?>
-              <?php if (sfConfig::get('app_multi_repository')): ?>
-                <?php if (null !== $repository = 
$item->getRepository(array('inherit' => true))): ?>
-                  <?php echo link_to(render_title($repository), 
array($repository, 'module' => 'repository')) ?>
-                <?php endif; ?>
-              <?php else: ?>
-                <?php echo $item->levelOfDescription ?>
-              <?php endif; ?>
-            <?php endif; ?>
-          <?php else: ?>
-            <?php if ('updatedUp' == $sf_request->sort || 'updatedDown' == 
$sf_request->sort): ?>
-              <?php if (sfConfig::get('app_multi_repository')): ?>
-                <?php if (null !== $repository = 
$item->getRepository(array('inherit' => true))): ?>
-                  <?php echo link_to(render_title($repository), 
array($repository, 'module' => 'repository')) ?>
-                <?php endif; ?>
-              <?php else: ?>
-               <?php echo $item->levelOfDescription ?>
-              <?php endif; ?>
-            <?php else: ?>
-              <?php echo $item->levelOfDescription ?>
-            <?php endif; ?>
-          <?php endif; ?>
-        </td><td>
-          <?php if ('titleDown' == $sf_request->sort || 'titleUp' == 
$sf_request->sort): ?>
-            <?php if (sfConfig::get('app_multi_repository')): ?>
-              <?php if (null !== $repository = 
$item->getRepository(array('inherit' => true))): ?>
-                <?php echo link_to(render_title($repository), 
array($repository, 'module' => 'repository')) ?>
-              <?php endif; ?>
-            <?php else: ?>
-              <ul>
-                <?php foreach ($item->getCreators(array('inherit' => true)) as 
$creator): ?>
-                  <li><?php echo link_to(render_title($creator), 
array($creator, 'module' => 'actor')) ?></li>
-                <?php endforeach; ?>
-              </ul>
-            <?php endif; ?>
-          <?php else: ?>
-            <?php if ('updatedDown' == $sf_request->sort || 'updatedUp' == 
$sf_request->sort || $sf_user->isAuthenticated()): ?>
-              <?php echo format_date($item->updatedAt, 'f') ?>
-            <?php else: ?>
-              <?php if (sfConfig::get('app_multi_repository')): ?>
-                <?php if (null !== $repository = 
$item->getRepository(array('inherit' => true))): ?>
-                  <?php echo link_to(render_title($repository), 
array($repository, 'module' => 'repository')) ?>
-                <?php endif; ?>
-              <?php else: ?>
-                <ul>
-                  <?php foreach ($item->getCreators(array('inherit' => true)) 
as $creator): ?>
-                    <li><?php echo link_to(render_title($creator), 
array($creator, 'module' => 'actor')) ?></li>
-                  <?php endforeach; ?>
-                </ul>
-              <?php endif; ?>
-            <?php endif; ?>
-          <?php endif; ?>
-        </td>
+<?php foreach ($results as $parent => $items): ?>
+  <h2><?php echo $parent ?></h2>
+
+  <table>
+    <thead>
+      <tr>
+        <th><?php echo __('Title') ?></th>
+        <th><?php echo __('Dates') ?></th>
+        <th><?php echo __('Access restrictions') ?></th>
+        <th><?php echo __('Retrival information') ?></th>
+      </tr>
+    </thead><tbody>
+    <?php foreach ($items as $item): ?>
+      <tr>
+        <td><?php echo $item['title'] ?></td>
+        <td><?php echo $item['dates'] ?></td>
+        <td><?php echo $item['accessConditions'] ?></td>
+        <td><?php echo $item['locations'] ?></td>
       </tr>
     <?php endforeach; ?>
-  </tbody>
-</table>
+    </tbody>
+  </table>
+<?php endforeach; ?>

-- 
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.com/group/qubit-commits?hl=en.

Reply via email to