/**
  * 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]));
 }
예제 #2
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();
     }
 }