Exemplo n.º 1
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         YBoardVote::deleteAll(['choice_id' => $this->id]);
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 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;
     }
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getVote()
 {
     return $this->hasOne(YBoardVote::className(), ['poll_id' => 'id']);
 }
Exemplo n.º 4
0
 /**
  * Handle Ajax call for voting
  */
 public function actionVote()
 {
     if (!Yii::$app->user->can('app.forum.forum.vote')) {
         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['poll_id'])) {
         $this->poll = YBoardPoll::findOne($_POST['poll_id']);
         if (isset($_POST['choice'])) {
             // In case of a revote: remove previous votes
             $votes = YBoardVote::find()->where(['poll_id' => $_POST['poll_id'], 'user_id' => Yii::$app->user->id])->all();
             foreach ($votes as $vote) {
                 $this->poll->updateCounters(['votes' => -1]);
                 $model = YBoardChoice::findOne($vote->choice_id);
                 $model->updateCounters(['votes' => -1]);
                 $vote->delete();
             }
             foreach ($_POST['choice'] as $choice) {
                 $model = new YBoardVote();
                 $model->poll_id = $_POST['poll_id'];
                 $model->choice_id = $choice;
                 $model->user_id = Yii::$app->user->id;
                 $model->save();
                 $model = YBoardChoice::findOne($choice);
                 $model->updateCounters(array('votes' => 1));
                 $this->poll->updateCounters(array('votes' => 1));
             }
             $provider = new ActiveDataProvider(['query' => YBoardChoice::find()->where(['poll_id' => $_POST['poll_id']])->orderBy('sort'), 'pagination' => false]);
             $json['html'] = $this->renderAjax('poll', array('choiceProvider' => $provider), true);
             $json['success'] = 'yes';
         } else {
             $json['success'] = 'no';
         }
     } else {
         $json['success'] = 'no';
     }
     echo json_encode($json);
     Yii::$app->end();
 }