Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- ?>
- <?php
- class searchComponents extends sfComponents
- {
- /**
- * Executes index action
- *
- * @param sfRequest $request A request object
- */
- public function executeIndex(sfWebRequest $request)
- {
- $query = $this->applyQueryOrder( Doctrine::getTable('Aplic')->getSolrSearchQuery( $request->getParameter( 'q' ) ) );
- $this->results = new wsPager( 'Aplic', sfConfig::get( 'app_apps_per_page' ) );
- $this->results->setQuery( $query );
- $this->results->setPage( $request->getParameter( 'page', 1 ) );
- $this->results->init();
- $this->from = ($this->results->getPage() - 1) * sfConfig::get( 'app_apps_per_page' ) + 1;
- $this->to = $this->results->getPage() * sfConfig::get( 'app_apps_per_page' );
- $this->results_count = $this->results->getNbResults();
- if( $this->to > $this->results->getNbResults() )
- {
- $this->to = $this->results->getNbResults();
- }
- }
- private function applyQueryOrder( Doctrine_Query $query )
- {
- $orderType = $this->getRequestParameter( 'type' );
- switch( $orderType )
- {
- case 'rating':
- if( $this->getRequestParameter( 'order' ) == 'asc' )
- {
- $query->orderBy( $query->getRootAlias().'.average ASC' );
- }
- else
- {
- $query->orderBy( $query->getRootAlias().'.average DESC' );
- }
- break;
- case 'date':
- if( $this->getRequestParameter( 'order' ) == 'asc' )
- {
- $query->orderBy( $query->getRootAlias().'.released ASC' );
- }
- else
- {
- $query->orderBy( $query->getRootAlias().'.released DESC' );
- }
- break;
- case 'price':
- if( $this->getRequestParameter( 'order' ) == 'asc' )
- {
- $query->orderBy( $query->getRootAlias().'.price_eu ASC' );
- }
- else
- {
- $query->orderBy( $query->getRootAlias().'.price_eu DESC' );
- }
- break;
- case 'a-z':
- if( $this->getRequestParameter( 'order' ) == 'asc' )
- {
- $query->orderBy( $query->getRootAlias().'.name ASC' );
- }
- else
- {
- $query->orderBy( $query->getRootAlias().'.name DESC' );
- }
- break;
- case 'score':
- if( $this->getRequestParameter( 'order' ) == 'asc' )
- {
- $query->orderBy( $query->getRootAlias().'.score ASC' );
- }
- else
- {
- $query->orderBy( $query->getRootAlias().'.score DESC' );
- }
- break;
- }
- return $query;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement