116 (
new IntegerField(
"ID", [
"primary" =>
true,
"autocomplete" =>
true])),
119 (
new BooleanField(
"ACTIVE", [
"values" => [
"N",
"Y"],
"default_value" =>
"Y"])),
120 (
new IntegerField(
"ANONYMITY", [
"default_value" => Anonymity::PUBLICLY])),
121 (
new EnumField(
"NOTIFY", [
"values" => [
"N",
"Y",
"I"],
"default_value" =>
"N"])),
123 (
new Reference(
"AUTHOR", \
Bitrix\Main\UserTable::class, Join::on(
"this.AUTHOR_ID",
"ref.ID"))),
125 (
new DatetimeField(
"DATE_START", [
"default_value" =>
function(){
return new DateTime();},
"required" =>
true,
"validation" =>
function() {
128 [__CLASS__,
"validateActivityDate"]
131 (
new DatetimeField(
"DATE_END", [
"default_value" =>
function(){
135 },
"required" =>
true,
"validation" =>
function() {
138 [__CLASS__,
"validateActivityDate"]
145 (
new EnumField(
"DESCRIPTION_TYPE", [
"values" => [
"text",
"html"],
"default_value" =>
"text"])),
147 (
new Reference(
"IMAGE", FileTable::class, Join::on(
"this.IMAGE_ID",
"ref.ID"))),
151 (
new IntegerField(
"UNIQUE_TYPE", [
"default_value" => EventLimits::BY_IP|EventLimits::BY_USER_ID])),
152 (
new IntegerField(
"KEEP_IP_SEC", [
"default_value" => 604800])),
153 (
new IntegerField(
"OPTIONS", [
"default_value" => Option::ALLOW_REVOTE])),
156 "WHEN (%s='Y' AND %s='Y' AND %s <= {$now} AND {$now} <= %s AND %s='Y') THEN 'yellow' ".
157 "WHEN (%s='Y' AND %s='Y' AND %s <= {$now} AND {$now} <= %s AND %s!='Y') THEN 'green' ".
160 [
"CHANNEL.ACTIVE",
"ACTIVE",
"DATE_START",
"DATE_END",
"CHANNEL.VOTE_SINGLE",
161 "CHANNEL.ACTIVE",
"ACTIVE",
"DATE_START",
"DATE_END",
"CHANNEL.VOTE_SINGLE"])),
162 (
new Reference(
"CHANNEL", ChannelTable::class, Join::on(
"this.CHANNEL_ID",
"ref.ID"))),
163 (
new Reference(
"QUESTION", QuestionTable::class, Join::on(
"this.ID",
"ref.VOTE_ID"))),
164 (
new Reference(
"USER", \
Bitrix\Main\UserTable::class, Join::on(
"this.AUTHOR_ID",
"ref.ID"))),
174 public static function validateActivityDate($value, $primary, $row, $field)
179 $field,
Loc::getMessage(
"VOTE_ERROR_DATE_VOTE_IS_EMPTY"), $field->getName()
190 public static function onBeforeAdd(\
Bitrix\Main\ORM\Event $event)
192 $result = new \Bitrix\Main\ORM\EventResult();
193 if (($events = GetModuleEvents(
"vote",
"onBeforeVoteAdd",
true)) && !empty($events))
196 $data = $event->getParameter(
"fields");
197 foreach ($events as $ev)
199 if (ExecuteModuleEventEx($ev, array(&$data)) ===
false)
201 $result->addError(
new EntityError(
"Error: ".serialize($ev),
"event"));
205 if ($data != $event->getParameter(
"fields"))
207 $result->modifyFields($data);
210 return self::modifyData($event, $result);
218 $id = $event->getParameter(
"id");
219 $id = is_array($id) && array_key_exists(
"ID", $id) ? $id[
"ID"] : $id;
220 $fields = $event->getParameter(
"fields");
222 foreach (GetModuleEvents(
"vote",
"onAfterVoteAdd",
true) as $event)
223 ExecuteModuleEventEx($event, [$id, $fields]);
231 public static function onBeforeUpdate(\
Bitrix\Main\ORM\
Event $event)
233 $result = new \Bitrix\Main\ORM\EventResult();
234 if (($events = GetModuleEvents(
"vote",
"onBeforeVoteUpdate",
true)) && !empty($events))
237 $data = $event->getParameter(
"fields");
238 $id = $event->getParameter(
"id");
239 $id = is_array($id) && array_key_exists(
"ID", $id) ? $id[
"ID"] : $id;
240 foreach ($events as $ev)
242 if (ExecuteModuleEventEx($ev, array($id, &$data)) ===
false)
244 $result->addError(
new EntityError(
"Error: ".serialize($ev),
"event"));
248 if ($data != $event->getParameter(
"fields"))
250 $result->modifyFields($data);
253 return self::modifyData($event, $result);
262 $id = $event->getParameter(
"id");
263 $id = is_array($id) && array_key_exists(
"ID", $id) ? $id[
"ID"] : $id;
264 $fields = $event->getParameter(
"fields");
266 foreach (GetModuleEvents(
"vote",
"onAfterVoteUpdate",
true) as $event)
267 ExecuteModuleEventEx($event, [$id, $fields]);
278 $data = array_merge($event->getParameter(
"fields"), $result->getModified());
281 if (isset($data[
"UNIQUE_TYPE"]) && (
282 !($data[
"UNIQUE_TYPE"] & \
Bitrix\
Vote\
Vote\EventLimits::BY_USER_AUTH) &&
283 ($data[
"UNIQUE_TYPE"] & \
Bitrix\
Vote\
Vote\EventLimits::BY_USER_DATE_REGISTER ||
288 foreach ([
"TIMESTAMP_X",
"DATE_START",
"DATE_END"] as $key)
290 if (isset($data[$key]) && !($data[$key] instanceof
DateTime))
295 if (array_key_exists(
"IMAGE_ID", $data))
297 if ($str = \CFile::CheckImageFile($data[
"IMAGE_ID"]))
299 $result->addError(
new FieldError(static::getEntity()->getField(
"IMAGE_ID"), $str));
303 $fields[
"IMAGE_ID"] = $data[
"IMAGE_ID"];
304 $fields[
"IMAGE_ID"][
"MODULE_ID"] =
"vote";
305 if ($id = $event->getParameter(
"id"))
307 $id = is_integer($id) ? $id : $id[
"ID"];
308 if ($id > 0 && ($vote = VoteTable::getById($id)->fetch()) && ($vote[
"IMAGE_ID"] > 0))
310 $fields[
"IMAGE_ID"][
"old_file"] = $vote[
"IMAGE_ID"];
313 if (\CFile::SaveForDB($fields,
"IMAGE_ID",
"") ===
false)
315 $result->unsetField(
"IMAGE_ID");
322 $result->modifyFields(array_merge($result->getModified(), $fields));
333 public static function checkFields(Result $result, $primary, array $data)
335 parent::checkFields($result, $primary, $data);
336 if ($result->isSuccess())
345 if ($result instanceof AddResult)
349 "ACTIVE" => (array_key_exists(
"ACTIVE", $data) ? $data[
"ACTIVE"] :
"Y"),
350 "CHANNEL_ID" => $data[
"CHANNEL_ID"],
351 "DATE_START" => $data[
"DATE_START"],
352 "DATE_END" => $data[
"DATE_END"]
355 else if (array_key_exists(
"CHANNEL_ID", $data) ||
356 array_key_exists(
"ACTIVE", $data) && $data[
"ACTIVE"] ==
"Y" ||
357 array_key_exists(
"DATE_START", $data) ||
358 array_key_exists(
"DATE_END", $data)
364 "ID" => $primary[
"ID"],
365 "ACTIVE" => (array_key_exists(
"ACTIVE", $data) ? $data[
"ACTIVE"] : $vote[
"ACTIVE"]),
366 "CHANNEL_ID" => (array_key_exists(
"CHANNEL_ID", $data) ? $data[
"CHANNEL_ID"] : $vote[
"CHANNEL_ID"]),
367 "DATE_START" => (array_key_exists(
"DATE_START", $data) ? $data[
"DATE_START"] : $vote[
"DATE_START"]),
368 "DATE_END" => (array_key_exists(
"DATE_END", $data) ? $data[
"DATE_END"] : $vote[
"DATE_END"])
371 if (!is_null($params))
373 $params[
"DATE_START"] = static::getEntity()->getField(
"DATE_START")->cast($params[
"DATE_START"]);
374 $params[
"DATE_END"] = static::getEntity()->getField(
"DATE_END")->cast($params[
"DATE_END"]);
375 if (array_key_exists(
"DATE_END", $data))
376 $data[
"DATE_END"] = $params[
"DATE_END"];
377 if (!($params[
"DATE_START"] instanceof DateTime) || !($params[
"DATE_END"] instanceof DateTime))
378 $result->addError(
new FieldError(
379 static::getEntity()->getField(
"DATE_START"),
382 else if ($params[
"DATE_START"]->
getTimestamp() > $params[
"DATE_END"]->getTimeStamp())
384 $result->addError(
new FieldError(
385 static::getEntity()->getField(
"DATE_START"),
389 else if ($params[
"ACTIVE"] ==
"Y")
393 if ($channel[
"VOTE_SINGLE"] ==
"Y")
395 $dbRes = VoteTable::getList([
396 "select" => [
"ID",
"TITLE",
"DATE_START",
"DATE_END"],
397 "filter" => (is_null($params[
"ID"]) ? [] : [
398 "!ID" => $params[
"ID"]]) + [
399 "CHANNEL_ID" => $channel[
"ID"],
402 "><DATE_START" => [$params[
"DATE_START"], $params[
"DATE_END"]],
403 "><DATE_END" => [$params[
"DATE_START"], $params[
"DATE_END"]],
405 "<=DATE_START" => $params[
"DATE_START"],
406 ">=DATE_END" => $params[
"DATE_END"]
411 if ($res = $dbRes->fetch())
413 $field = static::getEntity()->getField(
"DATE_START");
414 $result->addError(
new FieldError(
416 Loc::getMessage(
"VOTE_ERROR_SAME_DATE_VOTE_IS_ALREADY_EXISTS", [
"#VOTE#" => $res[
"TITLE"].
" [".$res[
"ID"].
"]"])
424 catch (\Exception $e)
426 $result->addError(
new Error(
438 public static function setCounter(array $id, $increment =
true)
442 $connection = \Bitrix\Main\Application::getInstance()->getConnection();
444 $sql = intval($increment);
445 if ($increment ===
true)
447 else if ($increment ===
false)
449 $connection->queryExecute(
"UPDATE ".self::getTableName().
" SET COUNTER=".$sql.
" WHERE ID IN (".implode(
", ", $id).
")");
466 throw new \Bitrix\Main\ArgumentNullException(
"vote id");
467 parent::__construct(
$id);
472 $data = self::getData($this->
id);
475 $this->vote = array_diff_key($data, array(
"QUESTIONS" =>
""));
476 foreach ($data[
"QUESTIONS"] as $q)
478 $this->questions[$q[
"ID"]] = $q;
480 $eventManager = \Bitrix\Main\EventManager::getInstance();
481 $eventManager->addEventHandler(
"vote",
"onAfterVoteQuestionAdd", array($this,
"clearCache"));
482 $eventManager->addEventHandler(
"vote",
"onAfterVoteQuestionUpdate", array($this,
"clearCache"));
483 $eventManager->addEventHandler(
"vote",
"onAfterVoteQuestionDelete", array($this,
"clearCache"));
484 $eventManager->addEventHandler(
"vote",
"onVoteQuestionActivate", array($this,
"clearCache"));
485 $eventManager->addEventHandler(
"vote",
"onVoteReset", array($this,
"clearCache"));
492 public static function getData($id)
494 if (!array_key_exists($id, self::$storage))
496 self::$storage[$id] =
null;
498 $dbRes = VoteTable::getList(array(
502 "Q_" =>
"QUESTION.*",
503 "A_" =>
"QUESTION.ANSWER",
506 "QUESTION.C_SORT" =>
"ASC",
507 "QUESTION.ID" =>
"ASC",
508 "QUESTION.ANSWER.C_SORT" =>
"ASC",
509 "QUESTION.ANSWER.ID" =>
"ASC",
516 if (($row = $dbRes->fetch()) && $row)
520 foreach ($row as $key => $val)
521 if (mb_strpos($key,
"V_") === 0)
522 $vote[mb_substr($key, 2)] = $val;
526 "QUESTIONS" => array());
527 if ($vote[
"IMAGE_ID"] > 0)
528 $images[$vote[
"IMAGE_ID"]] = &$vote[
"IMAGE"];
529 $question = array(
"ID" =>
null);
533 foreach ($row as $key => $val)
535 if (mb_strpos($key,
"A_") === 0)
536 $answer[mb_substr($key, 2)] = $val;
538 if ($answer[
"IMAGE_ID"] > 0)
539 $images[$answer[
"IMAGE_ID"]] = &$answer[
"IMAGE"];
540 if ($answer[
"QUESTION_ID"] != $question[
"ID"])
544 foreach ($row as $key => $val)
546 if (mb_strpos($key,
"Q_") === 0)
547 $question[mb_substr($key, 2)] = $val;
554 if ($question[
"IMAGE_ID"] > 0)
555 $images[$question[
"IMAGE_ID"]] = &$question[
"IMAGE"];
556 $vote[
"QUESTIONS"][$question[
"ID"]] = &$question;
558 $answer[
"FIELD_NAME"] = $answer[
"~FIELD_NAME"] = \Bitrix\Vote\Event::getFieldName($vote[
"ID"], $question[
"ID"]);
559 $answer[
"MESSAGE_FIELD_NAME"] = \Bitrix\Vote\Event::getMessageFieldName($vote[
"ID"], $question[
"ID"], $answer[
"ID"]);
566 $answer[
"FIELD_NAME"] = $answer[
"MESSAGE_FIELD_NAME"];
570 $answer[
"FIELD_TYPE"] = $question[
"FIELD_TYPE"];
572 $answer[
"~PERCENT"] = ($question[
"COUNTER"] > 0 ? $answer[
"COUNTER"] * 100 / $question[
"COUNTER"] : 0);
573 $answer[
"PERCENT"] = round($answer[
"~PERCENT"], 2);
574 $question[
"ANSWERS"][$answer[
"ID"]] = &$answer;
576 }
while (($row = $dbRes->fetch()) && $row);
579 if (count($images) > 0)
581 $dbRes = \Bitrix\Main\FileTable::getList(array(
"select" => array(
"*"),
"filter" => array(
"ID" => array_keys($images))));
582 while ($res = $dbRes->fetch())
584 $images[$res[
"ID"]] = $res + array(
"SRC" => \CFile::GetFileSRC($res));
589 foreach ($vote[
"QUESTIONS"] as $question)
591 $questionId = strval($question[
"ID"]);
594 foreach ($question[
"ANSWERS"] as $answer)
600 self::$storage[
$id] = $vote;
604 return self::$storage[
$id];
638 public static function checkData(array &$data, $voteId = 0)
641 $questionsToRevise = [];
645 $vote = static::getData($voteId);
648 $questionsToRevise = ($vote[
"QUESTIONS"] ?: []);
650 $questionsToSave = isset($data[
"QUESTIONS"]) && is_array($data[
"QUESTIONS"]) ? $data[
"QUESTIONS"] : [];
651 unset($data[
"QUESTIONS"]);
652 VoteTable::checkFields($result, [
"ID" => $voteId], $data);
653 if (!$result->isSuccess())
657 foreach ($questionsToSave as $key => $question)
659 if (($question[
"DEL"] ??
null) ==
"Y")
662 $question[
"ID"] = intval($question[
"ID"] ??
null);
664 "ID" => (array_key_exists($question[
"ID"], $questionsToRevise) ? $question[
"ID"] :
null),
665 "QUESTION" => trim($question[
"QUESTION"]),
666 "QUESTION_TYPE" => trim($question[
"QUESTION_TYPE"]),
667 "FIELD_TYPE" => $question[
"FIELD_TYPE"],
668 "ANSWERS" => (is_array($question[
"ANSWERS"]) ? $question[
"ANSWERS"] : array()));
670 $savedAnswers = ($question[
"ID"] > 0 ? $questionsToRevise[$question[
"ID"]][
"ANSWERS"] : array());
671 $newAnswers = array();
672 foreach ($question[
"ANSWERS"] as $keya => $answer)
674 $answer[
"ID"] = intval($answer[
"ID"] ??
null);
675 $answer[
"MESSAGE"] = trim($answer[
"MESSAGE"]);
676 if (($answer[
"DEL"] ??
null) !=
"Y" && $answer[
"MESSAGE"] !==
"")
679 "ID" => $answer[
"ID"],
680 "MESSAGE" => $answer[
"MESSAGE"],
681 "MESSAGE_TYPE" => $answer[
"MESSAGE_TYPE"],
682 "FIELD_TYPE" => $answer[
"FIELD_TYPE"]);
683 if (!array_key_exists($answer[
"ID"], $savedAnswers))
684 unset($answer[
"ID"]);
686 unset($savedAnswers[$answer[
"ID"]]);
687 $newAnswers[] = $answer;
690 $question[
"ANSWERS"] = $newAnswers;
692 if ($question[
"QUESTION"] ==
"" && empty($question[
"ANSWERS"]))
694 else if ($question[
"QUESTION"] ==
"")
696 $result->addError(
new Error(
Loc::getMessage(
"VOTE_QUESTION_EMPTY", array(
"#NUMBER#" => $key)),
"QUESTION_".$key));
698 else if (empty($question[
"ANSWERS"]))
700 $result->addError(
new Error(
Loc::getMessage(
"VOTE_ANSWERS_EMPTY", array(
"#QUESTION#" => HtmlFilter::encode($question[
"QUESTION"]))),
"QUESTION_".$key));
704 foreach ($savedAnswers as $answer)
706 $question[
"ANSWERS"][] = $answer + array(
"DEL" =>
"Y");
709 unset($questionsToRevise[$question[
"ID"]]);
712 if (!$result->isSuccess())
716 foreach ($questionsToRevise as $question)
718 $questions[] = $question + array(
"DEL" =>
"Y");
730 public static function saveData($voteId, array $data)
732 if (!($voteId > 0) && empty($data[
"QUESTIONS"]))
738 $result = VoteTable::update($voteId, $data);
743 $result = VoteTable::add($data);
744 if ($result->isSuccess())
745 $voteId = $result->getId();
747 if (!$result->isSuccess())
750 $vote = static::getData($voteId);
752 $vote = \Bitrix\Vote\VoteTable::getById($voteId)->fetch();
753 $vote += [
"QUESTIONS" => []];
756 foreach ($data[
"QUESTIONS"] as $question)
758 $savedAnswers = array();
759 if ($question[
"ID"] > 0 && array_key_exists($question[
"ID"], $vote[
"QUESTIONS"]))
761 $savedAnswers = $vote[
"QUESTIONS"][$question[
"ID"]][
"ANSWERS"];
762 unset($vote[
"QUESTIONS"][$question[
"ID"]]);
763 if (isset($question[
"DEL"]) && $question[
"DEL"] ===
"Y")
765 \CVoteQuestion::Delete($question[
"ID"]);
768 $question[
"C_SORT"] = (++$iQuestions) * 10;
769 \CVoteQuestion::Update($question[
"ID"], $question);
773 $question[
"C_SORT"] = (++$iQuestions) * 10;
774 $question[
"VOTE_ID"] = $vote[
"ID"];
775 $question[
"ID"] = \CVoteQuestion::Add($question);
776 if ($question[
"ID"] <= 0)
780 foreach ($question[
"ANSWERS"] as $answer)
782 if (!empty($answer[
"ID"]) && array_key_exists($answer[
"ID"], $savedAnswers))
784 unset($savedAnswers[$answer[
"ID"]]);
785 if ($answer[
"DEL"] ==
"Y")
787 \CVoteAnswer::Delete($answer[
"ID"]);
790 $answer[
"C_SORT"] = (++$iAnswers)* 10;
791 \CVoteAnswer::Update($answer[
"ID"], $answer);
795 $answer[
"QUESTION_ID"] = $question[
"ID"];
796 $answer[
"C_SORT"] = (++$iAnswers) * 10;
797 $answer[
"ID"] = intval(\CVoteAnswer::Add($answer));
798 if ($answer[
"ID"] <= 0)
804 \CVoteQuestion::Delete($question[
"ID"]);
807 else if (!empty($savedAnswers))
809 while ($answer = array_pop($savedAnswers))
810 \CVoteAnswer::Delete($answer[
"ID"]);
813 if ($iQuestions <= 0)
833 if (!empty($vote[
"URL"]))
835 if (defined(
"SITE_SERVER_NAME"))
836 $url = SITE_SERVER_NAME;
837 $url = (!empty($url) ? $url : \COption::GetOptionString(
"main",
"server_name"));
839 $url = (\CMain::IsHTTPS() ?
"https" :
"http") .
"://" . $url . $vote[
"URL"];
844 if ($event[
"VISIBLE"] ==
"Y" && $this->
getUser()->getParam(
"PERSONAL_GENDER") ==
"F")
847 "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
848 "TO_USER_ID" => $vote[
"AUTHOR_ID"],
849 "FROM_USER_ID" => ( $event[
"VISIBLE"] ==
"Y" ? $this->
getUser()->
getId() : 0),
850 "NOTIFY_TYPE" => IM_NOTIFY_FROM,
851 "NOTIFY_MODULE" =>
"vote",
852 "NOTIFY_EVENT" =>
"voting",
853 "NOTIFY_TAG" =>
"VOTING|" . $vote[
"ID"],
854 "NOTIFY_MESSAGE" => (!empty($vote[
"URL"]) ?
855 Loc::getMessage(
"V_NOTIFY_MESSAGE_HREF" . $gender, array(
"#VOTE_TITLE#" => $vote[
"TITLE"],
"#VOTE_URL#" => $vote[
"URL"])) :
856 Loc::getMessage(
"V_NOTIFY_MESSAGE" . $gender, array(
"#VOTE_TITLE#" => $vote[
"TITLE"]))),
857 "NOTIFY_MESSAGE_OUT" => (!empty($url) ?
858 Loc::getMessage(
"V_NOTIFY_MESSAGE_OUT_HREF" . $gender, array(
"#VOTE_TITLE#" => $vote[
"TITLE"],
"#VOTE_URL#" => $url)) :
859 Loc::getMessage(
"V_NOTIFY_MESSAGE" . $gender, array(
"#VOTE_TITLE#" => $vote[
"TITLE"])))
861 \CIMNotify::Add($res);
867 $dbUser = \CUser::getById($vote[
"AUTHOR_ID"]);
868 if ($dbUser && ($u = $dbUser->Fetch()) && !empty($u[
"EMAIL"]))
870 $eventFields = array(
871 "EMAIL_TO" => $u[
"EMAIL"],
872 "VOTE_STATISTIC" =>
"",
873 "ID" => $event[
"EVENT_ID"],
874 "TIME" => GetTime(time(),
"FULL"),
875 "VOTE_TITLE" => $vote[
"TITLE"],
876 "VOTE_DESCRIPTION" => $vote[
"DESCRIPTION"],
877 "VOTE_ID" => $vote[
"ID"],
878 "VOTE_COUNTER" => $vote[
"COUNTER"],
879 "URL" => $vote[
"URL"],
882 "VOTER_ID" => $event[
"VOTE_USER_ID"],
883 "USER_NAME" => ($event[
"VISIBLE"] ==
"Y" ? $this->
getUser()->getFullName() :
"Hidden"),
884 "LOGIN" => ($event[
"VISIBLE"] ==
"Y" ? $this->
getUser()->getLogin() :
"hidden"),
885 "USER_ID" => ($event[
"VISIBLE"] ==
"Y" ? $this->
getUser()->getID() : 0),
886 "STAT_GUEST_ID" => intval($_SESSION[
"SESS_GUEST_ID"]),
887 "SESSION_ID" => intval($_SESSION[
"SESS_SESSION_ID"]),
888 "IP" => \Bitrix\Main\Context::getCurrent()->getServer()->get(
"REMOTE_ADDR")
890 $eventFields[
"USER_NAME"] = (!!$eventFields[
"USER_NAME"] && $event[
"VISIBLE"] ==
"Y" ? $eventFields[
"USER_NAME"] : $eventFields[
"LOGIN"]);
893 foreach ($this[
"QUESTIONS"] as $question)
895 if (array_key_exists($question[
"ID"], $event[
"BALLOT"]))
897 $text[$question[
"ID"]] = array();
898 foreach ($question[
"ANSWERS"] as $answer)
900 if (array_key_exists($answer[
"ID"], $event[
"BALLOT"][$question[
"ID"]][
"ANSWERS"]))
903 $event[
"BALLOT"][$question[
"ID"]][
"ANSWERS"][$answer[
"ID"]][
"MESSAGE"] !==
"")
905 $text[$question[
"ID"]][] = $event[
"BALLOT"][$question[
"ID"]][
"ANSWERS"][$answer[
"ID"]][
"MESSAGE"];
909 $text[$question[
"ID"]][] = $answer[
"MESSAGE"];
913 if (!empty($text[$question[
"ID"]]))
915 $text[$question[
"ID"]] =
" - " . $question[
"QUESTION"] .
"\n - " . implode(
", ", $text[$question[
"ID"]]);
919 $text[$question[
"ID"]] =
" - " . $question[
"QUESTION"] .
"\n - ...\n";
923 $eventFields[
"VOTE_STATISTIC"] =
"\n" . implode(
"\n\n", $text);
924 $arrSites = \CVoteChannel::GetSiteArray(
$channel[
"ID"]);
925 \CEvent::Send(
"VOTE_FOR", $arrSites, $eventFields,
"N");
938 foreach ($this->questions as &$qs)
939 foreach ($qs[
"ANSWERS"] as &$as)
940 $as[
"STAT"] = array();
942 $dbRes = \Bitrix\Vote\EventTable::getList(array(
945 "Q_" =>
"QUESTION.*",
946 "A_" =>
"QUESTION.ANSWER.*",
947 "U_ID" =>
"USER.USER.ID",
948 "U_NAME" =>
"USER.USER.NAME",
949 "U_LAST_NAME" =>
"USER.USER.LAST_NAME",
950 "U_SECOND_NAME" =>
"USER.USER.SECOND_NAME",
951 "U_LOGIN" =>
"USER.USER.LOGIN",
952 "U_PERSONAL_PHOTO" =>
"USER.USER.PERSONAL_PHOTO",
954 "filter" => array(
"VOTE_ID" => $this->
id,
"VALID" =>
"Y"),
956 "USER.USER.LAST_NAME" =>
"ASC",
957 "USER.USER.NAME" =>
"ASC",
958 "USER.USER.LOGIN" =>
"ASC"
961 while ($dbRes && ($res = $dbRes->fetch()))
963 if (array_key_exists($res[
"Q_QUESTION_ID"], $this->questions) &&
964 array_key_exists($res[
"A_ANSWER_ID"], $this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"]))
966 $stat = &$this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"][$res[
"A_ANSWER_ID"]][
"STAT"];
971 "MESSAGE" => $res[
"A_MESSAGE"]
974 $res[
"V_VISIBLE"] ==
"Y" && $res[
"U_ID"] > 0)
976 $result[
"USER"] = array(
977 "ID" => $res[
"U_ID"],
978 "NAME" => $res[
"U_NAME"],
979 "LAST_NAME" => $res[
"U_LAST_NAME"],
980 "SECOND_NAME" => $res[
"U_SECOND_NAME"],
981 "LOGIN" => $res[
"U_LOGIN"],
982 "PERSONAL_PHOTO" => $res[
"U_PERSONAL_PHOTO"],
985 $stat[$res[
"A_ID"]] = $result;
991 $dbRes = \Bitrix\Vote\EventTable::getList(array(
994 "Q_" =>
"QUESTION.*",
995 "A_" =>
"QUESTION.ANSWER.*",
996 "U_ID" =>
"USER.USER.ID",
997 "U_NAME" =>
"USER.USER.NAME",
998 "U_LAST_NAME" =>
"USER.USER.LAST_NAME",
999 "U_SECOND_NAME" =>
"USER.USER.SECOND_NAME",
1000 "U_PERSONAL_PHOTO" =>
"USER.USER.PERSONAL_PHOTO",
1002 "filter" => array(
"VOTE_ID" => $this->
id,
"VALID" =>
"Y"),
1004 "USER.USER.LAST_NAME" =>
"ASC",
1005 "USER.USER.NAME" =>
"ASC",
1006 "USER.USER.LOGIN" =>
"ASC"
1010 while ($dbRes && ($res = $dbRes->fetch()))
1012 if (!array_key_exists($res[
"V_ID"], $result))
1014 $result[$res[
"V_ID"]] = [
1015 "ID" => $res[
"V_ID"],
1016 "DATE" => $res[
"V_DATE_VOTE"],
1018 $res[
"V_VISIBLE"] ==
"Y" ?
"Y" :
"N"),
1020 "USER" => [
"ID" => 0]
1022 if ($result[$res[
"V_ID"]][
"VISIBLE"] ==
"Y" && $res[
"U_ID"] > 0)
1024 $result[$res[
"V_ID"]][
"USER"] = array(
1025 "ID" => $res[
"U_ID"],
1026 "NAME" => $res[
"U_NAME"],
1027 "LAST_NAME" => $res[
"U_LAST_NAME"],
1028 "SECOND_NAME" => $res[
"U_SECOND_NAME"],
1029 "LOGIN" => $res[
"U_LOGIN"],
1030 "PERSONAL_PHOTO" => $res[
"U_PERSONAL_PHOTO"],
1034 $ballot = &$result[$res[
"V_ID"]][
"BALLOT"];
1035 if (!array_key_exists($res[
"Q_QUESTION_ID"], $ballot))
1037 $ballot[$res[
"Q_QUESTION_ID"]] = [];
1039 $ballot[$res[
"Q_QUESTION_ID"]][$res[
"A_ANSWER_ID"]] = trim($res[
"A_MESSAGE"]);
1048 if ($this->channel ===
null)
1050 $this->channel = array();
1052 while (($res = $db->fetch()) && $res)
1054 if ($this->vote[
"CHANNEL_ID"] == $res[
"ID"])
1056 $this->channel = $res;
1061 return $this->channel;
1068 public function get($key)
1070 return $this->vote[$key];
1080 if (array_key_exists($id, $this->questions))
1081 return $this->questions[$id];
1089 return $this->questions;
1098 VoteTable::update($this->
id, [
"DATE_END" => (
new DateTime())->add(
"1Y")]);
1108 VoteTable::update($this->
id, [
"DATE_END" =>
new DateTime()]);
1117 public static function delete(
$id)
1120 return \CVote::Delete(
$id);
1130 unset($VOTE_CACHE[
"VOTE"][$this->
id]);
1131 unset(self::$storage[$this->
id]);
1132 unset(self::$canVoteStorage[$this->
id]);
1138 private function clearVotingCache()
1141 unset($VOTE_CACHE[
"VOTE_CACHE_VOTING"][$this->
id]);
1142 unset(self::$canVoteStorage[$this->
id]);
1152 global $APPLICATION;
1154 $dateTemplate = \Bitrix\Main\Type\DateTime::getFormat();
1156 $APPLICATION->restartBuffer();
1157 while(ob_get_clean());
1158 header(
"Content-Transfer-Encoding: binary");
1161 $table1 = [
"body" => []];
1167 foreach ($statistic as $event)
1170 if ($event[
"VISIBLE"] !==
"Y")
1174 else if ($event[
"USER"][
"ID"] > 0)
1176 $user = \CUser::formatName($nameTemplate, $event[
"USER"],
true,
false);
1180 "DATE" => $event[
"DATE"]->toUserTime()->format($dateTemplate),
1184 foreach ($this->questions as $questionId => $question)
1186 $answerMessage = [];
1187 if (array_key_exists($questionId, $event[
"BALLOT"]))
1189 foreach ($question[
"ANSWERS"] as $answerId => $answer)
1191 if (array_key_exists($answerId, $event[
"BALLOT"][$questionId]))
1193 if (!array_key_exists(
"STAT", $this->questions[$questionId][
"ANSWERS"][$answerId]))
1194 $this->questions[$questionId][
"ANSWERS"][$answerId][
"STAT"] = [];
1195 $stat = &$this->questions[$questionId][
"ANSWERS"][$answerId][
"STAT"];
1196 if ($event[
"BALLOT"][$questionId][$answerId] <>
'')
1198 $stat[$event[
"ID"]] = $row[
"USER"].
" (".$event[
"BALLOT"][$questionId][$answerId].
")";
1199 $answerMessage[] = $event[
"BALLOT"][$questionId][$answerId];
1203 $answerMessage[] = $answer[
"MESSAGE"];
1204 $stat[$event[
"ID"]] = $row[
"USER"];
1209 $row[] = implode(
", ", $answerMessage);
1211 $table2[
"body"][] = array_values($row);
1213 foreach ($this->questions as $questionId => $question)
1215 $table1[
"body"][] = [$question[
"QUESTION"],
"",
"",
""];
1216 foreach ($question[
"ANSWERS"] as $answerId => $answer)
1218 $table1[
"body"][] = [
"", $answer[
"MESSAGE"], $answer[
"COUNTER"], (array_key_exists(
"STAT", $answer) ? implode(
", ", $answer[
"STAT"]) :
"")];
1220 $table2[
"head"][] = $question[
"QUESTION"];
1223 if ($type ===
"csv")
1225 Header(
"Content-Type: ". MimeType::getByFileExtension(
"csv"));
1226 header(
"Content-Disposition: attachment;filename=vote".$this->
id.
".csv");
1228 $f = fopen(
"php://output",
"w");
1229 fputcsv($f, $table2[
"head"],
';');
1230 foreach ($table2[
"body"] as $row) {
1231 fputcsv($f, $row,
';');
1241 if ($type ===
"xls")
1244 foreach ($table1[
"body"] as $row)
1246 $bodyRows[] = implode(
"</Data></Cell><Cell ss:StyleID=\"bold\"><Data ss:Type=\"String\">", $row);
1248 $table1[
"body"] = implode(
"</Data></Cell></Row><Row><Cell><Data ss:Type=\"String\">", $bodyRows);
1250 $table2[
"head"] = implode(
"</Data></Cell><Cell ss:StyleID=\"bold\"><Data ss:Type=\"String\">", $table2[
"head"]);
1252 foreach ($table2[
"body"] as $row)
1254 $bodyRows[] = implode(
"</Data></Cell><Cell ss:StyleID=\"bold\"><Data ss:Type=\"String\">", $row);
1256 $table2[
"body"] = implode(
"</Data></Cell></Row><Row><Cell><Data ss:Type=\"String\">", $bodyRows);
1257 $LANG_CHARSET = LANG_CHARSET;
1260<?xml version=
"1.0" charset=
"{$LANG_CHARSET}"?>
1261<?mso-application progid=
"Excel.Sheet"?>
1262<Workbook xmlns=
"urn:schemas-microsoft-com:office:spreadsheet" xmlns:o=
"urn:schemas-microsoft-com:office:office" xmlns:x=
"urn:schemas-microsoft-com:office:excel" xmlns:ss=
"urn:schemas-microsoft-com:office:spreadsheet" xmlns:html=
"http://www.w3.org/TR/REC-html40">
1264 <Style ss:ID=
"bold">
1268 <Worksheet ss:Name=
"{$mess["GENERAL_INFO
"]}">
1271 <Cell><Data ss:
Type=
"String">{$table1[
"body"]}</Data></Cell>
1275 <Worksheet ss:Name=
"{$mess["STATISTIC
"]}">
1278 <Cell ss:StyleID=
"bold"><Data ss:
Type=
"String">{$table2[
"head"]}</Data></Cell>
1281 <Cell><Data ss:
Type=
"String">{$table2[
"body"]}</Data></Cell>
1290 $LANG_CHARSET = LANG_CHARSET;
1293 foreach ($table1[
"body"] as $row)
1295 $bodyRows[] = implode(
"</td><td>", $row);
1297 $table1[
"body"] = implode(
"</td></tr><tr><td>", $bodyRows);
1299 $table2[
"head"] = implode(
"</th><th>", $table2[
"head"]);
1301 foreach ($table2[
"body"] as $row)
1303 $bodyRows[] = implode(
"</td><td>", $row);
1305 $table2[
"body"] = implode(
"</td></tr><tr><td>", $bodyRows);
1308<meta http-equiv=
"Content-type" content=
"text/html;charset={$LANG_CHARSET}" />
1312 <tr><td>{$table1[
"body"]}</td></tr>
1318 <thead><tr><th>{$table2[
"head"]}</th></tr></thead>
1319 <tbody><tr><td>{$table2[
"body"]}</td></tr></tbody>
1324 header(
"Content-Type: ". MimeType::getByFileExtension(
"xls"));
1325 header(
"Content-Disposition: attachment;filename=vote".$this->
id.
".xls");
1328 \CMain::finalActions();
1332 private function getDataFromRequest(array $request)
1334 $res = \Bitrix\Vote\Event::getDataFromRequest($this->getId(), $request);
1341 $questions = $this->getQuestions();
1342 $data = [
"EXTRAS" => [],
"BALLOT" => [],
"MESSAGE" => []];
1344 foreach ($questions as $question)
1346 $data[
"BALLOT"][$question[
"ID"]] = array();
1347 foreach ($question[
"ANSWERS"] as $answer)
1350 $question[
"FIELD_TYPE"] == \Bitrix\Vote\QuestionTypes::COMPATIBILITY ||
1352 $answer[
"FIELD_TYPE"] : $question[
"FIELD_TYPE"]);
1358 $fieldName = ($fieldType ==
AnswerTypes::RADIO ?
"vote_radio_" :
"vote_dropdown_").$question[
"ID"];
1359 if ($request[$fieldName] == $answer[
"ID"])
1360 $data[
"BALLOT"][$question[
"ID"]][$answer[
"ID"]] =
true;
1364 $fieldName = ($fieldType ==
AnswerTypes::CHECKBOX ?
"vote_checkbox_" :
"vote_multiselect_").$question[
"ID"];
1365 if (array_key_exists($fieldName, $request) && is_array($request[$fieldName]) && in_array($answer[
"ID"], $request[$fieldName]))
1366 $data[
"BALLOT"][$question[
"ID"]][$answer[
"ID"]] =
true;
1369 $fieldName = ($answer[
"FIELD_TYPE"] ==
AnswerTypes::TEXT ?
"vote_field_" :
"vote_memo_") . $answer[
"ID"];
1370 $value = trim($request[$fieldName]);
1373 if (!array_key_exists($question[
"ID"], $data[
"MESSAGE"]))
1374 $data[
"MESSAGE"][$question[
"ID"]] = [];
1375 $data[
"MESSAGE"][$question[
"ID"]][$answer[
"ID"]] = $value;
1376 $data[
"BALLOT"][$question[
"ID"]][$answer[
"ID"]] =
true;
1403 public function voteFor(array $request, $params = [])
1405 return $this->registerEvent($this->getDataFromRequest($request), $params,
User::getCurrent());
1408 public function registerEvent(array $data, array $params, \
Bitrix\
Vote\
User $user)
1410 if ($this[
"LAMP"] ==
"red")
1414 $voteId = $this->getId();
1415 if ($user->lock($voteId) !==
true)
1420 $userId = $user->getId();
1422 $this->errorCollection->clear();
1425 if ($params[
"revote"] !=
true)
1427 $result = $this->canVote($user);
1432 && $result->isSuccess()
1433 && !empty($result->getData())
1434 && ($eventIdsToDelete = array_column($result->getData(),
'ID'))
1435 && !empty($eventIdsToDelete)
1438 $dbRes = \Bitrix\Vote\EventTable::getList([
1441 "Q_" =>
"QUESTION.*",
1442 "A_" =>
"QUESTION.ANSWER.*"],
1444 "VOTE_ID" => $voteId,
1445 "ID" => $eventIdsToDelete],
1448 "QUESTION.ID" =>
"ASC",
1449 "QUESTION.ANSWER.ID" =>
"ASC"]
1451 if ($dbRes && ($res = $dbRes->fetch()))
1455 \CIMNotify::DeleteByTag(
"VOTING|".$voteId, $userId);
1461 if ($vEId < $res[
"V_ID"])
1463 $vEId = $res[
"V_ID"];
1464 \Bitrix\Vote\Event::deleteEvent(intval($res[
"V_ID"]));
1465 $this->vote[
"COUNTER"] = max($this->vote[
"COUNTER"] - 1, 0);
1467 if (array_key_exists($res[
"Q_QUESTION_ID"], $this->questions) &&
1468 array_key_exists($res[
"A_ANSWER_ID"], $this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"]))
1470 if ($qEId < $res[
"Q_ID"])
1472 $qEId = $res[
"Q_ID"];
1473 $this->questions[$res[
"Q_QUESTION_ID"]][
"COUNTER"] = max($this->questions[$res[
"Q_QUESTION_ID"]][
"COUNTER"] - 1, 0);
1476 $this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"][$res[
"A_ANSWER_ID"]][
"COUNTER"] = max(
1477 $this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"][$res[
"A_ANSWER_ID"]][
"COUNTER"] - 1,
1479 if ($this->questions[$res[
"Q_QUESTION_ID"]][
"COUNTER"] > 0)
1481 $this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"][$res[
"A_ANSWER_ID"]][
"~PERCENT"] =
1482 $this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"][$res[
"A_ANSWER_ID"]][
"COUNTER"] * 100 /
1483 $this->questions[$res[
"Q_QUESTION_ID"]][
"COUNTER"];
1484 $this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"][$res[
"A_ANSWER_ID"]][
"PERCENT"] = round($this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"][$res[
"A_ANSWER_ID"]][
"~PERCENT"], 2);
1488 $this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"][$res[
"A_ANSWER_ID"]][
"~PERCENT"] = 0;
1489 $this->questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"][$res[
"A_ANSWER_ID"]][
"PERCENT"] = 0;
1492 }
while ($dbRes && ($res = $dbRes->fetch()));
1494 $this->clearVotingCache();
1496 $result = $this->canVote($user);
1500 if (!$result->isSuccess())
1502 $this->errorCollection->add($result->getErrors());
1506 $event = new \Bitrix\Vote\Event($this);
1510 $eventFields = array(
1512 "DATE_VOTE" => (
new DateTime()),
1513 "STAT_SESSION_ID" => $_SESSION[
"SESS_SESSION_ID"],
1518 if (!$event->check($data)
1519 || !($eventResult = $event->add($eventFields, $data))
1522 $this->errorCollection->add($event->getErrors());
1526 $this->vote[
"COUNTER"]++;
1527 foreach ($eventResult->get(
"BALLOT") as $questionId => $question)
1529 $this->questions[$questionId][
"COUNTER"]++;
1530 foreach ($question[
"ANSWERS"] as $answerId => $answerEventParams)
1532 $this->questions[$questionId][
"ANSWERS"][$answerId][
"COUNTER"]++;
1535 foreach ($this->questions as $questionId => $question)
1537 foreach ($question[
"ANSWERS"] as $answerId => $answerEventParams)
1539 if ($this->questions[$questionId][
"ANSWERS"][$answerId][
"COUNTER"] > 0)
1541 $this->questions[$questionId][
"ANSWERS"][$answerId][
"~PERCENT"] =
1542 $this->questions[$questionId][
"ANSWERS"][$answerId][
"COUNTER"] * 100 /
1543 $this->questions[$questionId][
"COUNTER"];
1544 $this->questions[$questionId][
"ANSWERS"][$answerId][
"PERCENT"] = round($this->questions[$questionId][
"ANSWERS"][$answerId][
"~PERCENT"], 2);
1548 $this->questions[$questionId][
"ANSWERS"][$answerId][
"~PERCENT"] = 0;
1549 $this->questions[$questionId][
"ANSWERS"][$answerId][
"PERCENT"] = 0;
1553 self::$statStorage[] = $voteId;
1554 $_SESSION[
"VOTE"][
"VOTES"][$voteId] = $eventResult->get(
"EVENT_ID");
1558 $event3 = $this[
"EVENT3"];
1561 $event3 = (\Bitrix\Main\Context::getCurrent()->getRequest()->isHttps() ?
"https://" :
"http://") .
1563 "/bitrix/admin/vote_user_results.php?EVENT_ID=" . $eventResult->get(
"EVENT_ID") .
"&lang=" . LANGUAGE_ID;
1565 \CStatEvent::AddCurrent($this[
"EVENT1"], $this[
"EVENT2"], $event3);
1568 if ($this[
"NOTIFY"] !==
"N" && $this[
"AUTHOR_ID"] > 0 && $this[
"AUTHOR_ID"] != $userId)
1570 self::sendVotingMessage($eventResult->toArray(), $this, ($this[
"NOTIFY"] ==
"I" ?
"im" :
"mail"));
1574 foreach (GetModuleEvents(
"vote",
"onAfterVoting",
true) as $ev)
1576 ExecuteModuleEventEx($ev, array($voteId, $eventResult->get(
"EVENT_ID"), $userId));
1581 $user->unlock($voteId);
1582 return $this->errorCollection->isEmpty();
1590 public function isVotedFor($userId)
1594 $canVoteResult = $this->canVote($user);
1595 if (!$canVoteResult->isSuccess())
1599 $canVoteResult->getErrorCollection()->rewind();
1600 $canVoteResult->getErrorCollection()->valid();
1601 $canVoteResult->getErrorCollection()->next()
1605 $error = $canVoteResult->getErrorCollection()->current();
1606 $result |= $error->getCode();
1618 if (parent::canEdit($userId))
1620 else if (parent::canRead($userId))
1622 $groups = parent::loadUserGroups($userId);
1624 "select" => array(
"*"),
1628 ">=PERMISSION.PERMISSION" => 1,
1629 "PERMISSION.GROUP_ID" => $groups
1634 "group" => array(
"ID")
1636 while ($res = $dbRes->fetch())
1638 if ($res[
"ID"] == $this->
get(
"CHANNEL_ID"))
1652 if (parent::canEdit($userId))
1654 else if (parent::canRead($userId))
1656 $groups = parent::loadUserGroups($userId);
1658 "select" => array(
"*"),
1662 ">=PERMISSION.PERMISSION" => 4,
1663 "PERMISSION.GROUP_ID" => $groups
1668 "group" => array(
"ID")
1670 while ($res = $dbRes->fetch())
1672 if ($res[
"ID"] == $this->
get(
"CHANNEL_ID"))
1681 return $this->
canRead($userId) && $this->vote[
"LAMP"] ==
"green";
1692 public function canVote($user)
1695 $voteId = intval($vote[
"ID"]);
1698 $user = \Bitrix\Vote\User::loadFromId($user);
1700 if (!array_key_exists($voteId, self::$canVoteStorage))
1702 self::$canVoteStorage[$voteId] = [];
1704 if (array_key_exists($user->getId(), self::$canVoteStorage[$voteId]))
1706 return self::$canVoteStorage[$voteId][$user->getId()];
1709 $uniqueType = intval($vote[
"UNIQUE_TYPE"]);
1712 $filter = [
"LOGIC" =>
"OR"];
1714 $result = new \Bitrix\Main\Result();
1716 if ($uniqueType & \
Bitrix\Vote\Vote\
EventLimits::BY_SESSION && is_array($_SESSION[
"VOTE"][
"VOTES"]) && array_key_exists($voteId, $_SESSION[
"VOTE"][
"VOTES"]))
1718 $filter[
"ID"] = $_SESSION[
"VOTE"][
"VOTES"][$voteId];
1724 $filter[
"USER.COOKIE_ID"] = $user->getCookieId();
1729 $delay = intval($vote[
"KEEP_IP_SEC"]);
1731 "IP" => \Bitrix\Main\Context::getCurrent()->getRequest()->getRemoteAddress()] +
1733 ">=DATE_VOTE" => (new \Bitrix\Main\Type\DateTime())->add(
"-T".$delay.
"S")] : []));
1741 if (!$user->getUser()->IsAuthorized())
1750 $us = \CUser::GetByID($user->getId())->fetch();
1751 if (MakeTimeStamp($vote[
"DATE_START"]) < MakeTimeStamp($us[
"DATE_REGISTER"]))
1758 $filter[
"USER.AUTH_USER_ID"] = $user->getId();
1764 if ($filterCard > 0)
1766 $dbRes = \Bitrix\Vote\EventTable::getList([
1769 "USER_COOKIE_ID" =>
"USER.COOKIE_ID",
1770 "USER_AUTH_USER_ID" =>
"USER.AUTH_USER_ID",
1773 "VOTE_ID" => $voteId,
1777 $data = $dbRes->fetchAll();
1778 $result->setData($data);
1779 foreach ($data as $res)
1788 if ($vote[
"KEEP_IP_SEC"] > 0)
1791 $res[
"DATE_VOTE"]->add(
"T".$vote[
"KEEP_IP_SEC"].
"S");
1805 if ($filterCard <= 0)
1809 self::$canVoteStorage[$voteId][$user->getId()] = $result;
1815 $canVoteResult = $this->canVote($user);
1816 $result = new \Bitrix\Main\Result();
1817 if ($canVoteResult->isSuccess() || (
1820 $canVoteResult->getErrorCollection()->count() == 1
1823 $result->setData($canVoteResult->getData());
1826 return $canVoteResult;
1831 $result = new \Bitrix\Main\Result();
1835 $user = \Bitrix\Vote\User::loadFromId($user);
1838 if ($this[
"AUTHOR_ID"] != $user->getId())
1842 $result->addError(
new Error(
"Access denied.",
"Hidden results"));
1844 else if ($this[
"LAMP"] ==
"green")
1846 $canVoteResult = $this->canVote($user);
1847 if ($canVoteResult->isSuccess())
1848 $result->addError(
new Error(
"Access denied.",
"Hidden results"));
1860 if ($offset ==
"QUESTIONS")
1862 return array_key_exists($offset, $this->vote);
1870 if (array_key_exists($offset, $this->vote))
1871 return $this->vote[$offset];
1872 else if ($offset ==
"QUESTIONS")
1873 return $this->questions;
1885 throw new \Bitrix\Main\NotSupportedException(
"Model provide ArrayAccess only for reading");
1895 throw new \Bitrix\Main\NotSupportedException(
"Model provide ArrayAccess only for reading");