Author: david
Date: Thu Oct 13 13:56:06 2011
New Revision: 10077

Log:
Copy fileList action and templates to itemList

Added:
   trunk/apps/qubit/modules/informationobject/actions/itemListAction.class.php
      - copied unchanged from r10071, 
trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php
   trunk/apps/qubit/modules/informationobject/templates/itemListCriteria.php
      - copied unchanged from r10073, 
trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php
   trunk/apps/qubit/modules/informationobject/templates/itemListSuccess.php
      - copied unchanged from r10073, 
trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php

Copied: 
trunk/apps/qubit/modules/informationobject/actions/itemListAction.class.php 
(from r10071, 
trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/informationobject/actions/itemListAction.class.php 
Thu Oct 13 13:56:06 2011        (r10077, copy of r10071, 
trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php)
@@ -0,0 +1,200 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * File list report
+ *
+ * @package    qubit
+ * @subpackage informationobject
+ * @author     Peter Van Garderen <[email protected]>
+ * @author     David Juhasz <[email protected]>
+ * @version    svn:$Id$
+ */
+class InformationObjectFileListAction extends sfAction
+{
+  // Arrays not allowed in class constants
+  public static
+    $NAMES = array(
+      'sortBy'
+    );
+
+  protected function addField($name)
+  {
+    switch ($name)
+    {
+      case 'sortBy':
+        $choices = array(
+          'referenceCode' => $this->context->i18n->__('Reference code'),
+          'title' => $this->context->i18n->__('Title'),
+          'startDate' => $this->context->i18n->__('Date (most recent first)')
+        );
+
+        if ($this->getUser()->isAuthenticated())
+        {
+          $choices['locations'] = $this->context->i18n->__('Location');
+        }
+
+        $this->form->setDefault($name, 'referenceCode');
+        $this->form->setValidator($name, new sfValidatorChoice(array('choices' 
=> array_keys($choices))));
+        $this->form->setWidget($name, new sfWidgetFormChoice(array(
+          'expanded' => true,
+          'choices' => $choices)));
+
+        break;
+    }
+  }
+
+  public function execute($request)
+  {
+    $this->resource = $this->getRoute()->resource;
+    if (!isset($this->resource))
+    {
+      $this->forward404();
+    }
+
+    $this->form = new sfForm;
+
+    foreach ($this::$NAMES as $name)
+    {
+      $this->addField($name);
+    }
+
+    if ($request->isMethod('post'))
+    {
+      $this->form->bind($request->getPostParameters());
+      if ($this->form->isValid())
+      {
+        $this->generateReport($request);
+      }
+    }
+
+    else
+    {
+      return 'Criteria';
+    }
+  }
+
+  public function generateReport($request)
+  {
+    // Get "file" term in "level of description" taxonomy
+    $c2 = new Criteria;
+    $c2->addJoin(QubitTerm::ID, QubitTermI18n::ID, Criteria::INNER_JOIN);
+    $c2->add(QubitTermI18n::NAME, 'file');
+    $c2->add(QubitTermI18n::CULTURE, 'en');
+    $c2->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::LEVEL_OF_DESCRIPTION_ID);
+
+    $lod = QubitTermI18n::getOne($c2);
+
+    if (null === $lod)
+    {
+      throw new sfException('Can\'t find "file" level of description in term 
table');
+    }
+
+    $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);
+
+    // Filter drafts
+    $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
+
+    $this->results = array();
+    $this->resultCount = 0;
+    if (null !== ($results = QubitInformationObject::get($criteria)))
+    {
+      foreach($results as $item)
+      {
+        if ($lod->id == $item->levelOfDescriptionId)
+        {
+          $parentIsad = new sfIsadPlugin($item->parent);
+          $isad = new sfIsadPlugin($item);
+          $creationDates = self::getCreationDates($item);
+
+          $this->results[$parentIsad->__toString()][] = array(
+            'resource' => $item,
+            'referenceCode' => $isad->referenceCode,
+            'title' => $item->getTitle(array('cultureFallback' => true)),
+            'dates' => (isset($creationDates)) ? 
Qubit::renderDateStartEnd($creationDates->getDate(array('cultureFallback' => 
true)), $creationDates->startDate, $creationDates->endDate) : '&nbsp;',
+            'startDate' => (isset($creationDates)) ? $creationDates->startDate 
: null,
+            'accessConditions' => 
$item->getAccessConditions(array('cultureFallback' => true)),
+            'locations' => self::getLocationString($item)
+          );
+
+          $this->resultCount++;
+        }
+      }
+
+      // Sort parent names alphabetically
+      ksort($this->results);
+
+      // Sort items by selected criteria
+      $sortBy = $this->form->getValue('sortBy');
+      foreach ($this->results as $key => &$items)
+      {
+        uasort($items, function($a, $b) use ($sortBy) {
+           return strnatcasecmp($a[$sortBy], $b[$sortBy]); 
+        });
+
+        // Sort dates in *descending* order
+        if ('startDate' == $sortBy)
+        {
+          $items = array_reverse($items, true);
+        }
+      }
+
+    }
+  }
+
+  public static function getLocationString($resource)
+  {
+    $locations = array();
+    if (null !== ($physicalObjects = $resource->getPhysicalObjects()))
+    {
+      foreach ($physicalObjects as $item)
+      {
+        $locations[] = $item->getLabel();
+      }
+    }
+
+    return implode('; ', $locations);
+  }
+
+  public static function getCreationDates($resource)
+  {
+    $creationEvents = $resource->getCreationEvents();
+
+    if (0 == count($creationEvents))
+    {
+      if (isset($resource->parent))
+      {
+        return self::getCreationDates($resource->parent);
+      }
+    }
+    else
+    {
+      foreach ($creationEvents as $item)
+      {
+        if (null != $item->getDate(array('cultureFallback' => true)) || null 
!= $item->startDate)
+        {
+          return $item;
+        }
+      }
+    }
+  }
+}

