Author: sevein
Date: Wed Apr 18 17:02:54 2012
New Revision: 11470

Log:
Move taxonomy browser to main app

Deleted:
   branches/2.0/plugins/qtDominionPlugin/modules/taxonomy/
Modified:
   branches/2.0/apps/qubit/modules/taxonomy/actions/browseAction.class.php
   branches/2.0/apps/qubit/modules/taxonomy/templates/browseSuccess.php

Modified: 
branches/2.0/apps/qubit/modules/taxonomy/actions/browseAction.class.php
==============================================================================
--- branches/2.0/apps/qubit/modules/taxonomy/actions/browseAction.class.php     
Wed Apr 18 15:50:17 2012        (r11469)
+++ branches/2.0/apps/qubit/modules/taxonomy/actions/browseAction.class.php     
Wed Apr 18 17:02:54 2012        (r11470)
@@ -26,57 +26,115 @@
       $request->limit = sfConfig::get('app_hits_per_page');
     }
 
-    // HACK Use id deliberately, vs. slug, because "Subjects" and "Places"
-    // menus still use id
-    $this->resource = QubitTaxonomy::getById($request->id);
-    if (!isset($this->resource))
+    // determine what kind of term we are browsing
+    switch ($request->id)
     {
-      $this->forward404();
-    }
-
-    $criteria = new Criteria;
-    $criteria->add(QubitTerm::TAXONOMY_ID, $this->resource->id);
+      case QubitTaxonomy::SUBJECT_ID:
+        $this->field = 'subjects';
+        break;
 
-    $criteria->addJoin(QubitTerm::ID, QubitObjectTermRelation::TERM_ID);
-    $criteria->addJoin(QubitObjectTermRelation::OBJECT_ID, 
QubitInformationObject::ID);
+      case QubitTaxonomy::PLACE_ID:
+        $this->field = 'places';
+        break;
 
-    $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
+      case '':
+        // TODO: no ID specified, handle error condition (redirect?)
+        break;
+    }
 
-    // Do culture fallback
-    $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 
'QubitTerm');
+    // retrieve all institutions
+    $query = new Elastica_Query(new Elastica_Query_Term(array('taxonomyId' => 
$this->request->id)));
+    $query->setSort(array('_score' => 'desc', 'slug' => 'asc'));
+//    $query = $this->facetQuery($query);
 
-    $criteria->addGroupByColumn(QubitTerm::ID);
-    $criteria->addAsColumn('hits', 'COUNT('.QubitTerm::ID.')');
+    // set paging for request
+    $query->setLimit($this->request->limit);
 
-    switch ($request->sort)
+    if (!empty($this->request->page))
     {
-      case 'hitsDown':
-        $criteria->addDescendingOrderByColumn('hits');
-
-        break;
-
-      case 'hitsUp':
-        $criteria->addAscendingOrderByColumn('hits');
+      $query->setFrom(($this->request->page - 1) * $this->request->limit);
+    }
 
-        break;
+    try
+    {
+      $resultSet = 
QubitSearch::getInstance()->index->getType('QubitTerm')->search($query);
+    }
+    catch (Exception $e)
+    {
+      $this->error = $e->getMessage();
 
-      case 'termNameDown':
-        $criteria->addDescendingOrderByColumn('name');
+      return;
+    }
 
-        break;
+    // mock up a QubitPager for partial template backward compatibility
+    $this->pager = new stdClass();
+    $this->pager->resultSet = $resultSet;
 
