VoteTable::modifyData

  1. Bitrix24 API (v. 23.675.0)
  2. vote
  3. VoteTable
  4. modifyData
  • Модуль: vote
  • Путь к файлу: ~/bitrix/modules/vote/lib/vote.php
  • Класс: BitrixVoteVoteTable
  • Вызов: VoteTable::modifyData
static function modifyData(BitrixMainORMEvent $event, BitrixMainORMEventResult $result)
{
	$data = array_merge($event->getParameter("fields"), $result->getModified());
	$fields = [];

	if (isset($data["UNIQUE_TYPE"]) && (
			!($data["UNIQUE_TYPE"] & BitrixVoteVoteEventLimits::BY_USER_AUTH) &&
			($data["UNIQUE_TYPE"] & BitrixVoteVoteEventLimits::BY_USER_DATE_REGISTER ||
				$data["UNIQUE_TYPE"] & BitrixVoteVoteEventLimits::BY_USER_ID)
		))
		$fields["UNIQUE_TYPE"] = $data["UNIQUE_TYPE"] | BitrixVoteVoteEventLimits::BY_USER_AUTH;

	foreach (["TIMESTAMP_X", "DATE_START", "DATE_END"] as $key)
	{
		if (isset($data[$key]) && !($data[$key] instanceof DateTime))
			$fields[$key] = DateTime::createFromUserTime($data[$key]);
	}

	//region check image
	if (array_key_exists("IMAGE_ID", $data))
	{
		if ($str = CFile::CheckImageFile($data["IMAGE_ID"]))
		{
			$result->addError(new FieldError(static::getEntity()->getField("IMAGE_ID"), $str));
		}
		else
		{
			$fields["IMAGE_ID"] = $data["IMAGE_ID"];
			$fields["IMAGE_ID"]["MODULE_ID"] = "vote";
			if ($id = $event->getParameter("id"))
			{
				$id = is_integer($id) ? $id : $id["ID"];
				if ($id > 0 && ($vote = VoteTable::getById($id)->fetch()) && ($vote["IMAGE_ID"] > 0))
				{
					$fields["IMAGE_ID"]["old_file"] = $vote["IMAGE_ID"];
				}
			}
			if (CFile::SaveForDB($fields, "IMAGE_ID", "") === false)
			{
				$result->unsetField("IMAGE_ID");
			}
		}
	}
	//endregion
	if (!empty($fields))
	{
		$result->modifyFields(array_merge($result->getModified(), $fields));
	}
	return $result;
}

Добавить комментарий