Copied: 
trunk/apps/qubit/modules/informationobject/templates/itemListCriteria.php (from 
r10073, 
trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/informationobject/templates/itemListCriteria.php   
Thu Oct 13 13:56:06 2011        (r10077, copy of r10073, 
trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php)
@@ -0,0 +1,55 @@
+<div id="preview-message">
+  <?php echo __('Print preview') ?>
+  <?php echo link_to('Close', array($resource, 'module' => 
'informationobject', 'action' => 'fileList')) ?>
+</div>
+
+<h1 class="label"><?php echo __('File list') ?></h1>
+
+<?php $row = $startrow = 1; foreach ($results as $parent => $items): ?>
+
+  <h2 class="element-invisible"><?php echo __('%1% hierarchy', array('%1%' => 
sfConfig::get('app_ui_label_informationobject'))) ?></h2>
+  <div class="resource-hierarchy">
+    <ul>
+    <?php foreach ($items[0]['resource']->getAncestors()->orderBy('lft') as 
$ancestor): ?>
+      <?php if (QubitInformationObject::ROOT_ID != intval($ancestor->id)): ?>
+      <li><h3><?php $isad = new sfIsadPlugin($ancestor); echo 
$isad->__toString() ?></h3></li>
+      <?php endif; ?>
+    <?php endforeach; ?>
+    </ul>
+  </div>
+
+  <table>
+    <thead>
+      <tr>
+        <th><?php echo __('#') ?></th>
+        <th><?php echo __('Reference code') ?></th>
+        <th><?php echo __('Title') ?></th>
+        <th><?php echo __('Dates') ?></th>
+        <th><?php echo __('Access restrictions') ?></th>
+      <?php if ($sf_user->isAuthenticated()): ?>
+        <th><?php echo __('Retrieval information') ?></th>
+      <?php endif; ?>
+      </tr>
+    </thead><tbody>
+    <?php foreach ($items as $item): ?>
+      <tr>
+        <td class="row-number"><?php echo $row++ ?></td>
+        <td><?php echo $item['referenceCode'] ?></td>
+        <td><?php echo $item['title'] ?></td>
+        <td><?php echo $item['dates'] ?></td>
+        <td><?php echo isset($item['accessConditions']) ? 
$item['accessConditions'] : __('None') ?></td>
+      <?php if ($sf_user->isAuthenticated()): ?>
+        <td><?php echo $item['locations'] ?></td>
+      <?php endif; ?>
+      </tr>
+    <?php endforeach; ?>
+    </tbody>
+  </table>
+
+  <div class="result-count">
+    <?php echo __('Showing %1% to %2% of %3% results', array(
+      '%1%' => $startrow,
+      '%2%' => $startrow += count($items),
+      '%3%' => $resultCount + 1)) ?>
+  </div>
+<?php endforeach; ?>

Copied: 
trunk/apps/qubit/modules/informationobject/templates/itemListSuccess.php (from 
r10073, 
trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/informationobject/templates/itemListSuccess.php    
Thu Oct 13 13:56:06 2011        (r10077, copy of r10073, 
trunk/apps/qubit/modules/informationobject/templates/fileListSuccess.php)
@@ -0,0 +1,55 @@
+<div id="preview-message">
+  <?php echo __('Print preview') ?>
+  <?php echo link_to('Close', array($resource, 'module' => 
'informationobject', 'action' => 'fileList')) ?>
+</div>
+
+<h1 class="label"><?php echo __('File list') ?></h1>
+
+<?php $row = $startrow = 1; foreach ($results as $parent => $items): ?>
+
+  <h2 class="element-invisible"><?php echo __('%1% hierarchy', array('%1%' => 
sfConfig::get('app_ui_label_informationobject'))) ?></h2>
+  <div class="resource-hierarchy">
+    <ul>
+    <?php foreach ($items[0]['resource']->getAncestors()->orderBy('lft') as 
$ancestor): ?>
+      <?php if (QubitInformationObject::ROOT_ID != intval($ancestor->id)): ?>
+      <li><h3><?php $isad = new sfIsadPlugin($ancestor); echo 
$isad->__toString() ?></h3></li>
+      <?php endif; ?>
+    <?php endforeach; ?>
+    </ul>
+  </div>
+
+  <table>
+    <thead>
+      <tr>
+        <th><?php echo __('#') ?></th>
+        <th><?php echo __('Reference code') ?></th>
+        <th><?php echo __('Title') ?></th>
+        <th><?php echo __('Dates') ?></th>
+        <th><?php echo __('Access restrictions') ?></th>
+      <?php if ($sf_user->isAuthenticated()): ?>
+        <th><?php echo __('Retrieval information') ?></th>
+      <?php endif; ?>
+      </tr>
+    </thead><tbody>
+    <?php foreach ($items as $item): ?>
+      <tr>
+        <td class="row-number"><?php echo $row++ ?></td>
+        <td><?php echo $item['referenceCode'] ?></td>
+        <td><?php echo $item['title'] ?></td>
+        <td><?php echo $item['dates'] ?></td>
+        <td><?php echo isset($item['accessConditions']) ? 
$item['accessConditions'] : __('None') ?></td>
+      <?php if ($sf_user->isAuthenticated()): ?>
+        <td><?php echo $item['locations'] ?></td>
+      <?php endif; ?>
+      </tr>
+    <?php endforeach; ?>
+    </tbody>
+  </table>
+
+  <div class="result-count">
+    <?php echo __('Showing %1% to %2% of %3% results', array(
+      '%1%' => $startrow,
+      '%2%' => $startrow += count($items),
+      '%3%' => $resultCount + 1)) ?>
+  </div>
+<?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