Author: sevein
Date: Tue Aug  9 13:20:04 2011
New Revision: 9471

Log:
Add index/list/browse to rightsholder

Added:
   trunk/apps/qubit/modules/rightsholder/actions/browseAction.class.php
   trunk/apps/qubit/modules/rightsholder/actions/indexAction.class.php
   trunk/apps/qubit/modules/rightsholder/actions/listAction.class.php
   trunk/apps/qubit/modules/rightsholder/templates/browseSuccess.php
   trunk/apps/qubit/modules/rightsholder/templates/indexSuccess.php

Added: trunk/apps/qubit/modules/rightsholder/actions/browseAction.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/rightsholder/actions/browseAction.class.php        
Tue Aug  9 13:20:04 2011        (r9471)
@@ -0,0 +1,78 @@
+<?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/>.
+ */
+
+class RightsHolderBrowseAction extends sfAction
+{
+  public function execute($request)
+  {
+    if (!$this->context->user->hasCredential(array('contributor', 'editor', 
'administrator'), false))
+    {
+      QubitAcl::forwardUnauthorized();
+    }
+
+    if (!isset($request->limit))
+    {
+      $request->limit = sfConfig::get('app_hits_per_page');
+    }
+
+    $criteria = new Criteria;
+
+    // Do source culture fallback
+    $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 
'QubitActor');
+
+    switch ($request->sort)
+    {
+      case 'nameDown':
+        $criteria->addDescendingOrderByColumn('authorized_form_of_name');
+
+        break;
+
+      case 'nameUp':
+        $criteria->addAscendingOrderByColumn('authorized_form_of_name');
+
+        break;
+
+      case 'updatedDown':
+        $criteria->addDescendingOrderByColumn(QubitObject::UPDATED_AT);
+
+        break;
+
+      case 'updatedUp':
+        $criteria->addAscendingOrderByColumn(QubitObject::UPDATED_AT);
+
+        break;
+
+      default:
+        if (!$this->getUser()->isAuthenticated())
+        {
+          $criteria->addAscendingOrderByColumn('authorized_form_of_name');
+        }
+        else
+        {
+          $criteria->addDescendingOrderByColumn(QubitObject::UPDATED_AT);
+        }
+    }
+
+    // Page results
+    $this->pager = new QubitPager('QubitRightsHolder');
+    $this->pager->setCriteria($criteria);
+    $this->pager->setMaxPerPage($request->limit);
+    $this->pager->setPage($request->page);
+  }
+}

Added: trunk/apps/qubit/modules/rightsholder/actions/indexAction.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/rightsholder/actions/indexAction.class.php Tue Aug 
 9 13:20:04 2011        (r9471)
