Beispiel #1
0
 public function run()
 {
     $type = false;
     if ($this->type == self::TYPE_ARTICLE) {
         $type = 'article';
     } elseif ($this->type == self::TYPE_PAGE) {
         $type = 'page';
     } else {
         throw new Exception("Error CommentsWidget: unknown type [" . $this->type . "]");
     }
     $models = CommentRecord::find()->where(['parent_id' => (int) $this->parent_id, 'type' => $type, 'active' => CommentRecord::STATUS_IS_ACTIVE])->orderBy(['sort' => SORT_ASC])->all();
     return $this->render('comments', ['parent_id' => $this->parent_id, 'type' => $this->type, 'models' => $models]);
 }
Beispiel #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     if (!isset($params['parent_id'])) {
         throw new \Exception('Property parent_id must be setted');
     }
     // only for comments this way
     $query = CommentRecord::find()->where($this->getParentParams());
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]], 'pagination' => ['pageSize' => 3]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'sort' => $this->sort, 'user_id' => $this->user_id, 'active' => $this->active]);
     $query->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }