Controller::processActionGetBallot

  1. Bitrix24 API (v. 23.675.0)
  2. vote
  3. Controller
  4. processActionGetBallot
  • Модуль: vote
  • Путь к файлу: ~/bitrix/modules/vote/lib/attachment/controller.php
  • Класс: BitrixVoteAttachmentController
  • Вызов: Controller::processActionGetBallot
protected function processActionGetBallot()
{
	$attach = $this->attach;
	$eventId = 0;
	$userId = 0;
	if ($this->getUser()->isAdmin() && $this->request->getQuery("eventId") > 0)
		$eventId = $this->request->getQuery("eventId");
	else
	{
		$userId = $this->getUser()->getId();
		if ($attach->canRead($userId) && ($result = $attach->canRevote($userId)) && $result->isSuccess())
		{
			$event = reset($result->getData());
			$eventId = $event["ID"];
		}
	}
	$stat = array();
	$extras = array();
	if ($eventId > 0)
	{
		$dbRes = EventTable::getList(array(
			"select" => array(
				"V_" => "*",
				"Q_" => "QUESTION.*",
				"A_" => "QUESTION.ANSWER.*",
				"U_ID" => "USER.USER.ID",
				"U_NAME" => "USER.USER.NAME",
				"U_LAST_NAME" => "USER.USER.LAST_NAME",
				"U_SECOND_NAME" => "USER.USER.SECOND_NAME",
				"U_LOGIN" => "USER.USER.LOGIN",
				"U_PERSONAL_PHOTO" => "USER.USER.PERSONAL_PHOTO",
			),
			"filter" => array(
				"ID" => $eventId,
				"VOTE_ID" => $attach["VOTE_ID"]
			)
		));
		$questions = $attach["QUESTIONS"];
		if ($dbRes && ($res = $dbRes->fetch()))
		{
			$userId = $res["U_ID"];
			$extras = array(
				"VISIBLE" => $res["V_VISIBLE"],
				"VALID" => $res["V_VALID"]
			);
			do
			{
				if (!array_key_exists($res["Q_QUESTION_ID"], $questions) ||
					!array_key_exists($res["A_ANSWER_ID"], $questions[$res["Q_QUESTION_ID"]]["ANSWERS"]))
					continue;
				if (!array_key_exists($res["Q_QUESTION_ID"], $stat))
					$stat[$res["Q_QUESTION_ID"]] = array();

				$stat[$res["Q_QUESTION_ID"]][$res["A_ANSWER_ID"]] = array(
					"EVENT_ID" => $res["A_ID"],
					"EVENT_QUESTION_ID" => $res["Q_ID"],
					"ANSWER_ID" => $res["ANSWER_ID"],
					"ID" => $res["A_ID"], // delete this
					"MESSAGE" => $res["A_MESSAGE"]
				);
			} while ($res = $dbRes->fetch());
		}
	}
	$this->sendJsonSuccessResponse(array(
		"action" => $this->getAction(),
		"data" => array(
			"attach" => array(
				"ID" => $attach["ID"],
				"VOTE_ID" => $attach["VOTE_ID"],
				"FIELD_NAME" => $attach["FIELD_NAME"],
				"QUESTIONS" => $attach["QUESTIONS"]
			),
			"event" => array(
				"id" => $eventId,
				"userId" => $userId,
				"ballot" => $stat,
				"extras" => $extras
			)
		)
	));
}

Добавить комментарий