Author: david
Date: Mon Oct 10 20:47:13 2011
New Revision: 10014
Log:
Add ability to sort file list
Added:
trunk/apps/qubit/modules/informationobject/templates/fileListCriteria.php
- copied, changed from r10001,
trunk/apps/qubit/modules/informationobject/templates/reportsSuccess.php
Modified:
trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php
Modified:
trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php
Mon Oct 10 19:33:32 2011 (r10013)
+++ trunk/apps/qubit/modules/informationobject/actions/fileListAction.class.php
Mon Oct 10 20:47:13 2011 (r10014)
@@ -28,6 +28,34 @@
*/
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(
+ 'title' => $this->context->i18n->__('Title'),
+ 'startDate' => $this->context->i18n->__('Date'),
+ 'locations' => $this->context->i18n->__('Location'),
+ 'referenceCode' => $this->context->i18n->__('Reference code'),
+ );
+
+ $this->form->setDefault($name, 'title');
+ $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;
@@ -36,6 +64,30 @@
$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);
@@ -80,10 +132,29 @@
);
}
}
+
+ // 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 strcasecmp($a[$sortBy], $b[$sortBy]);
+ });
+
+ // Sort dates in *descending* order
+ if ('startDate' == $sortBy)
+ {
+ $items = array_reverse($items, true);
+ }
+ }
+
}
}
- public function getLocationString($resource)
+ public static function getLocationString($resource)
{
$locations = array();
if (null !== ($physicalObjects = $resource->getPhysicalObjects()))
@@ -97,7 +168,7 @@
return implode('; ', $locations);
}
- public function getCreationDates($resource)
+ public static function getCreationDates($resource)
{
$creationEvents = $resource->getCreationEvents();
Copied and modified:
trunk/apps/qubit/modules/informationobject/templates/fileListCriteria.php (from
r10001, trunk/apps/qubit/modules/informationobject/templates/reportsSuccess.php)
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/reportsSuccess.php
Mon Oct 10 00:13:00 2011 (r10001, copy source)
+++ trunk/apps/qubit/modules/informationobject/templates/fileListCriteria.php
Mon Oct 10 20:47:13 2011 (r10014)
@@ -1,14 +1,14 @@
-<h1><?php echo __('Reports') ?></h1>
+<h1><?php echo __('File list - report criteria') ?></h1>
<h1 class="label"><?php echo $resource->__toString() ?></h1>
<?php echo $form->renderGlobalErrors() ?>
-<?php echo $form->renderFormTag(url_for(array($resource, 'module' =>
'informationobject', 'action' => 'reports'))) ?>
+<?php echo $form->renderFormTag(url_for(array($resource, 'module' =>
'informationobject', 'action' => 'fileList'))) ?>
<div class="section">
-<?php echo render_show(__('Select report'), $form->report) ?>
+<?php echo render_show(__('Select sort column'), $form->sortBy) ?>
</div>
--
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.