• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/item/task.php
  • Класс: BitrixTasksItemTask
  • Вызов: Task::prepareData
public function prepareData($result)
{
	if(parent::prepareData($result))
	{
		$id = $this->getId();
		$now = $this->getContext()->getNow();

		if(!$this->isFieldModified('CHANGED_DATE'))
		{
			$this['CHANGED_DATE'] = $now;
		}

		// move 0 to null in PARENT_ID to avoid constraint and query problems
		// todo: move PARENT_ID, GROUP_ID and other "foreign keys" to the unique way of keeping absence of relation: null, 0 or ''
		//			if($this->isFieldModified('PARENT_ID'))
		//			{
		//				$parentId = intval($this['PARENT_ID']);
		//				if(!intval($parentId))
		//				{
		//					$this['PARENT_ID'] = false;
		//				}
		//			} // i dont know why

		if(!$id)
		{
			if(!$this->isFieldModified('SITE_ID'))
			{
				$this['SITE_ID'] = $this->getContext()->getSiteId();
			}
			if(!$this->isFieldModified('RESPONSIBLE_ID'))
			{
				$this['RESPONSIBLE_ID'] = $this->getUserId();
			}
			if(!$this->isFieldModified('CREATED_BY'))
			{
				$this['CREATED_BY'] = $this->getUserId();
			}
			if(!$this->isFieldModified('GUID'))
			{
				$this['GUID'] = Util::generateUUID();
			}
			if(!$this->isFieldModified('OUTLOOK_VERSION'))
			{
				$this['OUTLOOK_VERSION'] = 1;
			}

			// force GROUP_ID to 0 if not set (prevent occur as NULL in database)
			$this['GROUP_ID'] = intval($this['GROUP_ID']);

			if(!$this->isFieldModified('CHANGED_BY'))
			{
				$this['CHANGED_BY'] = $this['CREATED_BY'];
			}
			if(!$this->isFieldModified('STATUS_CHANGED_BY'))
			{
				$this['STATUS_CHANGED_BY'] = $this['CHANGED_BY'];
			}

			if(!$this->isFieldModified('CREATED_DATE')) // created date was not set manually
			{
				$this['CREATED_DATE'] = $now;
			}
			if(!$this->isFieldModified('STATUS_CHANGED_DATE'))
			{
				$this['STATUS_CHANGED_DATE'] = $now;
			}
			if(!$this->isFieldModified('ACTIVITY_DATE'))
			{
				$this['ACTIVITY_DATE'] = $now;
			}

			if($this->isFieldModified('DESCRIPTION_IN_BBCODE') && $this['DESCRIPTION_IN_BBCODE'] != 'Y')
			{
				$result->addError('ILLEGAL_DESCRIPTION', 'Tasks with HTML description are not allowed');
			}

			// todo: move scheduler out of here, to the process manager
			$this->processSchedulerBefore();
		}
		else
		{
			// todo
		}
	}

	return $result->isSuccess();
}