• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/internals/task/favorite.php
  • Класс: BitrixTasksInternalsTaskFavoriteTable
  • Вызов: FavoriteTable::add
static function add(array $data)
{
	// to avoid warnings in php7
	$behaviour = null;
	if (func_num_args() > 1)
	{
		$behaviour = func_get_arg(1);
	}

	if (!is_array($behaviour))
		$behaviour = array();
	if (!isset($behaviour['CHECK_EXISTENCE']))
		$behaviour['CHECK_EXISTENCE'] = true;
	if (!isset($behaviour['AFFECT_CHILDREN']))
		$behaviour['AFFECT_CHILDREN'] = false;

	$data = static::processPrimary($data);

	// already there, we dont want BitrixMainDBSqlQueryException "Duplicate entry" crumble everywhere
	if ($behaviour['CHECK_EXISTENCE'] && static::check($data))
	{
		$result = new BitrixMainEntityAddResult();
	}
	else
	{
		$result = parent::add($data);
	}

	if ($result->isSuccess() && $behaviour['AFFECT_CHILDREN'])
	{
		// add also all children...
		$res = TaskTable::getChildrenTasksData($data['TASK_ID'], array(
			'runtime' => TaskTable::getRuntimeFieldMixins(array('IN_FAVORITE'), array('USER_ID' => $data['USER_ID'])),
			'select' => array('IN_FAVORITE'),
		));
		while ($item = $res->fetch())
		{
			if (!$item['IN_FAVORITE'])
			{
				// our client
				static::add(array(
					'TASK_ID' => $item['ID']
				), array(
					'AFFECT_CHILDREN' => false,
					'CHECK_EXISTENCE' => false // list was already filtered by IN_FAVORITE, so no check is needed
				));
			}
		}
	}

	return $result;
}