Exemplo n.º 1
0
 /**
  * @param string $topicSlug
  * @param int    $topicId
  *
  * @return \Illuminate\Http\RedirectResponse
  *
  * @throws \Exception
  */
 public function undo($topicSlug, $topicId)
 {
     $topic = $this->topicRepository->find($topicId);
     if (!$topic) {
         throw new TopicNotFoundException();
     }
     if (!$topic->has_poll) {
         throw new PollNotFoundException();
     }
     $poll = $topic->poll;
     $pollPresenter = app()->make('MyBB\\Core\\Presenters\\Poll', [$poll]);
     if (!$this->guard->check()) {
         throw new PollNoGuestUndoException();
     }
     if ($pollPresenter->is_closed) {
         throw new PollClosedException();
     }
     $vote = $this->pollVoteRepository->findForUserPoll($this->guard->user(), $poll);
     if (!$vote) {
         // Error
         throw new PollNoUndoException();
     }
     $votes = explode(',', $vote->vote);
     $options = $pollPresenter->options();
     foreach ($votes as $option) {
         if (is_numeric($option) && 0 < $option && $option <= $pollPresenter->num_options()) {
             $options[$option - 1]['votes']--;
         }
     }
     $poll->update(['options' => $options]);
     $vote->delete();
     return redirect()->route('polls.show', [$topicSlug, $topicId]);
 }
Exemplo n.º 2
0
 /**
  * @return mixed
  */
 public function myVote()
 {
     if (!isset($this->cache['myVote'])) {
         if ($this->guard->check()) {
             $this->cache['myVote'] = $this->pollVoteRepository->findForUserPoll($this->guard->user(), $this->wrappedObject);
         } else {
             $this->cache['myVote'] = null;
         }
     }
     return $this->cache['myVote'];
 }
Exemplo n.º 3
0
 /**
  * Remove the poll
  *
  * @param Poll $poll
  *
  * @return bool
  */
 public function remove(Poll $poll)
 {
     $this->dbManager->transaction(function () use(&$poll) {
         $this->pollVoteRepository->removeAllByPoll($poll);
         $poll->delete();
     });
     if ($poll) {
         return false;
     } else {
         return true;
     }
 }