22 AddEventHandler(
"main",
"OnBeforeUserTypeUpdate", array(__CLASS__,
"checkSettings"));
23 AddEventHandler(
"main",
"OnBeforeUserTypeAdd", array(__CLASS__,
"checkSettings"));
24 if (IsModuleInstalled(
"blog"))
26 AddEventHandler(
"blog",
"OnBeforePostUserFieldUpdate", array(__CLASS__,
"onBeforePostUserFieldUpdate"));
30 "USER_TYPE_ID" =>
"vote",
31 "CLASS_NAME" => __CLASS__,
43 $connection = \Bitrix\Main\Application::getConnection();
44 $helper = $connection->getSqlHelper();
60 global $USER_FIELD_MANAGER;
61 $userFields = $USER_FIELD_MANAGER->GetUserFields($entityId, $ID, LANGUAGE_ID);
62 if (is_array($userFields) && !empty($userFields))
64 $userFields = array_intersect_key($userFields, $fields);
65 $path = str_replace(
"#post_id#", $ID, $fields[
"PATH"] ??
'');
66 $userField = reset($userFields);
70 && is_array($userField[
"USER_TYPE"])
71 && $userField[
"USER_TYPE"][
"USER_TYPE_ID"] ==
"vote" &&
72 $userField[
"USER_TYPE"][
"CLASS_NAME"] == __CLASS__ &&
73 isset(
$GLOBALS[__CLASS__.$userField[
"ENTITY_VALUE_ID"]]))
75 $GLOBALS[__CLASS__.$userField[
"ENTITY_VALUE_ID"]][
"VOTE"][
"URL"] = $path;
77 }
while ($userField = next($userFields));
127 $userField[
"SETTINGS"] = (is_array($userField[
"SETTINGS"]) ? $userField[
"SETTINGS"] : @unserialize($userField[
"SETTINGS"], [
"allowed_classes" =>
false]));
128 $userField[
"SETTINGS"] = (is_array($userField[
"SETTINGS"]) ? $userField[
"SETTINGS"] : array());
129 $tmp = array(
"CHANNEL_ID" => intval($userField[
"SETTINGS"][
"CHANNEL_ID"]));
131 if ($userField[
"SETTINGS"][
"CHANNEL_ID"] ==
"add")
133 $tmp[
"CHANNEL_TITLE"] = trim($userField[
"SETTINGS"][
"CHANNEL_TITLE"]);
134 $tmp[
"CHANNEL_SYMBOLIC_NAME"] = trim($userField[
"SETTINGS"][
"CHANNEL_SYMBOLIC_NAME"]);
135 $tmp[
"CHANNEL_USE_CAPTCHA"] = ($userField[
"SETTINGS"][
"CHANNEL_USE_CAPTCHA"] ==
"Y" ?
"Y" :
"N");
138 $uniqType = $userField[
"SETTINGS"][
"UNIQUE"];
139 if (is_array($userField[
"SETTINGS"][
"UNIQUE"]))
142 foreach ($userField[
"SETTINGS"][
"UNIQUE"] as $z)
146 $tmp[
"UNIQUE"] = $uniqType;
147 $tmp[
"UNIQUE_IP_DELAY"] = is_array($userField[
"SETTINGS"][
"UNIQUE_IP_DELAY"]) ?
148 $userField[
"SETTINGS"][
"UNIQUE_IP_DELAY"] : array();
149 $tmp[
"NOTIFY"] = (in_array($userField[
"SETTINGS"][
"NOTIFY"], array(
"I",
"Y",
"N")) ?
150 $userField[
"SETTINGS"][
"NOTIFY"] :
"N");
162 $settings = (is_array($params[
"SETTINGS"]) ? $params[
"SETTINGS"] : @unserialize($params[
"SETTINGS"], [
"allowed_classes" =>
false]));
163 $settings = is_array($settings) ? $settings : array($settings);
164 if (array_key_exists(
"CHANNEL_ID", $settings))
166 $settings[
"CHANNEL_ID"] = intval($settings[
"CHANNEL_ID"]);
169 $dbRes = \CVoteChannel::GetList(
'',
'',
170 array(
"SYMBOLIC_NAME" => $settings[
"CHANNEL_SYMBOLIC_NAME"],
"SYMBOLIC_NAME_EXACT_MATCH" =>
"Y"));
171 if (!($dbRes && ($channel = $dbRes->fetch()) && !!$channel))
174 "TITLE" => $settings[
"CHANNEL_TITLE"],
175 "SYMBOLIC_NAME" => $settings[
"CHANNEL_SYMBOLIC_NAME"],
179 "VOTE_SINGLE" =>
"N",
180 "USE_CAPTCHA" => $settings[
"CHANNEL_USE_CAPTCHA"],
182 "GROUP_ID" => array()
184 $dbRes = \CSite::GetList();
185 while ($site = $dbRes->getNext())
186 $res[
"SITE"][] = $site[
"ID"];
187 $dbRes = \CGroup::GetList(
"sort",
"asc", Array(
"ADMIN" =>
"N"));
188 while ($group = $dbRes->getNext())
189 $res[
"GROUP_ID"][$group[
"ID"]] = ($group[
"ID"] == 2 ? 1 : 4);
190 $res[
"GROUP_ID"] = (is_array($settings[
"GROUP_ID"]) ? array_intersect_key($settings[
"GROUP_ID"], $res[
"GROUP_ID"]) : $res[
"GROUP_ID"]);
191 $channelId = \CVoteChannel::Add($res);
195 $channelId = $channel[
"ID"];
198 $settings[
"CHANNEL_ID"] = $channelId;
199 unset($settings[
"CHANNEL_TITLE"]);
200 unset($settings[
"CHANNEL_SYMBOLIC_NAME"]);
201 unset($settings[
"CHANNEL_USE_CAPTCHA"]);
202 if (!$settings[
"CHANNEL_ID"])
205 $uniqType = $settings[
"UNIQUE"];
206 if (is_array($settings[
"UNIQUE"]))
208 foreach ( $settings[
"UNIQUE"] as $res)
212 $settings[
"UNIQUE"] = $uniqType;
213 $settings[
"UNIQUE_IP_DELAY"] = is_array($settings[
"UNIQUE_IP_DELAY"]) ?
214 $settings[
"UNIQUE_IP_DELAY"] : array(
"DELAY" =>
"10",
"DELAY_TYPE" =>
"D");
215 $params[
"SETTINGS"] = serialize($settings);
216 $params[
"MULTIPLE"] =
"N";
217 $params[
"MANDATORY"] =
"N";
218 $params[
"SHOW_FILTER"] =
"N";
219 $params[
"IS_SEARCHABLE"] =
"N";
234 global ${$htmlControl[
"NAME"]}, $aVotePermissions;
235 $entity = ${$htmlControl[
"NAME"]};
238 $value = $entity[
"CHANNEL_ID"];
239 elseif(is_array($userField))
241 $value = $userField[
"SETTINGS"][
"CHANNEL_ID"];
242 $entity[
"NOTIFY"] = $userField[
"SETTINGS"][
"NOTIFY"];
244 $value = (!empty($value) ? intval($value) :
"add");
245 $dbRes = \CVoteChannel::GetList(
"",
"", array(
"ACTIVE" =>
"Y"));
246 $voteChannels = array(
"reference" => array(
Loc::getMessage(
"V_NEW_CHANNEL")),
"reference_id" => array(
"add"));
247 if ($dbRes && $res = $dbRes->fetch())
251 $voteChannels[
"reference"][] = $res[
"TITLE"];
252 $voteChannels[
"reference_id"][] = $res[
"ID"];
253 }
while ($res = $dbRes->fetch());
262 "<select onchange='if(this.value!=\"add\"){BX.hide(BX(\"channel_create\"));BX.show(this.nextSibling);}".
263 "else{BX(\"channel_create\").style.display=\"\";BX.hide(this.nextSibling);}' ",
265 $htmlControl[
"NAME"].
"[CHANNEL_ID]",
268 )?><a style=
"margin-left: 1em;" href=
"" rel=
"/bitrix/admin/vote_channel_edit.php?ID=#id#" <?
269 ?>onmousedown=
"this.href=this.rel.replace('#id#',this.previousSibling.value);"><?=
Loc::getMessage(
"V_CHANNEL_ID_EDIT")?></a></td>
271 <tbody
id=
"channel_create" style=
"<?if ($value != "add
"): ?>display:none;<? endif; ?>">
272 <tr
class=
"adm-detail-required-field">
273 <td
class=
"adm-detail-content-cell-l" width=
"40%"><?=
Loc::getMessage(
"V_CHANNEL_ID_TITLE")?></td>
274 <td
class=
"adm-detail-content-cell-r" width=
"60%"><input type=
"text" name=
"<?=$htmlControl["NAME
"]?>[CHANNEL_TITLE]" <?
275 ?>value=
"<?=htmlspecialcharsbx($entity["CHANNEL_TITLE
"]);?>" /></td>
277 <tr
class=
"adm-detail-required-field">
278 <td
class=
"adm-detail-content-cell-l"><?=
Loc::getMessage(
"V_CHANNEL_ID_SYMBOLIC_NAME")?></td>
279 <td
class=
"adm-detail-content-cell-r"><input type=
"text" name=
"<?=$htmlControl["NAME
"]?>[CHANNEL_SYMBOLIC_NAME]" <?
280 ?>value=
"<?=htmlspecialcharsbx($entity["CHANNEL_SYMBOLIC_NAME
"]);?>" /></td>
283 <td
class=
"adm-detail-content-cell-l"> </td>
284 <td
class=
"adm-detail-content-cell-r"><input type=
"checkbox" name=
"<?=$htmlControl["NAME
"]?>[CHANNEL_USE_CAPTCHA]" <?
285 ?>
id=
"CHANNEL_USE_CAPTCHA" <?
if ($entity[
"CHANNEL_USE_CAPTCHA"] ==
"Y"): ?> checked <? endif;
286 ?>value=
"Y" /> <label
for=
"CHANNEL_USE_CAPTCHA"><?=
Loc::getMessage(
"V_CHANNEL_ID_USE_CAPTCHA")?></label></td>
288 $dbRes = \CGroup::GetList(
"sort",
"asc", Array(
"ADMIN" =>
"N"));
289 while ($group = $dbRes->getNext())
292 $value = $entity[
"GROUP_ID"][$group[
"ID"]];
294 $value = ($group[
"ID"] == 2 ? 1 : ($group[
"ID"] == 1 ? 4 : 2));
297 <td
class=
"adm-detail-content-cell-l"><?=$group[
"NAME"].
":"?></td>
298 <td
class=
"adm-detail-content-cell-r"><?=SelectBoxFromArray(
"GROUP_ID[".$group[
"ID"].
"]", $aVotePermissions, $value);?></td>
307 $entity[
'UNIQUE'] = is_array($entity[
'UNIQUE']) ?
308 $entity[
'UNIQUE'] : array();
310 foreach ($entity[
'UNIQUE'] as $res)
316 if (is_array($userField) && array_key_exists(
"SETTINGS", $userField) && array_key_exists(
"UNIQUE", $userField[
"SETTINGS"]))
319 if (is_array($userField[
"SETTINGS"][
"UNIQUE"]))
321 foreach ( $userField[
"SETTINGS"][
"UNIQUE"] as $res)
326 $uniqType = intval($userField[
"SETTINGS"][
"UNIQUE"]);
335 <script language=
"javascript">
336 function __utch(show)
338 if (
BX(
"UNIQUE_TYPE_IP").checked)
339 BX.show(
BX(
"DELAY_TYPE"),
"");
341 BX.hide(
BX(
"DELAY_TYPE"));
344 show =
BX(
"UNIQUE_TYPE_USER_ID").checked,
345 res =
BX(
"UNIQUE_TYPE_USER_ID_NEW");
346 res.disabled = !show;
348 BX.show(res.parentNode.parentNode,
"");
350 BX.hide(res.parentNode.parentNode);
354 <td
class=
"adm-detail-content-cell-l adm-detail-valign-top" width=
"40%"><?=
Loc::getMessage(
"VOTE_NOTIFY")?></td>
355 <td
class=
"adm-detail-content-cell-r" width=
"60%"><?
356 $entity[
"NOTIFY"] = (
357 $entity[
"NOTIFY"] !=
"I" && $entity[
"NOTIFY"] !=
"Y" ?
358 "N" : $entity[
"NOTIFY"]);
359 if (IsModuleInstalled(
"im")): ?>
360 <?=InputType(
"radio", $htmlControl[
"NAME"].
"[NOTIFY]",
"I", $entity[
"NOTIFY"],
false,
Loc::getMessage(
"VOTE_NOTIFY_IM"))?><br /><?
362 $entity[
"NOTIFY"] = ($entity[
"NOTIFY"] ==
"I" ?
363 "N" : $entity[
"NOTIFY"]);
365 <?=InputType(
"radio", $htmlControl[
"NAME"].
"[NOTIFY]",
"Y", $entity[
"NOTIFY"],
false,
Loc::getMessage(
"VOTE_NOTIFY_EMAIL"))?><br />
366 <?=InputType(
"radio", $htmlControl[
"NAME"].
"[NOTIFY]",
"N", $entity[
"NOTIFY"],
false,
Loc::getMessage(
"VOTE_NOTIFY_N"))?><?
370 <td
class=
"adm-detail-content-cell-l adm-detail-valign-top"><?=
Loc::getMessage(
"V_UNIQUE")?></td>
371 <td
class=
"adm-detail-content-cell-r">
372 <?
if (IsModuleInstalled(
'statistic')): ?>
374 <label
for=
"UNIQUE_TYPE_SESSION"><?=
Loc::getMessage(
"V_UNIQUE_SESSION")?></label><br />
377 <label
for=
"UNIQUE_TYPE_COOKIE"><?=
Loc::getMessage(
"V_UNIQUE_COOKIE_ONLY")?></label><br />
378 <input type=
"checkbox" name=
"<?=$htmlControl["NAME
"]?>[UNIQUE][]" id=
"UNIQUE_TYPE_IP" onclick=
"__utch()" value=
"<?=\Bitrix\Vote\Vote\EventLimits::BY_IP?>" <?
380 <label
for=
"UNIQUE_TYPE_IP"><?=
Loc::getMessage(
"V_UNIQUE_IP_ONLY")?></label><br />
381 <input type=
"checkbox" name=
"<?=$htmlControl["NAME
"]?>[UNIQUE][]" id=
"UNIQUE_TYPE_USER_ID" onclick=
"__utch();" value=
"<?=(\Bitrix\Vote\Vote\EventLimits::BY_USER_AUTH|\Bitrix\Vote\Vote\EventLimits::BY_USER_ID)?>" <?
383 <label
for=
"UNIQUE_TYPE_USER_ID"><?=
Loc::getMessage(
"V_UNIQUE_USER_ID_ONLY")?></label><br />
387 <td
class=
"adm-detail-content-cell-l" width=
"40%"> </td>
388 <td
class=
"adm-detail-content-cell-r" width=
"60%"><input type=
"checkbox" name=
"<?=$htmlControl["NAME
"]?>[UNIQUE][]" id=
"UNIQUE_TYPE_USER_ID_NEW" value=
"16" <?
389 ?><?=($uniqType & 16)?
" checked ":
""?><?
390 ?><?=($uniqType & 8)?
"":
" disabled"?> /> <label
for=
"UNIQUE_TYPE_USER_ID_NEW"><?=
Loc::getMessage(
"V_UNIQUE_USER_ID_NEW")?></label>
395 $value = $entity[
"UNIQUE_IP_DELAY"];
397 $value = (is_array($userField) ?
398 $userField[
"SETTINGS"][
"UNIQUE_IP_DELAY"] :
399 array(
"DELAY" =>
"10",
"DELAY_TYPE" =>
"D"));
402 <td
class=
"adm-detail-content-cell-l" width=
"40%"><?=
Loc::getMessage(
"V_UNIQUE_IP_DELAY")?></td>
403 <td
class=
"adm-detail-content-cell-r" width=
"60%">
404 <input type=
"text" name=
"<?=$htmlControl["NAME
"]?>[UNIQUE_IP_DELAY][DELAY]" value=
"<?=htmlspecialcharsbx($value["DELAY
"]);?>" />
405 <?=SelectBoxFromArray(
406 $htmlControl[
"NAME"].
"[UNIQUE_IP_DELAY][DELAY_TYPE]",
408 "reference_id" => array(
"S",
"M",
"H",
"D"),
409 "reference" => array(
413 $value[
"DELAY_TYPE"]);?>
414 <script type=
"text/javascript">
416 if (!!document.forms.post_form.MULTIPLE)
417 BX.hide(document.forms.post_form.MULTIPLE.parentNode.parentNode);
425 return ob_get_clean();
437 "arUserField" => $userField,
438 "bVarsFromForm" => $bVarsFromForm
440 \Bitrix\Vote\UF\Manager::getInstance($userField)->showEdit($params, $value);
441 return ob_get_clean();
453 "arUserField" => $userField
458 \Bitrix\Vote\UF\Manager::getInstance($userField)->showView($params, $result);
459 return ob_get_clean();
479 $returnUrl = $APPLICATION->GetCurPageParam(
"", array(
"admin_history",
"mode",
"table_id"));
481 if($htmlControl[
"VALUE"] > 0)
483 $dbRes = \CVote::GetByIDEx($htmlControl[
"VALUE"]);
484 if ($dbRes && ($vote = $dbRes->GetNext()))
486 if ($vote[
"LAMP"] ==
"yellow")
487 $vote[
"LAMP"] = ($vote[
"ID"] == \CVote::GetActiveVoteId($vote[
"CHANNEL_ID"]) ?
"green" :
"red");
488 $return =
"<div class=\"lamp-red\" title=\"".($vote[
"ACTIVE"] !=
'Y' ?
Loc::getMessage(
"VOTE_NOT_ACTIVE") :
Loc::getMessage(
"VOTE_ACTIVE_RED_LAMP")).
"\" style=\"display:inline-block;\"></div>";
489 if ($vote[
"LAMP"]==
"green")
490 $return =
"<div class=\"lamp-green\" title=\"".Loc::getMessage(
"VOTE_LAMP_ACTIVE").
"\" style=\"display:inline-block;\"></div>";
491 $return .=
" [<a href='vote_edit.php?lang=".LANGUAGE_ID.
"&ID=".$vote[
"ID"].
"&return_url=".urlencode($returnUrl).
"' title='".
Loc::getMessage(
"VOTE_EDIT_TITLE").
"'>".$vote[
"ID"].
"</a>] ";
492 $return .= $vote[
"TITLE"].(!empty($vote[
"DESCRIPTION"]) ?
" <i>(".$vote[
"DESCRIPTION"].
")</i>" :
"");
493 if ($vote[
"COUNTER"] > 0)
494 $return .=
Loc::getMessage(
"VOTE_VOTES").
" <a href=\"vote_user_votes_table.php?lang={LANGUAGE_ID}&VOTE_ID={$vote["ID
"]}\">".$vote[
"COUNTER"].
"</a>";
508 return '<input type="text" '.
509 'name="'.$htmlControl[
"NAME"].
'" '.
510 'size="'.$userField[
"SETTINGS"][
"SIZE"].
'" '.
511 'value="'.$htmlControl[
"VALUE"].
'" '.
532 public static function checkFields($userField, $value, $userId =
false)
534 if ($userField && is_array($userField[
"USER_TYPE"]) && $userField[
"USER_TYPE"][
"CLASS_NAME"] == __CLASS__)
536 $userId = self::getOrCheckUserId($userId);
539 global ${$userField[
"FIELD_NAME"] .
"_" . $value .
"_DATA"};
540 $data = ${$userField[
"FIELD_NAME"] .
"_" . $value .
"_DATA"} ?:
false;
541 if (!is_array($data) || empty($data))
550 $attach = ($type == self::TYPE_SAVED_ATTACH ? $userFieldManager->loadFromAttachId($realValue) :
551 ($data[
"ID"] > 0 ? $userFieldManager->loadFromVoteId($data[
"ID"]) : $userFieldManager->loadEmptyObject()));
555 $attach = $userFieldManager->loadEmptyObject();
559 if (isset($attach[
"ID"]))
561 if ($data[
"ID"] > 0 && $attach[
"VOTE_ID"] != $data[
"ID"])
563 throw new \Bitrix\Main\ArgumentException(
Loc::getMessage(
"VOTE_IS_NOT_EXPECTED"));
565 if (intval($data[
"ID"]) <= 0 && $attach->getStorage()->getId() !== $userField[
"SETTINGS"][
"CHANNEL_ID"])
567 $attach = $userFieldManager->loadEmptyObject();
571 if (!$userFieldManager->belongsToEntity($attach, $userField[
"ENTITY_ID"], $userField[
"ENTITY_VALUE_ID"] ??
null))
573 throw new \Bitrix\Main\ObjectNotFoundException(
Loc::getMessage(
"VOTE_IS_NOT_FOUND"));
576 $data[
"OPTIONS"] = isset($data[
"OPTIONS"]) ? (is_array($data[
"OPTIONS"]) ? array_sum($data[
"OPTIONS"]) : (int) $data[
"OPTIONS"]) : 0;
578 $interval = intval($userField[
"SETTINGS"][
"UNIQUE_IP_DELAY"][
"DELAY"]);
579 $interval = in_array($userField[
"SETTINGS"][
"UNIQUE_IP_DELAY"][
"DELAY_TYPE"], array(
"S",
"M",
"H")) ?
"PT".$interval.$userField[
"SETTINGS"][
"UNIQUE_IP_DELAY"][
"DELAY_TYPE"] :
"P".$interval.
"D";
580 $data[
"KEEP_IP_SEC"] = (new \DateTime(
"@0"))->add(
new \DateInterval($interval))->getTimestamp();
581 $data[
"NOTIFY"] = $userField[
"SETTINGS"][
"NOTIFY"];
583 $attach->checkData($data);
585 if (!isset($attach[
"ID"]) &&
586 $attach->getStorage()->getId() != $userField[
"SETTINGS"][
"CHANNEL_ID"] &&
587 !$attach->getStorage()->canEditVote($userId))
589 throw new \Bitrix\Main\AccessDeniedException(
Loc::getMessage(
"VOTE_EDIT_ACCESS_IS_DENIED"));
591 if (!$attach->canRead($userId))
593 throw new \Bitrix\Main\AccessDeniedException(
Loc::getMessage(
"VOTE_READ_ACCESS_IS_DENIED"));
595 if (!empty($data) && !$attach->canEdit($userId))
597 throw new \Bitrix\Main\AccessDeniedException(
Loc::getMessage(
"VOTE_EDIT_ACCESS_IS_DENIED"));
600 catch (\Exception $e)
602 return array(array(
"id" =>
"voteUserType" ,
"text" => $e->getMessage()));
624 public static function onBeforeSave($userField, $value, $userId =
false)
637 $userId = self::getOrCheckUserId($userId);
639 global ${$userField[
"FIELD_NAME"] .
"_" . $value .
"_DATA"};
640 $data = ${$userField[
"FIELD_NAME"] .
"_" . $value .
"_DATA"} ?:
false;
644 if ($type == self::TYPE_SAVED_ATTACH && (!is_array($data) || empty($data)))
649 if (!is_array($data) || empty($data))
655 if ($type == self::TYPE_SAVED_ATTACH)
657 $attach = $userFieldManager->loadFromAttachId($realValue);
659 if ($attach->getStorage()->getId() != $userField[
"SETTINGS"][
"CHANNEL_ID"] &&
660 $userFieldManager->belongsToEntity($attach, $userField[
"ENTITY_ID"], $userField[
"ENTITY_VALUE_ID"])
664 $attach = $userFieldManager->loadEmptyObject();
670 $attach = ($data[
"ID"] > 0 ? $userFieldManager->loadFromVoteId($data[
"ID"]) : $userFieldManager->loadEmptyObject());
675 $attach = $userFieldManager->loadEmptyObject();
679 $data[
"OPTIONS"] = !empty($data[
"OPTIONS"]) ? (is_array($data[
"OPTIONS"]) ? array_sum($data[
"OPTIONS"]) : (int) $data[
"OPTIONS"]) : 0;
680 $data[
"UNIQUE_TYPE"] = intval($userField[
"SETTINGS"][
"UNIQUE"] & \
Bitrix\
Vote\
Vote\EventLimits::BY_USER_AUTH ? $userField[
"SETTINGS"][
"UNIQUE"] | \
Bitrix\
Vote\
Vote\EventLimits::BY_USER_ID : $userField[
"SETTINGS"][
"UNIQUE"]);
681 $interval = intval($userField[
"SETTINGS"][
"UNIQUE_IP_DELAY"][
"DELAY"]);
682 $interval = in_array($userField[
"SETTINGS"][
"UNIQUE_IP_DELAY"][
"DELAY_TYPE"], array(
"S",
"M",
"H")) ?
"PT".$interval.$userField[
"SETTINGS"][
"UNIQUE_IP_DELAY"][
"DELAY_TYPE"] :
"P".$interval.
"D";
683 $data[
"KEEP_IP_SEC"] = (new \DateTime(
"@0"))->add(
new \DateInterval($interval))->getTimestamp();
684 $data[
"NOTIFY"] = $userField[
"SETTINGS"][
"NOTIFY"];
686 $attach->save($data, $userId);
688 return $attach->getAttachId();
690 catch (\Exception $e)
705 public static function onBeforeCopy(array $userField,
int $newEntityId, $attachedId, $implementer, $userId =
false)
707 if (empty($userField) || empty($attachedId))
712 $userId = self::getOrCheckUserId($userId);
715 $attachedObject = $userFieldManager->loadFromAttachId($attachedId);
718 if (is_callable([$implementer,
"copyVote"]))
720 $voteId = $implementer->copyVote($attachedObject->getVoteId());
726 $attachedId = AttachTable::add([
727 "MODULE_ID" => $attachedObject->getModuleId(),
728 "OBJECT_ID" => $voteId,
729 "ENTITY_ID" => $newEntityId,
730 "ENTITY_TYPE" => $attachedObject->getEntityType(),
731 "CREATED_BY" => $userId,
744 public static function onDelete($userField, $value)
751 $attach = ($type == self::TYPE_SAVED_ATTACH ? $userFieldManager->loadFromAttachId($realValue) :
752 ($realValue > 0 ? $userFieldManager->loadFromVoteId($realValue) : $userFieldManager->loadEmptyObject()));
755 if ($userFieldManager->belongsToEntity($attach, $userField[
'ENTITY_ID'], $userField[
'ENTITY_VALUE_ID']) && $attach->canEdit($USER->getId()))
767 if (mb_strpos($value, self::NEW_VOTE_PREFIX) === 0)
770 $value = intval(mb_substr($value, 1));
773 $value = intval($value);
775 $return = ($prefix == self::NEW_VOTE_PREFIX ? array(self::TYPE_NEW_ATTACH, $value) : array(self::TYPE_SAVED_ATTACH, $value));
780 private static function getOrCheckUserId($userId =
false)
782 if ($userId ===
false)
785 if ($USER instanceof \CUser)
787 return $USER->GetID();
790 return intval($userId);
static includeModule($moduleName)
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static getInstance(array $params)
static getUserTypeDescription()
static onBeforeSave($userField, $value, $userId=false)
static getSettingsHTML($userField, $htmlControl, $varsFromForm)
static detectType($value)
static getPublicViewHTML($userField, $value)
static checkFields($userField, $value, $userId=false)
static onSearchIndex($userField)
static getAdminListEditHTMLMulty($userField, $htmlControl)
static onBeforePostUserFieldUpdate($entityId, $ID, $fields)
static getAdminListEditHTML($userField, $htmlControl)
static onDelete($userField, $value)
static getDBColumnType($userField)
static getAdminListViewHTML($userField, $htmlControl)
static getEditFormHTML($userField, $value, $bVarsFromForm=false)
static prepareSettings($userField)
static onBeforeCopy(array $userField, int $newEntityId, $attachedId, $implementer, $userId=false)
static checkSettings(&$params)
$GLOBALS['____1444769544']