Пример #1
0
 /**
  * Finds the Comment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Comment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #2
0
 /**
  * Возвращает комментарий.
  * @param int $id идентификатор комментария
  * @throws NotFoundHttpException
  * @return Comment
  */
 public function getComment($id)
 {
     if (($model = Comment::findOne($id)) !== null && $model->isPublished()) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested post does not exist.');
     }
 }
Пример #3
0
 public function save()
 {
     $comment = Comment::findOne($this->commentID);
     $comment->setAttributes(['author' => $this->author, 'text' => $this->text, 'email' => $this->email, 'published' => $this->published, 'deleted' => $this->deleted]);
     if ($comment->save(false)) {
         \Yii::$app->session->setFlash('saved', 'Комментарий сохранён!');
     } else {
         \Yii::$app->session->setFlash('error', 'Комментарий не сохранён!');
     }
 }
Пример #4
0
 public function actionAlarm()
 {
     $id = Yii::$app->request->post('id');
     $msg = Yii::$app->request->post('msg');
     $comment = Comment::findOne($id);
     if ($comment && !empty($msg)) {
         if (Alarm::addAlarm(Alarm::ENTITY_COMMENT, $comment->id, $msg)) {
             return json_encode(['content' => \frontend\widgets\CommentsWidget::widget(['entity' => $comment->entity, 'entity_id' => $comment->entity_id, 'showDialog' => false]), 'anchor' => $comment->id]);
         } else {
             return json_encode(['content' => '', 'anchor' => '']);
         }
     }
 }
Пример #5
0
 public static function addVote($entity, $id, $voteAdd)
 {
     $user = User::thisUser();
     $vote = Vote::findOne(['entity' => $entity, 'entity_id' => $id, 'user_id' => $user->id]);
     if (empty($vote)) {
         $vote = new Vote();
         $vote->entity = $entity;
         $vote->entity_id = $id;
         $vote->user_id = $user->id;
     }
     /** @var VoteModel $model */
     $model = null;
     if ($entity == self::ENTITY_ITEM) {
         $model = Item::findOne($id);
         if ($user->reputation < Item::MIN_REPUTATION_ITEM_VOTE) {
             // Если только пользователь не отменяет свои дизлайки
             if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
                 return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
             }
         }
     } else {
         if ($entity == self::ENTITY_EVENT) {
             $model = Event::findOne($id);
             if ($user->reputation < Event::MIN_REPUTATION_EVENT_VOTE) {
                 // Если только пользователь не отменяет свои дизлайки
                 if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
                     return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
                 }
             }
         } else {
             if ($entity == self::ENTITY_SCHOOL) {
                 $model = School::findOne($id);
                 if ($user->reputation < School::MIN_REPUTATION_SCHOOL_VOTE) {
                     // Если только пользователь не отменяет свои дизлайки
                     if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
                         return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
                     }
                 }
             } else {
                 if ($entity == self::ENTITY_COMMENT) {
                     $model = Comment::findOne($id);
                     if ($user->reputation < Comment::MIN_REPUTATION_COMMENT_VOTE) {
                         // Если только пользователь не отменяет свои дизлайки
                         if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
                             return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
                         }
                     }
                 }
             }
         }
     }
     if (!empty($model)) {
         if ($vote->vote == self::VOTE_UP) {
             if ($voteAdd == self::VOTE_UP) {
                 // убираем up
                 $vote->vote = self::VOTE_NONE;
                 $model->addVote(-1);
                 $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP);
             } else {
                 // ставим down
                 $vote->vote = self::VOTE_DOWN;
                 $model->addVote(-2);
                 $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP);
                 $model->addReputation(VoteModel::ADD_REPUTATION_DOWN);
             }
         } elseif ($vote->vote == self::VOTE_DOWN) {
             if ($voteAdd == self::VOTE_UP) {
                 // ставим up
                 $vote->vote = self::VOTE_UP;
                 $model->addVote(2);
                 $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN);
                 $model->addReputation(VoteModel::ADD_REPUTATION_UP);
             } else {
                 // убираем down
                 $vote->vote = self::VOTE_NONE;
                 $model->addVote(1);
                 $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN);
             }
         } else {
             if ($voteAdd == self::VOTE_UP) {
                 // ставим up
                 $vote->vote = self::VOTE_UP;
                 $model->addVote(1);
                 $model->addReputation(VoteModel::ADD_REPUTATION_UP);
             } else {
                 // ставим down
                 $vote->vote = self::VOTE_DOWN;
                 $model->addVote(-1);
                 $model->addReputation(VoteModel::ADD_REPUTATION_DOWN);
             }
         }
     }
     if ($vote->save()) {
         if (!empty($model)) {
             $model->save();
         }
     }
     return ['vote' => $vote->vote, 'count' => $model->getVoteCount()];
 }
Пример #6
0
 /**
  * Url: /complain/{$id}
  * @param int $id Comment id
  * @return mixed
  * @throws BadRequestHttpException
  * @throws NotFoundHttpException
  */
 public function actionComplain($id)
 {
     $comment = Comment::findOne($id);
     if (!isset($comment)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     if (Yii::$app->user->isGuest) {
         throw new BadRequestHttpException('Для отправки жалобы авторизируйтесь.');
     }
     $claim = Claim::find()->where(['comment_id' => $comment->id, 'user_id' => Yii::$app->user->id])->one();
     if (!isset($claim->id)) {
         $claim = new Claim();
         $claim->comment_id = $comment->id;
         $claim->comment_author = $comment->user_id;
         $claim->user_id = Yii::$app->user->id;
     }
     if ($claim->load(Yii::$app->request->post())) {
         $claim->save();
     }
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Жалоба на комментарий', 'columnFirst' => ['claim' => ['view' => '@frontend/views/forms/complain_form', 'data' => compact('comment', 'claim')]], 'columnSecond' => ['photo_news' => SiteBlock::getPhotoNews(), 'banner1' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner2' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner3' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner4' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner5' => SiteBlock::getBanner(Banner::REGION_NEWS)]]);
 }