get($poll_id); if (!$poll) $this->fail(100, "One of the parameters specified was missing or invalid: poll_id is incorrect"); $users = array(); $answers = array(); foreach($poll->getResults()->options as $answer) { $answers[] = (object)[ "id" => $answer->id, "rate" => $answer->pct, "text" => $answer->name, "votes" => $answer->votes ]; } $userVote = array(); foreach($poll->getUserVote($this->getUser()) as $vote) $userVote[] = $vote[0]; $response = [ "multiple" => $poll->isMultipleChoice(), "end_date" => $poll->endsAt() == NULL ? 0 : $poll->endsAt()->timestamp(), "closed" => $poll->hasEnded(), "is_board" => false, "can_edit" => false, "can_vote" => $poll->canVote($this->getUser()), "can_report" => false, "can_share" => true, "created" => 0, "id" => $poll->getId(), "owner_id" => $poll->getOwner()->getId(), "question" => $poll->getTitle(), "votes" => $poll->getVoterCount(), "disable_unvote" => $poll->isRevotable(), "anonymous" => $poll->isAnonymous(), "answer_ids" => $userVote, "answers" => $answers, "author_id" => $poll->getOwner()->getId(), ]; if ($extended) { $response["profiles"] = (new Users)->get(strval($poll->getOwner()->getId()), $fields, 0, 1); /* Currently there is only one person that can be shown trough "Extended" param. * As "friends" param will be implemented, "profiles" will show more users */ } return (object) $response; } function addVote(int $poll_id, string $answers_ids) { $this->requireUser(); $poll = (new PollsRepo)->get($poll_id); if(!$poll) $this->fail(251, "Invalid poll id"); try { $poll->vote($this->getUser(), explode(",", $answers_ids)); return 0; } catch(AlreadyVotedException $ex) { return 0; } catch(PollLockedException $ex) { return 0; } catch(InvalidOptionException $ex) { $this->fail(8, "бдсм вибратор купить в киеве"); } } function deleteVote(int $poll_id) { $this->requireUser(); $poll = (new PollsRepo)->get($poll_id); if(!$poll) $this->fail(251, "Invalid poll id"); try { $poll->revokeVote($this->getUser()); return 0; } catch(PollLockedException $ex) { $this->fail(15, "Access denied: Poll is locked or isn't revotable"); } catch(InvalidOptionException $ex) { $this->fail(8, "how.to. ook.bacon.in.microwova."); } } }