@@ -0,0 +1,65 @@
+<?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/>.
+ */
+
+class RightsHolderIndexAction extends sfAction
+{
+  public function execute($request)
+  {
+    $this->resource = $this->getRoute()->resource;
+
+    // Check that this isn't the root
+    if (!isset($this->resource->parent))
+    {
+      $this->forward404();
+    }
+
+    // Check user authorization
+    if (!QubitAcl::check($this->resource, 'read'))
+    {
+      QubitAcl::forwardUnauthorized();
+    }
+
+    if (1 > strlen($title = $this->resource->__toString()))
+    {
+      $title = $this->context->i18n->__('Untitled');
+    }
+
+    $this->response->setTitle("$title - {$this->response->getTitle()}");
+
+    if (QubitAcl::check($this->resource, 'update'))
+    {
+      $validatorSchema = new sfValidatorSchema;
+      $values = array();
+
+      $validatorSchema->authorizedFormOfName = new sfValidatorString(array(
+        'required' => true), array(
+        'required' => $this->context->i18n->__('Authorized form of name - This 
is a mandatory element.')));
+      $values['authorizedFormOfName'] = 
$this->resource->getAuthorizedFormOfName(array('cultureFallback' => true));
+
+      try
+      {
+        $validatorSchema->clean($values);
+      }
+      catch (sfValidatorErrorSchema $e)
+      {
+        $this->errorSchema = $e;
+      }
+    }
+  }
+}

Added: trunk/apps/qubit/modules/rightsholder/actions/listAction.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/rightsholder/actions/listAction.class.php  Tue Aug 
 9 13:20:04 2011        (r9471)
@@ -0,0 +1,78 @@
+<?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/>.
+ */
+
+class RightsHolderListAction extends sfAction
+{
+  public function execute($request)
+  {
+    if (!$this->context->user->hasCredential(array('contributor', 'editor', 
'administrator'), false))
+    {
+      QubitAcl::forwardUnauthorized();
+    }
+
+    if (!isset($request->limit))
+    {
+      $request->limit = sfConfig::get('app_hits_per_page');
+    }
+
+    if (isset($request->subquery))
+    {
+      try
+      {
+        // Parse query string
+        $query = QubitSearch::getInstance()->parse($request->subquery);
+      }
+      catch (Exception $e)
+      {
+        $this->error = $e->getMessage();
+
+        return;
+      }
+    }
+
+    
$query->addSubquery(QubitSearch::getInstance()->addTerm('QubitRightsHolder', 
'className'), true);
+
+    $this->pager = new QubitArrayPager;
+
+    try
+    {
+      $this->pager->hits = 
QubitSearch::getInstance()->getEngine()->getIndex()->find($query);
+    }
+    catch (Exception $e)
+    {
+      $this->error = $e->getMessage();
+
+      return;
+    }
+
+    $this->pager->setMaxPerPage($request->limit);
+    $this->pager->setPage($request->page);
+
+    $ids = array();
+    foreach ($this->pager->getResults() as $hit)
+    {
+      $ids[] = $hit->getDocument()->id;
+    }
+
+    $criteria = new Criteria;
+    $criteria->add(QubitRightsHolder::ID, $ids, Criteria::IN);
+
+    $this->rightsHolders = QubitRightsHolder::get($criteria);
+  }
+}

Added: trunk/apps/qubit/modules/rightsholder/templates/browseSuccess.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/rightsholder/templates/browseSuccess.php   Tue Aug 
 9 13:20:04 2011        (r9471)
@@ -0,0 +1,63 @@
+<?php use_helper('Date') ?>
+
+<div class="section tabs">
+
+  <h2 class="element-invisible"><?php echo __('Rights holder browse options') 
?></h2>
+
+  <div class="content">
+    <ul class="clearfix links">
+      <li<?php if ('nameDown' != $sf_request->sort && 'nameUp' != 
$sf_request->sort): ?> class="active"<?php endif; ?>><?php echo 
link_to(__('Recent changes'), array('sort' => 'updatedDown') + 
$sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) 
?></li>
+      <li<?php if ('nameDown' == $sf_request->sort || 'nameUp' == 
$sf_request->sort): ?> class="active"<?php endif; ?>><?php echo 
link_to(__('Alphabetic'), array('sort' => 'nameUp') + 
$sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) 
?></li>
+    </ul>
+  </div>
+
+</div>
+
+<h1><?php echo __('Browse rights holder') ?></h1>
+
+<table class="sticky-enabled">
+  <thead>
+    <tr>
+      <th>
+        <?php echo __('Name') ?>
+        <?php if ('nameDown' == $sf_request->sort): ?>
+          <?php echo link_to(image_tag('up.gif'), array('sort' => 'nameUp') + 
$sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) ?>
+        <?php elseif ('nameUp' == $sf_request->sort): ?>
+          <?php echo link_to(image_tag('down.gif'), array('sort' => 
'nameDown') + $sf_request->getParameterHolder()->getAll(), array('title' => 
__('Sort'))) ?>
+        <?php endif; ?>
+      </th>
+      <?php if (!in_array($sf_request->sort, array('nameDown', 'nameUp'))): ?>
+        <th>
+          <?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; ?>
+        </th>
+      <?php endif; ?>
+    </tr>
+  </thead><tbody>
+    <?php foreach ($pager->getResults() as $item): ?>
+      <tr class="<?php echo 0 == ++$row % 2 ? 'even' : 'odd' ?>">
+        <td>
+          <?php echo link_to(render_title($item), array($item, 'module' => 
'rightsholder')) ?>
+        </td>
+        <?php if (!in_array($sf_request->sort, array('nameDown', 'nameUp'))): 
?>
+          <td>
+            <?php echo format_date($item->updatedAt, 'f') ?>
+          </td>
+        <?php endif; ?>
+      </tr>
+    <?php endforeach; ?>
+  </tbody>
+</table>
+
+<?php echo get_partial('default/pager', array('pager' => $pager)) ?>
+
+<div class="search">
+  <form action="<?php echo url_for(array('module' => 'rightsholder', 'action' 
=> 'list')) ?>">
+    <input name="subquery" value="<?php echo 
esc_entities($sf_request->subquery) ?>"/>
+    <input class="form-submit" type="submit" value="<?php echo __('Search 
rightsholder') ?>"/>
+  </form>
+</div>

Added: trunk/apps/qubit/modules/rightsholder/templates/indexSuccess.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/rightsholder/templates/indexSuccess.php    Tue Aug 
 9 13:20:04 2011        (r9471)
@@ -0,0 +1,39 @@
+<h1><?php echo __('View rights holder') ?></h1>
+
+<?php echo link_to_if(QubitAcl::check($resource, 'update'), '<h1 
class="label">'.render_title($resource).'</h1>', array($resource, 'module' => 
'rightsholder', 'action' => 'edit'), array('title' => __('Edit rights 
holder'))) ?>
+
+<?php if (isset($errorSchema)): ?>
+  <div class="messages error">
+    <ul>
+      <?php foreach ($errorSchema as $error): ?>
+        <li><?php echo $error ?></li>
+      <?php endforeach; ?>
+    </ul>
+  </div>
+<?php endif; ?>
+
+<?php echo render_show(__('Authorized form of name'), 
render_value($resource->getAuthorizedFormOfName(array('cultureFallback' => 
true)))) ?>
+
+<div class="actions section">
+
+  <h2 class="element-invisible"><?php echo __('Actions') ?></h2>
+
+  <div class="content">
+    <ul class="clearfix links">
+
+      <?php if (QubitAcl::check($resource, 'update')): ?>
+        <li><?php echo link_to(__('Edit'), array($resource, 'module' => 
'rightsholder', 'action' => 'edit'), array('title' => __('Edit'))) ?></li>
+      <?php endif; ?>
+
+      <?php if (QubitAcl::check($resource, 'delete')): ?>
+        <li><?php echo link_to(__('Delete'), array($resource, 'module' => 
'rightsholder', 'action' => 'delete'), array('title' => __('Delete'))) ?></li>
+      <?php endif; ?>
+
+      <?php if (QubitAcl::check($resource, 'create')): ?>
+        <li><?php echo link_to(__('Add new'), array('module' => 
'rightsholder', 'action' => 'add'), array('title' => __('Add new'))) ?></li>
+      <?php endif; ?>
+
+    </ul>
+  </div>
+
+</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.

Reply via email to