Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.06 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * To change this template, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. ?>
  8. <?php
  9.  
  10. class searchComponents extends sfComponents
  11. {
  12.   /**
  13.   * Executes index action
  14.   *
  15.   * @param sfRequest $request A request object
  16.   */
  17.   public function executeIndex(sfWebRequest $request)
  18.   {
  19.     $query = $this->applyQueryOrder( Doctrine::getTable('Aplic')->getSolrSearchQuery( $request->getParameter( 'q' ) ) );
  20.     $this->results = new wsPager( 'Aplic', sfConfig::get( 'app_apps_per_page' ) );
  21.     $this->results->setQuery( $query );
  22.     $this->results->setPage( $request->getParameter( 'page', 1 ) );
  23.     $this->results->init();
  24.     $this->from = ($this->results->getPage() - 1) * sfConfig::get( 'app_apps_per_page' ) + 1;
  25.     $this->to = $this->results->getPage() * sfConfig::get( 'app_apps_per_page' );
  26.     $this->results_count = $this->results->getNbResults();
  27.     if( $this->to > $this->results->getNbResults() )
  28.     {
  29.         $this->to = $this->results->getNbResults();
  30.     }
  31.   }
  32.  
  33.   private function applyQueryOrder( Doctrine_Query $query )
  34.   {
  35.         $orderType = $this->getRequestParameter( 'type' );
  36.         switch( $orderType )
  37.         {
  38.             case 'rating':
  39.                 if( $this->getRequestParameter( 'order' ) == 'asc'  )
  40.                 {
  41.                     $query->orderBy( $query->getRootAlias().'.average ASC' );
  42.                 }
  43.                 else
  44.                 {
  45.                     $query->orderBy( $query->getRootAlias().'.average DESC' );
  46.                 }
  47.                 break;
  48.             case 'date':
  49.                 if( $this->getRequestParameter( 'order' ) == 'asc'  )
  50.                 {
  51.                     $query->orderBy( $query->getRootAlias().'.released ASC' );
  52.                 }
  53.                 else
  54.                 {
  55.                     $query->orderBy( $query->getRootAlias().'.released DESC' );
  56.                 }
  57.                 break;
  58.             case 'price':
  59.                 if( $this->getRequestParameter( 'order' ) == 'asc'  )
  60.                 {
  61.                     $query->orderBy( $query->getRootAlias().'.price_eu ASC' );
  62.                 }
  63.                 else
  64.                 {
  65.                     $query->orderBy( $query->getRootAlias().'.price_eu DESC' );
  66.                 }
  67.                 break;
  68.             case 'a-z':
  69.                 if( $this->getRequestParameter( 'order' ) == 'asc'  )
  70.                 {
  71.                     $query->orderBy( $query->getRootAlias().'.name ASC' );
  72.                 }
  73.                 else
  74.                 {
  75.                     $query->orderBy( $query->getRootAlias().'.name DESC' );
  76.                 }
  77.                 break;
  78.             case 'score':
  79.                 if( $this->getRequestParameter( 'order' ) == 'asc'  )
  80.                 {
  81.                     $query->orderBy( $query->getRootAlias().'.score ASC' );
  82.                 }
  83.                 else
  84.                 {
  85.                     $query->orderBy( $query->getRootAlias().'.score DESC' );
  86.                 }
  87.                 break;
  88.         }
  89.         return $query;
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement