9use Bitrix\Main\Application;
10use Bitrix\Main\ArgumentException;
11use Bitrix\Main\DB\SqlExpression;
12use \Bitrix\Main\Entity;
13use \Bitrix\Main\Error;
14use \Bitrix\Main\Localization\Loc;
15use Bitrix\Main\ORM\Data\AddResult;
16use Bitrix\Main\ORM\Event;
17use \Bitrix\Main\Result;
18use \Bitrix\Main\Type\DateTime;
19use \Bitrix\Vote\Base\BaseObject;
22Loc::loadMessages(__FILE__);
73 'data_type' =>
'integer',
75 'autocomplete' =>
true,
76 'title' => Loc::getMessage(
'V_TABLE_FIELD_ID'),
79 'data_type' =>
'integer',
80 'title' => Loc::getMessage(
'V_TABLE_FIELD_AUTH_USER_ID'),
82 'AUTH_USER_ID' =>
array(
83 'data_type' =>
'integer',
84 'title' => Loc::getMessage(
'V_TABLE_FIELD_AUTH_USER_ID'),
87 'data_type' =>
'integer',
88 'title' => Loc::getMessage(
'V_TABLE_FIELD_COUNTER'),
90 'DATE_FIRST' =>
array(
91 'data_type' =>
'datetime',
92 'title' => Loc::getMessage(
'V_TABLE_FIELD_DATE_FIRST'),
95 'data_type' =>
'datetime',
96 'title' => Loc::getMessage(
'V_TABLE_FIELD_DATE_LAST'),
99 'data_type' =>
'string',
101 'title' => Loc::getMessage(
'V_TABLE_FIELD_STAT_SESSION_ID')
103 'STAT_GUEST_ID' =>
array(
104 'data_type' =>
'integer',
105 'title' => Loc::getMessage(
'V_TABLE_FIELD_STAT_GUEST_ID'),
108 'data_type' =>
'\Bitrix\Main\UserTable',
109 'reference' =>
array(
110 '=this.AUTH_USER_ID' =>
'ref.ID',
112 'join_type' =>
'LEFT',
128 $sql = intval($increment);
129 if ($increment ===
true)
131 else if ($increment ===
false)
133 $connection->queryExecute(
"UPDATE ".self::getTableName().
" SET COUNTER=".$sql.
" WHERE ID IN (".implode(
", ", $id).
")");
139 private const DB_TIMELOCK = 15;
161 return intval(
$APPLICATION->get_cookie(
"VOTE_USER_ID"));
170 "COOKIE_ID" => $cookieId,
171 "AUTH_USER_ID" => intval($this->
getId())
175 if ($cookieId > 0 && !array_key_exists(
$id, self::$usersIds) && (
$res = UserTable::getList([
178 "COOKIE_ID" => $cookieId,
179 "AUTH_USER_ID" => intval($this->
getId())
183 self::$usersIds[
$id] = intval(
$res[
"ID"]);
185 return isset(self::$usersIds[
$id]) ? self::$usersIds[
$id] : 0;
193 $cookie = new \Bitrix\Main\Web\Cookie(
"VOTE_USER_ID", strval(
$id));
194 \Bitrix\Main\Context::getCurrent()->getResponse()->addCookie($cookie);
204 "STAT_GUEST_ID" => intval($_SESSION[
"SESS_GUEST_ID"] ?? 0),
206 "LAST_IP" =>
$_SERVER[
"REMOTE_ADDR"]
208 if ($incrementCount ===
true)
210 else if ($incrementCount ===
false)
222 "AUTH_USER_ID" => intval($this->
getId()),
224 "COUNTER" => ($incrementCount ===
true ? 1 : 0)
229 $add = !
$dbRes->isSuccess();
235 $sql =
"INSERT INTO ".UserTable::getTableName().
"(COOKIE_ID, ".$insert[0].
") ".
236 "SELECT COALESCE(MAX(COOKIE_ID) + 1, 0), ".$insert[1] .
" FROM ".UserTable::getTableName();
240 $dbRes->setData(UserTable::getById(
$dbRes->getId())->fetch());
245 self::$usersIds[implode(
248 "COOKIE_ID" =>
$fields[
"COOKIE_ID"],
249 "AUTH_USER_ID" =>
$fields[
"AUTH_USER_ID"] ??
null
260 public function isVotedFor($voteId)
267 $result = $vote->isVotedFor($this);
276 public static function isUserVotedFor($voteId,
$userId)
290 return implode(
'_', [
297 public function lock(
int $voteId): bool
300 return Application::getConnection()->lock($lockingKey, self::DB_TIMELOCK);
306 Application::getConnection()->unlock($lockingKey);
315 if (is_null(self::$instance))
317 return self::$instance;
322 $_SESSION[
"VOTE"] = [
"VOTES" => []];
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static loadFromId($id, $shouldBeNewIfIdIsNull=false)
getLockingKey(int $voteId)
setVotedUserId($incrementCount=null)
static setCounter(array $id, $increment=true)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]