- Модуль: vote
- Путь к файлу: ~/bitrix/modules/vote/lib/uf/voteusertype.php
- Класс: BitrixVoteUfVoteUserType
- Вызов: VoteUserType::checkFields
static function checkFields($userField, $value, $userId = false)
{
if ($userField && is_array($userField["USER_TYPE"]) && $userField["USER_TYPE"]["CLASS_NAME"] == __CLASS__)
{
$userId = self::getOrCheckUserId($userId);
try
{
global ${$userField["FIELD_NAME"] . "_" . $value . "_DATA"};
$data = ${$userField["FIELD_NAME"] . "_" . $value . "_DATA"} ?: false;
if (!is_array($data) || empty($data))
return array();
$userFieldManager = Manager::getInstance($userField);
[$type, $realValue] = self::detectType($value);
try
{
$attach = ($type == self::TYPE_SAVED_ATTACH ? $userFieldManager->loadFromAttachId($realValue) :
($data["ID"] > 0 ? $userFieldManager->loadFromVoteId($data["ID"]) : $userFieldManager->loadEmptyObject()));
}
catch (BitrixMainObjectNotFoundException $exception)
{
$attach = $userFieldManager->loadEmptyObject();
unset($data["ID"]);
}
if (isset($attach["ID"]))
{
if ($data["ID"] > 0 && $attach["VOTE_ID"] != $data["ID"])
{
throw new BitrixMainArgumentException(Loc::getMessage("VOTE_IS_NOT_EXPECTED"));
}
if (intval($data["ID"]) <= 0 && $attach->getStorage()->getId() !== $userField["SETTINGS"]["CHANNEL_ID"])
{
$attach = $userFieldManager->loadEmptyObject();
}
}
if (!$userFieldManager->belongsToEntity($attach, $userField["ENTITY_ID"], $userField["ENTITY_VALUE_ID"] ?? null))
{
throw new BitrixMainObjectNotFoundException(Loc::getMessage("VOTE_IS_NOT_FOUND"));
}
$data["OPTIONS"] = isset($data["OPTIONS"]) ? (is_array($data["OPTIONS"]) ? array_sum($data["OPTIONS"]) : (int) $data["OPTIONS"]) : 0;
$data["UNIQUE_TYPE"] = ($userField["SETTINGS"]["UNIQUE"] & BitrixVoteVoteEventLimits::BY_USER_AUTH ? $userField["SETTINGS"]["UNIQUE"] | BitrixVoteVoteEventLimits::BY_USER_ID : $userField["SETTINGS"]["UNIQUE"]);
$interval = intval($userField["SETTINGS"]["UNIQUE_IP_DELAY"]["DELAY"]);
$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";
$data["KEEP_IP_SEC"] = (new DateTime("@0"))->add(new DateInterval($interval))->getTimestamp();
$data["NOTIFY"] = $userField["SETTINGS"]["NOTIFY"];
$attach->checkData($data);
if (!isset($attach["ID"]) &&
$attach->getStorage()->getId() != $userField["SETTINGS"]["CHANNEL_ID"] &&
!$attach->getStorage()->canEditVote($userId))
{
throw new BitrixMainAccessDeniedException(Loc::getMessage("VOTE_EDIT_ACCESS_IS_DENIED"));
}
if (!$attach->canRead($userId))
{
throw new BitrixMainAccessDeniedException(Loc::getMessage("VOTE_READ_ACCESS_IS_DENIED"));
}
if (!empty($data) && !$attach->canEdit($userId))
{
throw new BitrixMainAccessDeniedException(Loc::getMessage("VOTE_EDIT_ACCESS_IS_DENIED"));
}
}
catch (Exception $e)
{
return array(array("id" => "voteUserType" , "text" => $e->getMessage()));
}
}
return array();
}