• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/internals/task/template/checklist.php
  • Класс: BitrixTasksInternalsTaskTemplateCheckListTable
  • Вызов: CheckListTable::updateForTemplate
static function updateForTemplate($templateId, $items = array())
{
	$templateId = 	Assert::expectIntegerPositive($templateId, '$templateId');
	$items = 		Assert::expectArray($items, '$items');

	$existed = array();
	$res = static::getList(array(
		'filter' => array('=TEMPLATE_ID' => $templateId),
		'select' => array('ID')
	));
	while($item = $res->fetch())
	{
		$existed[$item['ID']] = true;
	}

	$results = array();
	foreach($items as $item)
	{
		$item = Assert::expectArray($item, '$items[]');
		$item['TEMPLATE_ID'] = $templateId;

		$item['TITLE'] = trim($item['TITLE']);
		/*
		if((string) $item['TITLE'] == '')
		{
			continue;
		}
		*/

		if(intval($item['ID']))
		{
			$id = $item['ID'];

			unset($item['ID']);
			unset($existed[$id]);

			$results[$id] = static::update($id, $item);
		}
		else
		{
			$addResult = static::add($item);
			if($addResult->isSuccess())
				$results[$addResult->getId()] = $addResult;
			else
				$results[] = $addResult;
		}
	}

	foreach($existed as $id => $flag)
	{
		$results[$id] = static::delete($id);
	}

	return $results;
}