Example #1
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();
     // $rubric_table = Category::model()->tableName();
     // $rubric_orgs_table = OrgsCategory::model()->tableName();
     // $rubric_title_sql = "(select LOWER(rt.title) from $rubric_table as rt, $rubric_orgs_table as rot where rot.org = t.id)";
     $criteria->with = array('categorization', 'categories' => array());
     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('t.url', $this->url, true);
     $criteria->compare('t.created_date', $this->created_date, true);
     $criteria->compare('t.views_count', $this->views_count);
     if ($this->updated_date) {
         $criteria->addCondition("t.updated_date >='" . date('Y-m-d 00:00:00', strtotime($this->updated_date)) . "'");
         $criteria->addCondition("t.updated_date <='" . date('Y-m-d 23:59:59', strtotime($this->updated_date)) . "'");
     }
     $criteria->compare('t.author', $this->author);
     if (!empty($this->rubric_title)) {
         $criteria->with['categories'] = array('together' => true);
         $criteria->compare('LOWER(categories.title)', MHelper::String()->toLower($this->rubric_title), true);
     }
     if ($pagination) {
         return new CActiveDataProvider($this, array('criteria' => $criteria, 'sort' => Article::getCSort(), 'pagination' => array('pageSize' => 50)));
     } else {
         return new CActiveDataProvider($this, array('criteria' => $criteria, 'sort' => Article::getCSort('t.id'), 'pagination' => false));
     }
 }
    public function actionView()
    {
        $model = $this->_loadModel(Yii::app()->request->getQuery('url'));
        $this->model = $model;

        $this->pageTitle = $model->title.' - '.Yii::app()->name;

        $this->breadcrumbs['Статьи'] = Yii::app()->createAbsoluteUrl('/catalog/article/index');
        $this->breadcrumbs[] = $model->title;

        $popular = Article::model()->fullactive()->findAll(array('limit'=>3,'order'=>'views_count DESC')); 

        $query = Article::model()->fullactive()->cache(3600);
        $query->applyCategoriesWithSub($model);

        $dataProvider = new CActiveDataProvider($query, array(
            // Set id to false to not display model name in
            // sort and page params
            'id'=>false,
            'pagination'=>array(
                'pageSize'=>25,
            )
        ));

        $dataProvider->sort = Article::getCSort('t.created_date DESC, t.title');

        $this->render('view',array(
            'model'=>$model,
            'dataProvider'=>$dataProvider,
            'popular'=>$popular
        ));
    }