-      case 'termNameUp':
-      default:
-        $criteria->addAscendingOrderByColumn('name');
+    if (0 < $resultSet->getTotalHits())
+    {
+      $this->pager->resultSet = $resultSet;
+      $this->pager->page = $request->page ? $request->page : 1;
 
-        break;
+      if ($resultSet->hasFacets())
+      {
+        // build lookup tables for I18nized values
+        foreach ($resultSet->getFacets() as $name => $facet)
+        {
+          $ids = array();
+          foreach ($facet['terms'] as $term)
+          {
+            $ids[$term['term']] = $term['count'];
+          }
+
+          switch ($name)
+          {
+            case 'types':
+              $criteria = new Criteria;
+              $criteria->add(QubitObjectTermRelation::ID, array_keys($ids), 
Criteria::IN);
+
+              $types = QubitObjectTermRelation::get($criteria);
+
+              foreach ($types as $type)
+              {
+                $typeNames[$type->id] = 
$type->term->getName(array('cultureFallback' => true, 'culture' => 
$this->context->user->getCulture()));
+              }
+
+              foreach ($facet['terms'] as &$term)
+              {
+                $facets[strtr($name, '.', '_')]['terms'][$term['term']] = 
array('count' => $term['count'],
+                                                                               
 'term' => $typeNames[$term['term']]);
+              }
+              break;
+
+            case 'contact.i18n.region':
+              foreach ($facet['terms'] as $term)
+              {
+                $facets[strtr($name, '.', '_')]['terms'][$term['term']] = 
array('count' => $term['count'],
+                                                                               
 'term' => $term['term']);
+              }
+              break;
+          }
+        }
+        $this->pager->facets = $facets;
+      }
     }
+    else if (empty($this->error))
+    {
+      // no error, must be empty result set
+      $this->error = $this->context->i18n->__('No %1% found.', array('%1%' => 
__($this->field)));
+    }
+  }
 
-    $this->pager = new QubitPager('QubitTerm');
-    $this->pager->setCriteria($criteria);
-    $this->pager->setMaxPerPage($request->limit);
-    $this->pager->setPage($request->page);
+  public function facetQuery($query)
+  {
+    foreach (array('types', 'contact.i18n.region') as $field)
+    {
+      $facet = new Elastica_Facet_Terms($field);
+      $facet->setField($field);
+      $facet->setSize(50);
+      $query->addFacet($facet);
+    }
 
-    $this->terms = $this->pager->getResults();
+    return $query;
   }
 }

Modified: branches/2.0/apps/qubit/modules/taxonomy/templates/browseSuccess.php
==============================================================================
--- branches/2.0/apps/qubit/modules/taxonomy/templates/browseSuccess.php        
Wed Apr 18 15:50:17 2012        (r11469)
+++ branches/2.0/apps/qubit/modules/taxonomy/templates/browseSuccess.php        
Wed Apr 18 17:02:54 2012        (r11470)
@@ -1,62 +1,66 @@
-<div class="section tabs">
+<div id="search-results">
 
-  <h2 class="element-invisible"><?php echo __('Browse options') ?></h2>
+  <div class="row">
 
-  <div class="content">
-    <ul class="clearfix links">
-      <li<?php if ('hitsUp' == $sf_request->sort || 'hitsDown' == 
$sf_request->sort): ?> class="active"<?php endif; ?>><?php echo 
link_to(__('Results'), array('sort' => 'hitsUp') + 
$sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) 
?></li>
-      <li<?php if ('hitsUp' != $sf_request->sort && 'hitsDown' != 
$sf_request->sort): ?> class="active"<?php endif; ?>><?php echo 
link_to(__('Alphabetic'), array('sort' => 'termNameUp') + 
$sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) 
?></li>
-    </ul>
+    <div class="span12" id="headline">
+      <h1>
+        <?php echo 
image_tag('/plugins/qtDominionPlugin/images/icons-large/icon-'.$field.'.png', 
array('width' => '42', 'height' => '42')) ?>
+        <?php echo __('%1% %2%', array('%1%' => 
$pager->resultSet->getTotalHits(), '%2%' => ucfirst($field))); ?>
+      </h1>
+    </div>
+
+    <div id="filter" class="span12 mobileonly">
+      <h2 class="widebtn gray btn-huge" data-toggle="collapse" 
data-target="#facets"><?php echo __('Filter %1% %2%', array('%1%' => 
$pager->resultSet->getTotalHits(), '%2%' => ucfirst($field))); ?></h2>
+    </div>
   </div>
 
-</div>
+  <div class="row">
+    <div class="span3" id="facets">
+      <!-- FIXME: HACK HERE -->.
+    </div><!-- /.column .sidebar -->
 
-<h1><?php echo __('Browse %1%', array('%1%' => render_title($resource))) 
?></h1>
+    <div class="span9" id="grid">
+      <div id="print-date">
+        Printed: 2012-02-14
+      </div>
 
