/** * @param integer|null $id * @param string|null $media_slug * * @return mixed * @throws \yii\web\NotFoundHttpException */ public function actionView($id = null, $media_slug = null) { $render = 'view'; $comment = new Comment(); if ($id) { $model = $this->findModel($id); } elseif ($media_slug) { $model = $this->findModelBySlug($media_slug); } else { throw new NotFoundHttpException(Yii::t('writesdown', '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]); }
/** * Reply an existing MediaComment model. * If reply is successful, the browser will be redirected to 'update' page. * * @param int $id Find MediaComment model based on id as its parent * * @return string */ public function actionReply($id) { $commentParent = $this->findModel($id); $model = new MediaComment(['scenario' => 'reply']); if ($model->load(Yii::$app->request->post())) { $model->comment_media_id = $commentParent->comment_media_id; $model->comment_parent = $commentParent->id; if ($model->save()) { $this->redirect(['/media-comment/update', 'id' => $model->id]); } } return $this->render('reply', ['commentParent' => $commentParent, 'model' => $model]); }