/** * @param null $id * @param null $media_slug * * @return string * @throws \yii\web\NotFoundHttpException */ public function actionView($id = null, $media_slug = null) { $render = 'view'; $comment = new Comment(); if ($id) { $model = $this->findModel($id); } else { if ($media_slug) { $model = $this->findModelBySlug($media_slug); } else { throw new NotFoundHttpException('The requested page does not exist.'); } } if ($comment->load(Yii::$app->request->post()) && $comment->save()) { if (!$comment->comment_parent) { $model->media_comment_count++; } if ($model->save()) { $this->refresh(); } } if ($model->media_password && $model->media_password !== Yii::$app->request->post('password')) { return $this->render('protected', ['media' => $model]); } if (is_file($this->view->theme->basePath . '/media/view-' . substr($model->media_mime_type, 0, strpos($model->media_mime_type, '/', 1)) . '.php')) { $render = 'view-' . substr($model->media_mime_type, 0, strpos($model->media_mime_type, '/', 1)); } return $this->render($render, ['media' => $model, 'metadata' => $model->getMeta('metadata'), 'comment' => $comment]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @param int $media_id * * @return ActiveDataProvider */ public function search($params, $media_id) { $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()) { // 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, '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; }
/** * @return \yii\db\ActiveQuery */ public function getMediaComments() { return $this->hasMany(MediaComment::className(), ['comment_media_id' => 'id']); }
/** * Finds the MediaComment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param integer $id * * @return MediaComment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MediaComment::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }