Author: sevein
Date: Tue May 1 14:48:58 2012
New Revision: 11585
Log:
Refactor term browser to rely on ES, update templates regarding issue 2288.
Modified:
branches/2.0/apps/qubit/modules/term/actions/browseTermAction.class.php
branches/2.0/apps/qubit/modules/term/templates/browseTermSuccess.php
Modified:
branches/2.0/apps/qubit/modules/term/actions/browseTermAction.class.php
==============================================================================
--- branches/2.0/apps/qubit/modules/term/actions/browseTermAction.class.php
Tue May 1 14:37:09 2012 (r11584)
+++ branches/2.0/apps/qubit/modules/term/actions/browseTermAction.class.php
Tue May 1 14:48:58 2012 (r11585)
@@ -28,21 +28,82 @@
$this->resource = $this->getRoute()->resource;
- $criteria = new Criteria;
- $criteria->add(QubitObjectTermRelation::TERM_ID, $this->resource->id);
- $criteria->addJoin(QubitObjectTermRelation::OBJECT_ID,
QubitInformationObject::ID);
+ $queryBool = new Elastica_Query_Bool();
- $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
-
- $criteria = QubitCultureFallback::addFallbackCriteria($criteria,
'QubitInformationObject');
-
- $criteria->addAscendingOrderByColumn('title');
-
- $this->pager = new QubitPager('QubitInformationObject');
- $this->pager->setCriteria($criteria);
+ switch ($this->resource->taxonomyId)
+ {
+ case QubitTaxonomy::PLACE_ID:
+ $this->icon = 'places';
+ $queryBool->addMust(new Elastica_Query_Term(array('places.id' =>
$this->resource->id)));
+
+ break;
+
+ case QubitTaxonomy::SUBJECT_ID:
+ $this->icon = 'subjects';
+ $queryBool->addMust(new Elastica_Query_Term(array('subjects.id' =>
$this->resource->id)));
+
+ break;
+
+ default:
+ // pass
+ $queryFilter = new Elastica_Query_MatchAll();
+
+ break;
+ }
+
+ $query = new Elastica_Query();
+ $query->setSort(array('_score' => 'desc', 'slug' => 'asc'));
+ $query->setLimit($request->limit);
+ $queryBool->addMust(new Elastica_Query_Term(array('publicationStatusId' =>
QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID)));
+ $query->setQuery($queryBool);
+
+ try
+ {
+ $resultSet =
QubitSearch::getInstance()->index->getType('QubitInformationObject')->search($query);
+ }
+ catch (Exception $e)
+ {
+ $this->error = $e->getMessage();
+
+ return;
+ }
+
+ // mock up a QubitPager for partial template backward compatibility
+ $this->pager = new QubitSearchPager($resultSet);
+ $this->pager->setPage($request->page ? $request->page : 1);
$this->pager->setMaxPerPage($request->limit);
- $this->pager->setPage($request->page);
- $this->informationObjects = $this->pager->getResults();
+ if ($this->pager->hasResults())
+ {
+ $ancestorsIds = array();
+ foreach ($this->pager->getResults() as $hit)
+ {
+ $doc = $hit->getData();
+ foreach ($doc['ancestors'] as $item)
+ {
+ if (in_array($item, $ancestorsIds))
+ {
+ continue;
+ }
+
+ $ancestorsIds[] = $item;
+ }
+ }
+
+ $sql = 'SELECT
+ io.id,
+ o.slug,
+ io.title
+ FROM '.QubitInformationObjectI18n::TABLE_NAME.' AS io
+ LEFT JOIN '.QubitSlug::TABLE_NAME.' AS o ON (o.object_id = io.id AND
io.culture = ?)
+ WHERE o.object_id IN ('.implode(',', $ancestorsIds).')';
+ $this->pager->ancestors = array();
+ foreach (QubitPdo::fetchAll($sql,
array($this->context->user->getCulture())) as $ancestor)
+ {
+ $this->pager->ancestors[$ancestor->id] = array(
+ 'slug' => $ancestor->slug,
+ 'title' => $ancestor->title);
+ }
+ }
}
}
Modified: branches/2.0/apps/qubit/modules/term/templates/browseTermSuccess.php
==============================================================================
--- branches/2.0/apps/qubit/modules/term/templates/browseTermSuccess.php
Tue May 1 14:37:09 2012 (r11584)
+++ branches/2.0/apps/qubit/modules/term/templates/browseTermSuccess.php
Tue May 1 14:48:58 2012 (r11585)
@@ -1,66 +1,58 @@
<?php use_helper('Text') ?>
-<h1><?php echo render_title($resource->taxonomy) ?> - <?php echo
render_title($resource) ?></h1>
+<div id="search-results">
-<div class="section">
- <?php foreach ($informationObjects as $item): ?>
- <div class="clearfix <?php echo 0 == @++$row % 2 ? 'even' : 'odd' ?>">
-
- <?php if (isset($item->digitalObjects[0]) && null !==
$item->digitalObjects[0]->thumbnail): ?>
- <?php echo
link_to(image_tag(public_path($item->digitalObjects[0]->thumbnail->getFullPath()),
array('alt' => render_title($item))), array($item, 'module' =>
'informationobject')) ?>
- <?php endif; ?>
+ <div class="row">
- <h2><?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; ?></h2>
+ <div class="span12">
+ <h1>
+ <?php if (isset($icon)): ?>
+ <?php echo
image_tag('/plugins/qtDominionPlugin/images/icons-large/icon-'.$icon.'.png',
array('width' => '42', 'height' => '42')) ?>
+ <?php endif; ?>
+ <?php echo render_title($resource->taxonomy) ?> - <?php echo
render_title($resource) ?>
+ <strong class="hidden-phone">
+ <?php echo __('%1% search results', array('%1%' =>
$pager->getNbResults())) ?>
+ <?php if (sfConfig::get('app_multi_repository')): ?>
+ <?php echo __('in %1% institutions', array('%1%' =>
count($pager->facets['repository_id']['terms']))) ?>
+ <?php endif; ?>
+ </strong>
+ </h1>
+ </div>
- <div>
- <?php echo truncate_text($item->scopeAndContent, 250) ?>
- </div>
+ <div id="phone-filter" class="span12 visible-phone">
+ <h2 class="widebtn btn-huge" data-toggle="collapse"
data-target="#facets, #top-facet"><?php echo __('Filter %1% Results', array(
+ '%1%' => $pager->getNbResults())) ?></h2>
+ </div>
- <?php $isad = new sfIsadPlugin($item); echo render_show(__('Reference
code'), render_value($isad->referenceCode)) ?>
+ </div>
- <div class="field">
- <h3><?php echo __('Date(s)') ?></h3>
- <div>
- <ul>
- <?php foreach ($item->getDates() as $date): ?>
- <li>
-
- <?php echo
Qubit::renderDateStartEnd($date->getDate(array('cultureFallback' => true)),
$date->startDate, $date->endDate) ?> (<?php echo
$date->getType(array('cultureFallback' => true)) ?>)
-
- <?php if (isset($date->actor)): ?>
- <?php echo link_to(render_title($date->actor),
array($date->actor, 'module' => 'actor')) ?>
- <?php endif; ?>
-
- </li>
- <?php endforeach; ?>
- </ul>
- </div>
- </div>
+ <div class="row">
- <?php echo render_show(__('Level of description'),
render_value($item->levelOfDescription)) ?>
+ <div class="span3" id="facets">
- <?php if (sfConfig::get('app_multi_repository') &&
isset($item->repository)): ?>
- <?php echo render_show(__('Repository'),
link_to(render_title($item->repository), array($item->repository, 'module' =>
'repository'))) ?>
- <?php endif; ?>
-
- <?php if ($item->getCollectionRoot() !== $item): ?>
- <?php echo render_show(__('Part of'),
link_to(render_title($item->getCollectionRoot()),
array($item->getCollectionRoot(), 'module' => 'informationobject'))) ?>
- <?php endif; ?>
+ <?php echo link_to(__('Show all %1%', array('%1%' =>
$resource->taxonomy->__toString())),
+ array('module' => 'taxonomy', 'action' => 'browse', 'id' =>
$resource->taxonomyId),
+ array('class' => 'widebtn')) // HACK Use id deliberately because
"Subjects" and "Places" menus still use id ?>
</div>
- <?php endforeach; ?>
-</div>
-<?php echo get_partial('default/pager', array('pager' => $pager)) ?>
+ <div class="span9" id="content">
+
+ <div class="listings">
-<div class="actions section">
+ <?php foreach ($pager->getResults() as $hit): ?>
- <h2 class="element-invisible"><?php echo __('Actions') ?></h2>
+ <?php $doc = build_i18n_doc($hit, array('creators')) ?>
+ <?php echo include_partial('search/searchResult', array('doc' =>
$doc, 'pager' => $pager)) ?>
+
+ <?php endforeach; ?>
+
+ <?php echo get_partial('default/pager', array('pager' => $pager)) ?>
+
+ </div>
+
+ </div>
- <div class="content">
- <ul class="clearfix links">
- <li><?php echo link_to(__('Browse all %1%', array('%1%' =>
render_title($resource->taxonomy))), array('module' => 'taxonomy', 'action' =>
'browse', 'id' => $resource->taxonomy->id)) // HACK Use id deliberately because
"Subjects" and "Places" menus still use id ?></li>
- </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.