9use \Bitrix\Main\AccessDeniedException;
10use \Bitrix\Main\ArgumentNullException;
11use \Bitrix\Main\ArgumentTypeException;
12use \Bitrix\Main\Entity;
13use \Bitrix\Main\Error;
14use \Bitrix\Main\ErrorCollection;
15use \Bitrix\Main\InvalidOperationException;
16use \Bitrix\Main\Localization\Loc;
17use \Bitrix\Main\ArgumentException;
18use \Bitrix\Main\NotSupportedException;
19use Bitrix\Main\Result;
20use Bitrix\Main\Security\Random;
21use \Bitrix\Main\Type\DateTime;
22use \Bitrix\Vote\Attachment\Connector;
23use \Bitrix\Vote\Base\BaseObject;
24use \Bitrix\Vote\DBResult;
25use \Bitrix\Main\SystemException;
26use \Bitrix\Vote\Event;
27use \Bitrix\Main\ObjectNotFoundException;
28use Bitrix\Vote\Integration\Pull\VoteChangesSender;
29use Bitrix\Vote\Model\Dto\UserBallot;
30use Bitrix\Vote\Vote\Anonymity;
32Loc::loadMessages(__FILE__);
69 return 'b_vote_attached_object';
80 'data_type' =>
'integer',
82 'autocomplete' =>
true,
83 'title' => Loc::getMessage(
'V_TABLE_FIELD_ID'),
86 'data_type' =>
'integer',
87 'title' => Loc::getMessage(
'V_TABLE_FIELD_OBJECT_ID'),
90 'data_type' =>
'string',
92 'title' => Loc::getMessage(
'V_TABLE_FIELD_MODULE_ID')
94 'ENTITY_TYPE' =>
array(
95 'data_type' =>
'string',
97 'title' => Loc::getMessage(
'V_TABLE_FIELD_ENTITY_TYPE')
100 'data_type' =>
'integer',
101 'title' => Loc::getMessage(
'V_TABLE_FIELD_OBJECT_ID'),
103 'CREATE_TIME' =>
array(
104 'data_type' =>
'datetime',
105 'title' => Loc::getMessage(
'V_TABLE_FIELD_TIMESTAMP_X'),
107 'CREATED_BY' =>
array(
108 'data_type' =>
'integer',
109 'title' => Loc::getMessage(
'V_TABLE_FIELD_AUTHOR_ID'),
112 'data_type' =>
'string',
116 'data_type' =>
'\Bitrix\Vote\VoteTable',
117 'reference' =>
array(
118 '=this.OBJECT_ID' =>
'ref.ID',
120 'join_type' =>
'INNER',
131 return new DBResult(parent::getList($parameters));
144 throw new \Bitrix\Main\ArgumentNullException(
'filter');
148 'select' =>
array(
'ID'),
153 if(!empty($row[
'ID']))
155 $resultDelete = static::delete($row[
'ID']);
156 if(!$resultDelete->isSuccess())
167 $row = AttachTable::query()
175 return $row[
'ID'] ??
null;
194 "attachIds" =>
array(),
195 "voteIds" =>
array(),
196 "entities" =>
array()
208 if (is_array($this->
id))
226 if (!array_key_exists(
"MODULE_ID",
$attach) ||
$attach[
"MODULE_ID"] ==
'')
228 if (!array_key_exists(
"ENTITY_TYPE",
$attach) ||
$attach[
"ENTITY_TYPE"] ==
'')
230 if (array_key_exists(
"ID",
$attach))
231 $this->
id = intval(
$attach[
"ID"]);
277 $filter = array_change_key_case(
$id, CASE_UPPER);
285 if (!array_key_exists(
$id, self::$storage))
287 self::$storage[
$id] =
null;
292 'V_LAMP' =>
'VOTE.LAMP',
293 'Q_' =>
'VOTE.QUESTION.*',
294 'A_' =>
'VOTE.QUESTION.ANSWER',
298 'VOTE.QUESTION.C_SORT' =>
'ASC',
299 'VOTE.QUESTION.ID' =>
'ASC',
300 'VOTE.QUESTION.ANSWER.C_SORT' =>
'ASC',
301 'VOTE.QUESTION.ANSWER.ID' =>
'ASC',
308 $vote = [
"ID" =>
null];
309 $question = [
"ID" =>
null];
313 $buffer = [
"attach" => [],
"vote" => [],
"question" => []];
318 if (mb_strpos(
$key,
"O_") === 0)
320 else if (mb_strpos(
$key,
"V_") === 0)
322 else if (mb_strpos(
$key,
"Q_") === 0)
324 else if (mb_strpos(
$key,
"A_") === 0)
339 "QUESTIONS" =>
array());
340 if (
$vote[
"IMAGE_ID"] > 0)
342 if (!array_key_exists(
$vote[
"ID"], Vote::$storage))
345 if (
$buffer[
"question"][
"ID"] != $question[
"ID"])
353 if ($question[
"IMAGE_ID"] > 0)
354 $images[$question[
"IMAGE_ID"]] = &$question[
"IMAGE"];
357 $vote[
"QUESTIONS"][$question[
"ID"]] = &$question;
367 $answer[
"FIELD_NAME"] = $answer[
"MESSAGE_FIELD_NAME"];
371 $answer[
"FIELD_TYPE"] = $question[
"FIELD_TYPE"];
373 $answer[
"~PERCENT"] = ($question[
"COUNTER"] > 0 ? $answer[
"COUNTER"] * 100 / $question[
"COUNTER"] : 0);
374 $answer[
"PERCENT"] = round($answer[
"~PERCENT"], 2);
375 $question[
"ANSWERS"][$answer[
"ID"]] = &$answer;
379 unset(
$vote); unset($question);
381 if (
count($images) > 0)
383 $dbRes = \Bitrix\Main\FileTable::getList(
array(
'select' =>
array(
'*'),
'filter' =>
array(
'ID' => array_keys($images))));
396 self::$storage[
$id] = (is_array(self::$storage[
$id]) ? self::$storage[
$id] :
array());
402 return self::$storage[
$id];
412 $id1 = md5(serialize(
$id));
413 if (!array_key_exists($id1, self::$storage))
415 self::$storage[$id1] =
array();
421 'V_LAMP' =>
'VOTE.LAMP',
422 'Q_' =>
'VOTE.QUESTION.*',
423 'A_' =>
'VOTE.QUESTION.ANSWER',
426 'VOTE.QUESTION.C_SORT' =>
'ASC',
427 'VOTE.QUESTION.ID' =>
'ASC',
428 'VOTE.QUESTION.ANSWER.C_SORT' =>
'ASC',
429 'VOTE.QUESTION.ANSWER.ID' =>
'ASC',
432 'ENTITY_TYPE' =>
$id[
'ENTITY_TYPE'],
433 'ENTITY_ID' =>
$id[
'ENTITY_ID']
441 if (mb_strpos(
$key,
"O_") === 0)
443 else if (mb_strpos(
$key,
"V_") === 0)
446 $questions = &
$vote[
"QUESTIONS"];
452 if (mb_strpos(
$key,
"Q_") === 0)
453 $question[mb_substr(
$key, 2)] =
$val;
454 else if (mb_strpos(
$key,
"A_") === 0)
457 $qid =
"".$question[
"ID"];
458 if (!array_key_exists($qid, $questions))
459 $questions[$qid] = array_merge($question,
array(
"ANSWERS" =>
array()));
462 $answers = &$questions[$qid][
"ANSWERS"];
465 if (!array_key_exists($answer[
"ID"], $answers))
466 $answers[$answer[
"ID"]] = $answer;
476 return self::$storage[$id1];
497 return $this->
getConnector()->canRead(
$userId) && is_object($this->vote) && $this->vote[
"LAMP"] ==
"green";
502 return $this->vote->canVote(
$userId);
507 return $this->vote->canRevote(
$userId);
512 return $this->vote->canReadResult(
$userId);
533 if ($this->connector ===
null)
535 $this->connector = Connector::buildFromAttachedObject($this);
545 if (!($this->channel instanceof
Channel))
547 $this->
setStorage($this->vote instanceof
Vote ? $this->vote[
"CHANNEL_ID"] :
null);
557 return $this->attach[
'ID'] ??
null;
565 return is_object($this->vote) ? $this->vote[
"ID"] :
null;
573 return $this->attach[
"MODULE_ID"];
581 return $this->attach[
"ENTITY_TYPE"];
589 return $this->attach[
"ENTITY_ID"];
597 if (is_object($this->vote))
598 $this->vote->fillStatistic();
605 public function delete()
607 if (empty($this->vote))
610 if ($this->attach[
"ID"] > 0)
611 AttachTable::delete($this->attach[
"ID"]);
614 "select" =>
array(
"ID",
"OBJECT_ID"),
615 "filter" =>
array(
"OBJECT_ID" => $this->vote[
"ID"]),
653 $data = array_merge(
$data, (is_null($this->vote) ? [
662 if ((
$data[
"TITLE"] ??
null) ==
'' && is_array(
$data[
"QUESTIONS"]))
664 $q = reset(
$data[
"QUESTIONS"]);
665 if (is_array($q) && $q[
"QUESTION"] <>
'')
667 $data[
"TITLE"] = $q[
"QUESTION"];
695 if (!isset(
$data[
"AUTHOR_ID"]))
696 $data[
"AUTHOR_ID"] = $createdBy;
700 $voteId = Vote::saveData(is_null($this->vote) ? 0 : $this->vote[
"ID"],
$data);
703 if (!array_key_exists(
"ID", $this->attach))
707 'OBJECT_ID' => $voteId,
710 'CREATED_BY' => $createdBy,
716 $id = $this->attach[
"ID"];
722 else if ($this->attach[
"ID"] ??
null > 0)
724 $this->attach =
null;
746 if (!is_object($this->vote))
755 $this->sendVotingPush($actionUuid);
759 $this->errorCollection->add($this->vote->getErrors());
771 if (!is_object($this->vote))
773 $this->vote->exportExcel();
783 return $this->vote->isVotedFor(
$userId);
795 public function resume(
string $actionUuid =
'')
797 if (!is_object($this->vote))
799 $this->vote->resume();
815 public function stop(
string $actionUuid =
'')
817 if (!is_object($this->vote))
838 if (is_array($this->attach) && array_key_exists($offset, $this->attach) || is_object($this->vote) && isset($this->vote[$offset]))
840 if ($offset ==
"VOTE_ID" && is_object($this->vote))
851 if (is_array($this->attach) && array_key_exists($offset, $this->attach))
852 return $this->attach[$offset];
853 if (is_object($this->vote))
855 if (isset($this->vote[$offset]))
856 return $this->vote[$offset];
857 if ($offset ==
"VOTE_ID")
858 return $this->vote[
"ID"];
892 return parent::loadFromId(
$id,
true);
897 $eventId = $this->getUserEventId(
$userId);
911 "Q_" =>
"QUESTION.*",
912 "A_" =>
"QUESTION.ANSWER.*",
913 "U_ID" =>
"USER.USER.ID",
917 "VOTE_ID" => $this[
"VOTE_ID"],
920 $questions = $this[
"QUESTIONS"];
928 "VISIBLE" =>
$res[
"V_VISIBLE"],
929 "VALID" =>
$res[
"V_VALID"]
933 if (!array_key_exists(
$res[
"Q_QUESTION_ID"], $questions) ||
934 !array_key_exists(
$res[
"A_ANSWER_ID"], $questions[
$res[
"Q_QUESTION_ID"]][
"ANSWERS"]))
936 if (!array_key_exists(
$res[
"Q_QUESTION_ID"], $stat))
940 "EVENT_ID" =>
$res[
"A_ID"],
941 "EVENT_QUESTION_ID" =>
$res[
"Q_ID"],
942 "ANSWER_ID" =>
$res[
"A_ANSWER_ID"],
943 "ID" =>
$res[
"A_ID"],
944 "MESSAGE" =>
$res[
"A_MESSAGE"]
954 $canRevoteResult = $this->
canRevote($userId);
955 if (!$canRevoteResult->isSuccess())
957 return $canRevoteResult;
963 $this->sendVotingPush($actionUuid);
969 private function getUserEventId(
int $userId): ?int
971 $eventData = $this->
canVote($userId)->getData();
972 $firstKey = array_key_first($eventData);
973 if ($firstKey ===
null)
978 return $eventData[$firstKey][
'ID'] ??
null;
981 private function sendVotingPush(
string $actionUuid): void
983 (
new VoteChangesSender())->sendVoting($this, $actionUuid);
993 $anonymity = (int)($this[
'ANONYMITY'] ?? Anonymity::UNDEFINED);
995 return $anonymity === Anonymity::PUBLICLY;
1000 return Random::getStringByAlphabet(self::UID_LENGTH, Random::ALPHABET_ALPHALOWER | Random::ALPHABET_NUM);
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
stop(string $actionUuid='')
save($data, $createdBy=0)
voteFor(array $request, string $actionUuid='')
getUserEventAnswers(int $eventId)
static getDataByEntity(array $id)
getUserEventsAnswersStatByUserId(int $userId)
resume(string $actionUuid='')
recall(int $userId, string $actionUuid='')
offsetSet($offset, $value)
static loadFromId($id, $shouldBeNewIfIdIsNull=false)
static getIdByUid(string $uid)
static deleteByFilter(array $filter)
static getList(array $parameters=array())
static loadFromId($id, $shouldBeNewIfIdIsNull=false)
static getExtrasFieldName($id, $name)
static getMessageFieldName($id, $questionId, $answerId)
static getDataFromRequest($id, array $request)
static getFieldName($id, $questionId)
if(!defined("ADMIN_AJAX_MODE") &&(($_REQUEST["mode"] ?? '') !='excel')) $buffer
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"