Author: sevein Date: Thu Apr 19 14:35:23 2012 New Revision: 11476 Log: Make taxonomy browser extend default browser controller
Modified: branches/2.0/apps/qubit/modules/actor/actions/browseAction.class.php branches/2.0/apps/qubit/modules/actor/templates/browseSuccess.php branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php branches/2.0/apps/qubit/modules/search/actions/indexAction.class.php branches/2.0/apps/qubit/modules/taxonomy/actions/browseAction.class.php Modified: branches/2.0/apps/qubit/modules/actor/actions/browseAction.class.php ============================================================================== --- branches/2.0/apps/qubit/modules/actor/actions/browseAction.class.php Thu Apr 19 14:12:27 2012 (r11475) +++ branches/2.0/apps/qubit/modules/actor/actions/browseAction.class.php Thu Apr 19 14:35:23 2012 (r11476) @@ -27,7 +27,7 @@ * @author Wu Liu <[email protected]> * @version svn:$Id$ */ -class ActorBrowseAction extends sfAction +class ActorBrowseAction extends DefaultBrowseAction { public function execute($request) { Modified: branches/2.0/apps/qubit/modules/actor/templates/browseSuccess.php ============================================================================== --- branches/2.0/apps/qubit/modules/actor/templates/browseSuccess.php Thu Apr 19 14:12:27 2012 (r11475) +++ branches/2.0/apps/qubit/modules/actor/templates/browseSuccess.php Thu Apr 19 14:35:23 2012 (r11476) @@ -12,7 +12,7 @@ <?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; ?> + <?php endif; ?> </ul> </div> @@ -38,7 +38,7 @@ <?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; ?> + <?php endif; ?> </th><th> <?php if ('nameDown' == $sf_request->sort || 'nameUp' == $sf_request->sort || ('lastUpdated' != $sortSetting && 'updatedDown' != $sf_request->sort && 'updatedUp' != $sf_request->sort)): ?> <?php echo __('Type') ?> Modified: branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php ============================================================================== --- branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php Thu Apr 19 14:12:27 2012 (r11475) +++ branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php Thu Apr 19 14:35:23 2012 (r11476) @@ -95,7 +95,7 @@ { $this->error = $e->getMessage(); - return sfView::NONE; + return; } $this->pager = new QubitSearchPager($resultSet); @@ -109,5 +109,9 @@ $this->buildFacetTable($name, $facet); } } + else if (empty($this->error)) + { + // $this->error = $this->context->i18n->__('No %1% found.', array('%1%' => __($this->field))); + } } } Modified: branches/2.0/apps/qubit/modules/search/actions/indexAction.class.php ============================================================================== --- branches/2.0/apps/qubit/modules/search/actions/indexAction.class.php Thu Apr 19 14:12:27 2012 (r11475) +++ branches/2.0/apps/qubit/modules/search/actions/indexAction.class.php Thu Apr 19 14:35:23 2012 (r11476) @@ -82,8 +82,7 @@ } // mock up a QubitPager for partial template backward compatibility - $this->pager = new QubitSearchPager; - $this->pager->setResultSet($resultSet); + $this->pager = new QubitSearchPager($resultSet); $this->pager->setPage($request->page ? $request->page : 1); if ('print' != $request->getGetParameter('media')) Modified: branches/2.0/apps/qubit/modules/taxonomy/actions/browseAction.class.php ============================================================================== --- branches/2.0/apps/qubit/modules/taxonomy/actions/browseAction.class.php Thu Apr 19 14:12:27 2012 (r11475) +++ branches/2.0/apps/qubit/modules/taxonomy/actions/browseAction.class.php Thu Apr 19 14:35:23 2012 (r11476) @@ -17,23 +17,10 @@ * along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>. */ -class TaxonomyBrowseAction extends sfAction +class TaxonomyBrowseAction extends DefaultBrowseAction { - protected $query; - public static - $FACETS = array( - 'types', - 'contact.i18n.region'); - - protected function addFacet($name) - { - $facet = new Elastica_Facet_Terms($name); - $facet->setField($name); - $facet->setSize(50); - - $this->query->addFacet($facet); - } + $FACETS = array(); protected function buildFacetTable($name, $facet) { @@ -45,72 +32,40 @@ 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) - { - $this->pager->facets[strtr($name, '.', '_')]['terms'][$term['term']] = array( - 'count' => $term['count'], - 'term' => $typeNames[$term['term']]); } - - break; - - case 'contact.i18n.region': - foreach ($facet['terms'] as $term) - { - $this->pager->facets[strtr($name, '.', '_')]['terms'][$term['term']] = array( - 'count' => $term['count'], - 'term' => $term['term']); - } + default: break; } } - public function execute($request) + protected function earlyExecute() { - if (!isset($request->limit)) - { - $request->limit = sfConfig::get('app_hits_per_page'); - } - - // determine what kind of term we are browsing + // Determine what kind of term we are browsing switch ($request->id) { case QubitTaxonomy::SUBJECT_ID: $this->field = 'subjects'; + break; case QubitTaxonomy::PLACE_ID: $this->field = 'places'; + break; case '': // TODO: no ID specified, handle error condition (redirect?) + break; } $this->query = new Elastica_Query(new Elastica_Query_Term(array('taxonomyId' => $request->id))); - $this->setSort(array('_score' => 'desc', 'slug' => 'asc')); - // $query = $this->facetQuery($query); - - // set paging for request - $query->setLimit($this->request->limit); + $this->query->setSort(array('_score' => 'desc', 'slug' => 'asc')); + } - if (!empty($this->request->page)) - { - $query->setFrom(($this->request->page - 1) * $this->request->limit); - } + public function execute($request) + { + parent::execute($request); try { @@ -123,59 +78,20 @@ return; } - $this->pager = new QubitSearchPager; - $this->pager->setResultSet($resultSet); - $this->pager->setPage($request->page ? $request->page : 1); + $this->pager = new QubitSearchPager($resultSet); + $this->pager->setPage($request->page); + $this->pager->setMaxPerPage($request->limit); if ($this->pager->hasResults()) { 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; + $this->buildFacetTable($name, $facet); } } 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->error = $this->context->i18n->__('No %1% found.', array('%1%' => __($this->field))); } } } -- 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.
