• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/classes/general/taskitem.php
  • Класс: CTaskItem
  • Вызов: CTaskItem::proceedActionFavorite
private function proceedActionFavorite($arActionArguments)
{
	if(!is_array($arActionArguments))
		$arActionArguments = array();

	$addChildren = true;
	if(array_key_exists('AFFECT_CHILDREN', $arActionArguments))
	{
		$addChildren = $arActionArguments['AFFECT_CHILDREN'] == 'Y' || $arActionArguments['AFFECT_CHILDREN'] === true;
	}
	$tellSocnet = true;
	if(array_key_exists('TELL_SOCNET', $arActionArguments))
	{
		$tellSocnet = $arActionArguments['TELL_SOCNET'] == 'Y' || $arActionArguments['TELL_SOCNET'] === true;
	}

	$f = 'toggle';

	// ensure we have access to the task
	$this->checkCanReadThrowException();

	// drop cache
	$this->markCacheAsDirty();

	// here could be trouble: socnet doesn`t know anything aboult child tasks
	// in case of a ticket came, get all child tasks IDs here, pass ID list to BitrixTasksIntegrationSocialnetworkTask::toggleFavorites()
	// and also pass ID list as a cache to FavoriteTable::$f to avoid calling same query twice

	$res = FavoriteTable::$f(array(
		'TASK_ID' => $this->getId(),
		'USER_ID' => $this->executiveUserId
	), array(
		'AFFECT_CHILDREN' => $addChildren
	));

	if(!$res->isSuccess())
	{
		static::throwExceptionVerbose($res->getErrors());
	}

	$result = ($res instanceof BitrixMainEntityAddResult);
	$add = $result;

	foreach(GetModuleEvents('tasks', 'OnTaskToggleFavorite', true) as $arEvent)
	{
		ExecuteModuleEventEx($arEvent, array($this->getId(), $this->executiveUserId, $add));
	}

	if($tellSocnet)
	{
		BitrixTasksIntegrationSocialnetworkTask::toggleFavorites(array(
			'TASK_ID' => $this->getId(),
			'USER_ID' => $this->executiveUserId,
			'OPERATION' => $add ? 'ADD' : 'DELETE'
		));
	}

	return $result;
}