Ejemplo n.º 1
0
 /**
  * Callback to validate module database records.
  *
  * @param Event $event
  */
 public static function onIntegrityCheck($event)
 {
     $integrityController = $event->sender;
     $integrityController->showTestHeadline("Polls Module - Answers (" . PollAnswer::find()->count() . " entries)");
     foreach (PollAnswer::find()->joinWith('poll')->all() as $answer) {
         if ($answer->poll === null) {
             if ($integrityController->showFix("Deleting poll answer id " . $answer->id . " without existing poll!")) {
                 $answer->delete();
             }
         }
     }
     $integrityController->showTestHeadline("Polls Module - Answers User (" . PollAnswerUser::find()->count() . " entries)");
     foreach (PollAnswerUser::find()->joinWith(['poll', 'user'])->all() as $answerUser) {
         if ($answerUser->poll === null) {
             if ($integrityController->showFix("Deleting poll answer id " . $answerUser->id . " without existing poll!")) {
                 $answerUser->delete();
             }
         }
         if ($answerUser->user === null) {
             if ($integrityController->showFix("Deleting poll answer id " . $answerUser->id . " without existing user!")) {
                 $answerUser->delete();
             }
         }
     }
 }
 /**
  * Returns a user list including the pagination which contains all results
  * for an answer
  */
 public function actionUserListResults()
 {
     $poll = $this->getPollByParameter();
     $answerId = (int) Yii::$app->request->get('answerId', '');
     $answer = PollAnswer::findOne(['id' => $answerId]);
     if ($answer == null || $poll->id != $answer->poll_id) {
         throw new HttpException(401, Yii::t('PollsModule.controllers_PollController', 'Invalid answer!'));
     }
     $query = User::find();
     $query->leftJoin('poll_answer_user', 'poll_answer_user.created_by=user.id');
     $query->andWhere('poll_answer_user.poll_id IS NOT NULL');
     $query->andWhere('poll_answer_user.poll_answer_id = ' . $answerId);
     $query->orderBy('poll_answer_user.created_at DESC');
     $title = Yii::t('PollsModule.controllers_PollController', "Users voted for: <strong>{answer}</strong>", array('{answer}' => Html::encode($answer->answer)));
     return $this->renderAjaxContent(UserListBox::widget(['query' => $query, 'title' => $title]));
 }
Ejemplo n.º 3
0
 public function vote($votes = array())
 {
     if ($this->hasUserVoted()) {
         return;
     }
     $voted = false;
     foreach ($votes as $answerId) {
         $answer = PollAnswer::findOne(array('id' => $answerId, 'poll_id' => $this->id));
         $userVote = new PollAnswerUser();
         $userVote->poll_id = $this->id;
         $userVote->poll_answer_id = $answer->id;
         if ($userVote->save()) {
             $voted = true;
         }
     }
     if ($voted) {
         $activity = new \humhub\modules\polls\activities\NewVote();
         $activity->source = $this;
         $activity->originator = Yii::$app->user->getIdentity();
         $activity->create();
     }
 }