public function actionView()
 {
     $model = $this->_loadModel(Yii::app()->request->getQuery('url'));
     $cr = new CDbCriteria();
     if ($model) {
         $this->pageTitle = $model->title . ' - Быстрые отзывы покупателей';
         $modelFirst = $model;
         $name = $model->title;
         $cr->addCondition('t.categorie=' . $model->id);
     }
     // $query = Objects::model()->cache(3600);
     $cr->select = 't.*';
     $query = new Objects(null);
     $query->attachBehaviors($query->behaviors());
     $query->applyAttributes($this->activeAttributes)->active();
     //  ->with('images');
     $query->getDbCriteria()->mergeWith($cr);
     $provider = new CActiveDataProvider($query, array('id' => false, 'pagination' => array('pageSize' => 25)));
     $provider->sort = Objects::getCSort('t.created_date DESC, t.title');
     $itemView = '_objects_view';
     $count_items = $provider->totalItemCount;
     $criteria = new CDbCriteria();
     $criteria->scopes = 'active';
     $dataProvider = new CActiveDataProvider('Objects', array('criteria' => $criteria, 'sort' => array('defaultOrder' => 't.created_date DESC'), 'pagination' => array('pageSize' => 30)));
     $sql = 'select count(*) cnt, categorie
             from objects
             WHERE objects.status=' . Objects::STATUS_ACTIVE . '
             group by categorie';
     $connection = Yii::app()->db;
     $command = $connection->createCommand($sql);
     $rows = $command->queryAll();
     $search = false;
     $this->render('view', array('provider' => $provider, 'model' => $model, 'itemView' => $itemView, 'per_page' => 25, 'count_items' => $count_items, 'rows' => $rows, 'search' => $search));
 }
Exemple #2
0
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search($params = array(), $additionalCriteria = null, $pagination = true)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
		

		if($additionalCriteria !== null)
			$criteria->mergeWith($additionalCriteria);

		if($this->id)
			$this->id = (int)$this->id;
		$criteria->compare('t.id',$this->id);
		if($this->title){
			$criteria->compare('LOWER(t.title)',MHelper::String()->toLower($this->title),true);
		}
		$criteria->compare('LOWER(t.description)',MHelper::String()->toLower($this->description),true);
		$criteria->compare('LOWER(t.address)',MHelper::String()->toLower($this->address),true);
		$criteria->compare('LOWER(t.street)',MHelper::String()->toLower($this->street),true);
		$criteria->compare('LOWER(t.dom)',MHelper::String()->toLower($this->dom),true);
		$criteria->compare('t.city_id',$this->city_id);
		$criteria->compare('t.link',$this->link,true);
		$criteria->compare('t.url',$this->url,true);
		$criteria->compare('t.created_date',$this->created_date,true); 
		$criteria->compare('t.status',$this->status);
		$criteria->compare('t.categorie', $this->categorie);

		$criteria->compare('t.author', $this->author);

        if($pagination){
        	return new CActiveDataProvider($this, array(
				'criteria'   => $criteria,
				'sort'       => Objects::getCSort(),
				'pagination' => array(
					'pageSize'=>50,
				)
			));
        } else {
        	return new CActiveDataProvider($this, array(
				'criteria'   => $criteria,
				'sort'       => Objects::getCSort('t.id'),
				'pagination' => false
			));
        }
		
	}