Example #1
0
 /**
  * @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]);
 }
Example #2
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;
 }
Example #3
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;
 }
Example #4
0
 /**
  * @param AcceptanceTester $I
  */
 public function testReply(AcceptanceTester $I)
 {
     $I->wantTo('ensure that reply media-comment works');
     $replyPage = ReplyPage::openBy($I);
     $I->amGoingTo('reply media-comment with no content');
     $replyPage->submit('');
     $I->expectTo('see validation error');
     $I->see('Content cannot be blank.', '.help-block');
     $I->amGoingTo('reply media-comment with no empty content');
     $replyPage->submit('Test reply media-comment');
     $I->expect('the reply saved');
     $I->see('Update Media Comment 2', 'h1');
     MediaComment::deleteAll(['content' => 'Test reply media-comment']);
 }
 /**
  * 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;
     }
     throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
 }
Example #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMediaComments()
 {
     return $this->hasMany(MediaComment::className(), ['comment_media_id' => 'id']);
 }
Example #7
0
 /**
  * @param FunctionalTester $I
  */
 public function testUpdate(FunctionalTester $I)
 {
     $I->wantTo('ensure that update media-comment works');
     $updatePage = UpdatePage::openBy($I);
     $I->see('Update Media Comment: 1', 'h1');
     $I->amGoingTo('submit media-comment with no correct email & url');
     $updatePage->submit(['comment_author' => 'Tester', 'comment_author_email' => 'tester.author@test', 'comment_author_url' => 'http://.com']);
     $I->expectTo('see that email & url not correct');
     $I->see('Email is not a valid email address.', '.help-block');
     $I->see('URL is not a valid URL.', '.help-block');
     $I->amGoingTo('submit media-comment with correct data');
     $updatePage->submit(['comment_author' => 'Tester', 'comment_author_email' => '*****@*****.**', 'comment_author_url' => 'http://tester.com']);
     $I->expect('media-comment updated');
     $I->dontSee('Email is not a valid email address.', '.help-block');
     $I->dontSee('URL is not a valid URL.', '.help-block');
     MediaComment::findOne(1)->updateAll(['comment_author' => 'Mr. WritesDown', 'comment_author_email' => '*****@*****.**', 'comment_author_url' => 'http://www.writesdown.com']);
 }
Example #8
0
 /**
  * @param AcceptanceTester $I
  */
 public function testComment(AcceptanceTester $I)
 {
     $I->wantTo('ensure that media comment works');
     $mediaView = MediaViewPage::openBy($I);
     // $I->see('Test Media', 'h1');
     $I->see('Test Media');
     $I->amGoingTo('submit media comment form with no data');
     $mediaView->submitComment([]);
     $I->expectTo('see validations error');
     $I->see('Name cannot be blank.', '.help-block');
     $I->see('Email cannot be blank.', '.help-block');
     $I->see('Content cannot be blank.', '.help-block');
     $I->amGoingTo('submit media comment form with no correct email');
     $mediaView->submitComment(['comment_author' => 'tester', 'comment_author_email' => 'tester.email', 'comment_content' => 'New comment']);
     $I->expectTo('see that email is not correct');
     $I->see('Email is not a valid email address.');
     $I->dontSee('Name cannot be blank.', '.help-block');
     $I->dontSee('Content cannot be blank.', '.help-block');
     $I->amGoingTo('submit media comment form with correct data');
     $mediaView->submitComment(['comment_author' => 'tester', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'New comment']);
     $I->expect('new comment saved');
     $I->dontSee('Name cannot be blank.', '.help-block');
     $I->dontSee('Email cannot be blank.', '.help-block');
     $I->dontSee('Content cannot be blank.', '.help-block');
     MediaComment::deleteAll(['comment_author' => 'tester']);
     Media::findOne(1)->updateAttributes(['media_comment_count' => '1']);
 }
 /**
  * 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.');
     }
 }