Пример #1
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         //delete all upvotes and polls
         YBoardUpvoted::deleteAll(['poll_id' => $this->id]);
         return true;
     } else {
         return false;
     }
 }
Пример #2
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         //delete: Messages(to/from), Ban History, UpVotes, LogTopic
         YBoardMessage::deleteAll(['or', 'sendfrom' => $this->id, 'sendto' => $this->id]);
         // Post(Polls and Votes)
         YBoardVote::deleteAll(['user_id' => $this->id]);
         YBoardUpvoted::deleteAll(['member_id' => $this->id]);
         YBoardPoll::deleteAll(['user_id' => $this->id]);
         YBoardPost::deleteAll(['user_id' => $this->id]);
         //log topic
         YBoardLogTopic::deleteAll(['member_id' => $this->id]);
         //ban
         YBoardBan::deleteAll(['user_id' => $this->id]);
         return true;
     } else {
         return false;
     }
 }
Пример #3
0
 /**
  * Handle Ajax call for upvote/downvote of post
  */
 public function actionUpvote()
 {
     if (!Yii::$app->user->can('app.forum.forum.upvote')) {
         throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
     }
     $json = [];
     if (isset($_POST['id'])) {
         $criteria = ['member_id' => Yii::$app->user->identity->id, 'post_id' => $_POST['id']];
         if (YBoardUpvoted::find()->where($criteria)->count() > 0) {
             // remove upvote
             YBoardUpvoted::deleteAll($criteria);
             $post = YBoardPost::findOne($_POST['id']);
             $topic = YBoardTopic::findOne($post->topic_id);
             $member = YBoardMember::findOne($post->user_id);
             $post->updateCounters(array('upvoted' => -1));
             $topic->updateCounters(array('upvoted' => -1));
         } else {
             // add upvote
             $upvote = new YBoardUpvoted();
             $upvote->member_id = Yii::$app->user->id;
             $upvote->post_id = $_POST['id'];
             $upvote->author = $_POST['author'];
             $upvote->save();
             $post = YBoardPost::findOne($_POST['id']);
             $topic = YBoardTopic::findOne($post->topic_id);
             $member = YBoardMember::findOne($post->user_id);
             $post->updateCounters(array('upvoted' => 1));
             $topic->updateCounters(array('upvoted' => 1));
         }
         $json['success'] = 'yes';
         $json['html'] = $this->showUpvote($_POST['id']);
     } else {
         $json['success'] = 'no';
     }
     echo json_encode($json);
     Yii::$app->end();
 }