Author: sevein Date: Tue Apr 17 11:47:25 2012 New Revision: 11452 Log: Move repository browser to main apps/, cleanups and update template to fit with our CSS lib
Deleted: branches/2.0/plugins/qtDominionPlugin/modules/repository/ Modified: branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php branches/2.0/apps/qubit/modules/repository/templates/browseSuccess.php Modified: branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php ============================================================================== --- branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php Tue Apr 17 11:46:40 2012 (r11451) +++ branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php Tue Apr 17 11:47:25 2012 (r11452) @@ -18,12 +18,12 @@ */ /** - * @package qubit + * @package qtDominionPlugin * @subpackage repository - * @author Peter Van Garderen <[email protected]> - * @author Wu Liu <[email protected]> + * @author MJ Suhonos <[email protected]> * @version svn:$Id$ */ + class RepositoryBrowseAction extends sfAction { public function execute($request) @@ -33,6 +33,87 @@ $request->limit = sfConfig::get('app_hits_per_page'); } + // retrieve all institutions + $query = new Elastica_Query(new Elastica_Query_MatchAll()); + $query = $this->facetQuery($query); + + // set paging for request + $query->setLimit($this->request->limit); + + if (!empty($this->request->page)) + { + $query->setFrom(($this->request->page - 1) * $this->request->limit); + } + + try + { + $resultSet = QubitSearch::getInstance()->index->getType('QubitRepository')->search($query); + } + catch (Exception $e) + { + $this->error = $e->getMessage(); + + return; + } + + // mock up a QubitPager for partial template backward compatibility + $this->pager = new stdClass(); + $this->pager->resultSet = $resultSet; + + if (0 < $resultSet->getTotalHits()) + { + $this->pager->resultSet = $resultSet; + $this->pager->page = $request->page ? $request->page : 1; + + 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 subjects found.'); + } +/* if ($this->getUser()->isAuthenticated()) { $this->sortSetting = sfConfig::get('app_sort_browser_user'); @@ -85,5 +166,20 @@ $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); + } + + return $query; + } + } Modified: branches/2.0/apps/qubit/modules/repository/templates/browseSuccess.php ============================================================================== --- branches/2.0/apps/qubit/modules/repository/templates/browseSuccess.php Tue Apr 17 11:46:40 2012 (r11451) +++ branches/2.0/apps/qubit/modules/repository/templates/browseSuccess.php Tue Apr 17 11:47:25 2012 (r11452) @@ -1,102 +1,83 @@ -<?php use_helper('Date') ?> +<div id="search-results"> -<div class="section tabs"> + <div class="row"> - <h2 class="element-invisible"><?php echo __('Repository browse options') ?></h2> + <div class="span12 hidden-phone"> + <h1> + <?php echo image_tag('/plugins/qtDominionPlugin/images/icons-large/icon-institutions.png', array('width' => '42', 'height' => '42')) ?> + <?php echo __('%1% Institutions', array('%1%' => $pager->resultSet->getTotalHits())) ?> + </h1> + </div> + + <div id="filter" class="span12 visible-phone"> + <h2 class="widebtn btn-huge" data-toggle="collapse" data-target="#facets"> + <?php echo __('Filter %1% Institutions', array('%1%' => $pager->resultSet->getTotalHits())) ?> + </h2> + </div> - <div class="content"> - <ul class="clearfix links"> - <?php if ('lastUpdated' == $sortSetting): ?> - <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> - <?php else: ?> - <li<?php if ('updatedDown' == $sf_request->sort || 'updatedUp' == $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 ('updatedDown' != $sf_request->sort && 'updatedUp' != $sf_request->sort): ?> class="active"<?php endif; ?>><?php echo link_to(__('Alphabetic'), array('sort' => 'nameUp') + $sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) ?></li> - <?php endif; ?> - </ul> </div> -</div> + <div class="row"> + + <div class="span3" id="facets"> + + <div class="section"> + + <h2 class="visible-phone widebtn btn-huge" data-toggle="collapse" data-target="#archivetype"><?php echo __('Archive type') ?></h2> + + <h2 class="hidden-phone"><?php echo __('Archive type'); ?></h2> + + <div class="scrollable"> + <ul> + <li class="active"><?php echo link_to(__('All'), array('types' => null) + $sf_request->getParameterHolder()->getAll()) ?></li> + <?php foreach($pager->facets['types']['terms'] as $id => $term): ?> + <li><?php echo link_to(__($term['term']).'<span>'.$term['count'].'</span>', array('types' => $id) + $sf_request->getParameterHolder()->getAll()) ?></li> + <?php endforeach; ?> + </ul> + </div> + + </div> + + <div class="section"> + + <h2 class="visible-phone widebtn btn-huge" data-toggle="collapse" data-target="#province"><?php echo __('Province'); ?></h2> + + <h2 class="hidden-phone"><?php echo __('Province'); ?></h2> + + <div class="scrollable"> + <ul> + <li class="active"><?php echo link_to(__('All'), array('contact_i18n_region' => null) + $sf_request->getParameterHolder()->getAll()); ?></li> + <?php foreach($pager->facets['contact_i18n_region']['terms'] as $id => $term): ?> + <li><?php echo link_to(__($term['term']).'<span>'.$term['count'].'</span>', array('contact_i18n_region' => $id) + $sf_request->getParameterHolder()->getAll()) ?></li> + <?php endforeach; ?> + </ul> + </div> -<h1><?php echo __('Browse %1%', array('%1%' => sfConfig::get('app_ui_label_repository'))) ?></h1> + </div> + + </div> + + <div class="span9"> + + <?php foreach ($pager->resultSet->getResults() as $hit): ?> + <?php $doc = build_i18n_doc($hit) ?> + <div class="institution maxi"> + <h2 class="filltext"><?php echo link_to($doc[$sf_user->getCulture()]['authorizedFormOfName'] ?: $doc[$doc['sourceCulture']]['authorizedFormOfName'], array('module' => 'repository', 'slug' => $doc['slug'])) ?></h2> + </div> + <?php endforeach; ?> + + </div> + + <div class="row"> + + <div class="span9"> + + <a href="#" class="widebtn btn-huge">next »</a> + + </div> + + </div> + + </div> -<table class="sticky-enabled"> - <thead> - <tr> - <th> - <?php echo __('Name') ?> - <?php if ('lastUpdated' == $sortSetting): ?> - <?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; ?> - <?php else: ?> - <?php if (('nameDown' != $sf_request->sort && 'updatedDown' != $sf_request->sort && 'updatedUp' != $sf_request->sort) || ('nameUp' == $sf_request->sort)): ?> - <?php echo link_to(image_tag('down.gif'), array('sort' => 'nameDown') + $sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) ?> - <?php endif; ?> - <?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 endif; ?> - <?php endif; ?> - </th> - <?php if ('nameDown' == $sf_request->sort || 'nameUp' == $sf_request->sort || ('lastUpdated' != $sortSetting && 'updatedDown' != $sf_request->sort && 'updatedUp' != $sf_request->sort) ): ?> - <th> - <?php echo __('Type') ?> - </th><th> - <?php echo __('Country') ?> - </th> - <?php else: ?> - <th> - <?php echo __('Updated') ?> - <?php if ('lastUpdated' == $sortSetting): ?> - <?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; ?> - <?php else: ?> - <?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 elseif ('updatedDown' == $sf_request->sort): ?> - <?php echo link_to(image_tag('down.gif'), array('sort' => 'updatedUp') + $sf_request->getParameterHolder()->getAll(), array('title' => __('Sort'))) ?> - <?php endif; ?> - <?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' => 'repository')) ?> - </td> - <?php if ('nameDown' == $sf_request->sort || 'nameUp' == $sf_request->sort || ('lastUpdated' != $sortSetting && 'updatedDown' != $sf_request->sort && 'updatedUp' != $sf_request->sort) ): ?> - <td> - <ul> - <?php foreach ($item->getTermRelations(QubitTaxonomy::REPOSITORY_TYPE_ID) as $relation): ?> - <li><?php echo $relation->term ?></li> - <?php endforeach; ?> - </ul> - </td><td> - <?php echo $item->getCountry() ?> - </td> - <?php else: ?> - <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' => 'repository', 'action' => 'list')) ?>"> - <input name="subquery" value="<?php echo esc_entities($sf_request->subquery) ?>"/> - <input class="form-submit" type="submit" value="<?php echo __('Search %1%', array('%1%' => sfConfig::get('app_ui_label_repository'))) ?>"/> - </form> </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.
