Ejemplo n.º 1
0
 /**
  * Get comment children based on comment ID.
  *
  * @param int $id
  *
  * @return array|null
  */
 protected function getChildren($id)
 {
     $comments = [];
     $models = Comment::find()->select(['id', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_date', 'comment_content'])->andWhere(['comment_parent' => $id])->andWhere(['comment_media_id' => $this->model->id])->andWhere(['comment_approved' => 'approved'])->orderBy(['id' => $this->commentOrder])->all();
     if (empty($models)) {
         $comments = null;
     } else {
         /* @var $model \common\models\PostComment */
         foreach ($models as $model) {
             $comments[$model->id] = $model;
             $comments[$model->id]['child'] = $this->getChildren($model->id);
         }
     }
     return $comments;
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array    $params
  * @param int|null $media_id
  *
  * @return ActiveDataProvider
  */
 public function search($params, $media_id = null)
 {
     $query = MediaCommentModel::find();
     $query->innerJoinWith(['commentMedia' => function ($query) {
         /* @var $query \yii\db\ActiveQuery */
         return $query->from(['media' => Media::tableName()]);
     }]);
     if ($media_id) {
         $query->andWhere(['media.id' => $media_id]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'comment_media_id' => $this->comment_media_id, 'comment_parent' => $this->comment_parent, 'comment_user_id' => $this->comment_user_id]);
     $query->andFilterWhere(['like', 'comment_author', $this->comment_author])->andFilterWhere(['like', 'comment_author_email', $this->comment_author_email])->andFilterWhere(['like', 'comment_author_url', $this->comment_author_url])->andFilterWhere(['like', 'comment_author_ip', $this->comment_author_ip])->andFilterWhere(['like', 'comment_content', $this->comment_content])->andFilterWhere(['like', 'comment_approved', $this->comment_approved])->andFilterWhere(['like', 'comment_agent', $this->comment_agent])->andFilterWhere(['like', 'comment_date', $this->comment_date])->andFilterWhere(['like', 'media.media_title', $this->media_title]);
     return $dataProvider;
 }