-<table class="sticky-enabled">
-  <thead>
-    <tr>
-      <th>
-        <?php echo render_title($resource) ?>
-        <?php if ('termNameDown' == $sf_request->sort): ?>
-          <?php echo link_to(image_tag('up.gif'), array('sort' => 
'termNameUp') + $sf_request->getParameterHolder()->getAll(), array('title' => 
__('Sort'))) ?>
-        <?php elseif ('termNameUp' == $sf_request->sort || 
!in_array($sf_request->sort, array('hitsDown', 'hitsUp'))): ?>
-          <?php echo link_to(image_tag('down.gif'), array('sort' => 
'termNameDown') + $sf_request->getParameterHolder()->getAll(), array('title' => 
__('Sort'))) ?>
-        <?php endif; ?>
-      </th><th>
-        <?php echo __('Results') ?>
-        <?php if ('hitsDown' == $sf_request->sort): ?>
-          <?php echo link_to(image_tag('up.gif'), array('sort' => 'hitsUp') + 
$sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) ?>
-        <?php elseif ('hitsUp' == $sf_request->sort): ?>
-          <?php echo link_to(image_tag('down.gif'), array('sort' => 
'hitsDown') + $sf_request->getParameterHolder()->getAll(), array('title' => 
__('Sort'))) ?>
-        <?php endif; ?>
-      </th>
-    </tr>
-  </thead><tbody>
-    <?php foreach ($terms as $item): ?>
-      <tr class="<?php echo 0 == @++$row % 2 ? 'even' : 'odd' ?>">
-        <td>
-          <?php echo link_to(render_title($item), array($item, 'module' => 
'term', 'action' => 'browseTerm')) ?>
-        </td><td>
-          <?php echo $item->countRelatedInformationObjects() ?>
-        </td>
-      </tr>
-    <?php endforeach; ?>
-  </tbody>
-</table>
-
-<?php echo get_partial('default/pager', array('pager' => $pager)) ?>
-
-<div class="actions section">
-
-  <h2 class="element-invisible"><?php echo __('Actions') ?></h2>
-
-  <div class="content">
-    <ul class="clearfix links">
-      <?php if (QubitAcl::check($resource, array('edit', 'createTerm'))): ?>
-        <li><?php echo link_to(__('Add new'), array('module' => 'term', 
'action' => 'add', 'taxonomy' => url_for(array($resource, 'module' => 
'taxonomy')))) ?></li>
-      <?php endif; ?>
-    </ul>
-  </div>
+      <div class="row">
+        <div class="span9">
+
+          <?php foreach ($pager->resultSet->getResults() as $hit): ?>
+
+            <?php $doc = $hit->getData(); ?>
+            <?php foreach ($doc['i18n'] as $i18n): ?>
+
+              <?php $doc[$i18n['culture']] = $i18n; ?>
+
+            <?php endforeach; ?>
+            <?php unset($doc['i18n']); // continue; ?>
+
+            <div class="institution maxi">
+              <h2 class="filltext"><?php echo 
link_to($doc[$sf_user->getCulture()]['name'] ?: 
$doc[$doc['sourceCulture']]['name'], array('module' => 'search', $field .'_id' 
=> $hit->getId())) ?></h2>
+            </div>
+
+          <?php endforeach; ?>
+
+        </div>
+      </div>
+
+      <div class="row">
+        <div class="span9">
+          <?php if ($pager->resultSet->getTotalHits() > $pager->maxPerPage): ?>
+
+          <!-- FIXME: these should probably share a line -->
+          <?php if (1 < $pager->page): ?>
+            <?php echo link_to('&laquo;'. __('Previous'), array('page' => 
$pager->page - 1) + $sf_request->getParameterHolder()->getAll(), array('rel' => 
'prev', 'class' => 'widebtn btn-huge')) ?>
+            <?php endif; ?>
+
+          <?php if ($pager->resultSet->getTotalHits() > ($pager->maxPerPage * 
$pager->page)): ?>
+            <?php echo link_to(__('Next'). ' &raquo;', array('page' => 
$pager->page + 1) + $sf_request->getParameterHolder()->getAll(), array('rel' => 
'next', 'class' => 'widebtn btn-huge')) ?>
+            <?php endif; ?>
 
-</div>
+          <?php endif; ?>
+        </div>
+      </div>
+    </div><!-- /#grid -->
+  </div><!-- /.searchresults -->

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