Wait::checkFields

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Wait
  4. checkFields
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/wait.php
  • Класс: Bitrix\Crm\Activity\Provider\Wait
  • Вызов: Wait::checkFields
static function checkFields($action, &$fields, $id, $params = null)
{
	$result = new Main\Result();

	$bindings = isset($fields['BINDINGS']) && is_array($fields['BINDINGS'])
		? $fields['BINDINGS'] : array();
	if(!empty($bindings))
	{
		foreach($bindings as $binding)
		{
			$ownerTypeID = isset($binding['OWNER_TYPE_ID']) ? (int)$binding['OWNER_TYPE_ID'] : 0;
			$ownerID = isset($binding['OWNER_ID']) ? (int)$binding['OWNER_ID'] : 0;

			$query = new Query(ActivityTable::getEntity());
			$query->addSelect('ID');
			$query->addFilter('=IS_HANDLEABLE', 'Y');
			$query->setLimit(1);

			$query->registerRuntimeField(
				'',
				new ReferenceField('B',
					ActivityBindingTable::getEntity(),
					array(
						'=ref.ACTIVITY_ID' => 'this.ID',
						'=ref.OWNER_ID' => new SqlExpression($ownerID),
						'=ref.OWNER_TYPE_ID' => new SqlExpression($ownerTypeID)
					),
					array('join_type' => 'INNER')
				)
			);

			$dbResult = $query->exec();
			if(is_array($dbResult->fetch()))
			{
				$result->addError(
					new Main\Error(Loc::getMessage('CRM_ACT_PROVIDER_WAIT_SCHEDULE_NOT_EMPTY_ERROR'))
				);
				return $result;
			}
		}
	}

	if (
		$action === self::ACTION_UPDATE
		&& isset($fields['COMPLETED'])
		&& $fields['COMPLETED'] === 'Y'
		&& isset($params['PREVIOUS_FIELDS'])
		&& empty($params['PREVIOUS_FIELDS']['END_TIME'])
	)
	{
		$end = new Main\Type\DateTime();
		$fields['END_TIME'] = $end->toString();
	}

	//Only END TIME can be taken for DEADLINE!
	if (isset($fields['END_TIME']) && $fields['END_TIME'] !== '')
	{
		$fields['DEADLINE'] = $fields['END_TIME'];
	}

	//Wait is not handleabele always.
	$fields['IS_HANDLEABLE'] = 'N';
	return $result;
}

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