Advertisement
fernandezekiel

Untitled

Jul 20th, 2013
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.16 KB | None | 0 0
  1. public function search() {
  2.         $criteria = new ExtendedDbCriteria;
  3.         $criteria->scopes = array('withTotals');
  4.         $criteria->with = array(
  5.             'coordinator' => array(
  6.                 'alias' => 'cid',
  7.                 'with' => array('profile' => array(
  8.                         'alias' => 'cidp'
  9.                     )
  10.                 )
  11.             ),
  12.             'opportunity' => array(
  13.                 'alias' => 'o',
  14.                 'with' => array('customer' => array('alias' => 'ocu')),
  15.             ),
  16.         );
  17.        
  18.         if (isset($this->alias))
  19.             $criteria->alias = $this->alias;
  20.  
  21.         $criteria->compareHaving('totalTaxedAmount', $this->totalTaxedAmount, true);
  22.         $criteria->compareHaving('totalSalesCredited', $this->totalSalesCredited, true);
  23.  
  24.         $criteria->compare("CONCAT(cidp.first_name, ' ', cidp.last_name)", $this->coordinator_name, true);
  25.         $criteria->compare("$criteria->alias.id", $this->id);
  26.         $criteria->compare("o.name", $this->opportunity_name, true);
  27.  
  28.         $criteria->compare("$criteria->alias.opportunity_id", $this->opportunity_id);
  29.         $criteria->compare("$criteria->alias.quotation_number", $this->quotation_number, true);
  30.         //$criteria->compare("$criteria->alias.contact_id", $this->contact_id);
  31.         if($this->date != null)
  32.             $criteria->compare("$criteria->alias.date", date('Y-m-d',  strtotime($this->date)), true);
  33.         $criteria->compare("$criteria->alias.description", $this->description, true);
  34.         $criteria->compare("$criteria->alias.discount", $this->discount, true);
  35.         $criteria->compare("$criteria->alias.discount_type", $this->discount_type);
  36.         $criteria->compare("$criteria->alias.status", $this->status);
  37.         $criteria->compare("ocu.name", $this->customer_name, true);
  38.         $criteria->compare("$criteria->alias.project_type",$this->project_type);
  39.         $sort = new CSort();
  40.         $sort->defaultOrder = "$this->alias.date DESC";
  41.         $sort->attributes = array('*',
  42.             'totalAmount' => array(
  43.                 'asc' => 'total',
  44.                 'desc' => 'totalAmount DESC',
  45.             ),
  46.             'totalTaxedAmount' => array(
  47.                 'asc' => 'totalTaxedAmount',
  48.                 'desc' => 'totalTaxedAmount DESC',
  49.             ),
  50.             'opportunity_name'=>array(
  51.                 'asc'=>'o.name',
  52.                 'desc'=>'o.name DESC'
  53.             ),
  54.             'coordinator_name' => array(
  55.                 'asc' => 'cidp.first_name, cidp.last_name',
  56.                 'desc' => 'cidp.first_name DESC, cidp.last_name DESC',
  57.             ),
  58.             'customer_name' => array(
  59.                 'asc' => 'ocu.name',
  60.                 'desc' => 'ocu.name DESC',
  61.             ),
  62.         );
  63.         //this does not work
  64.         $count = self::model()->count($criteria);
  65.         return new RestrictedDataProvider($this, array(
  66.             'criteria' => $criteria,
  67.             'sort' => $sort,
  68.             'totalItemCount'=>$count,
  69.             //'recomputeTotalItemCount' => true,
  70.             'pagination' => array(
  71.                 'pageSize' => 10,
  72.             ),
  73.         ));
  74.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement