• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/provider/templateprovider.php
  • Класс: BitrixTasksProviderTemplateProvider
  • Вызов: TemplateProvider::applyFilter
private function applyFilter()
{
	foreach ($this->arFilter as $key => $val)
	{
		$res = CTasks::MkOperationFilter($key);
		$key = $res["FIELD"];
		$cOperationType = $res["OPERATION"];

		$key = strtoupper($key);

		switch ($key)
		{
			case "CREATED_BY":
			case "TASK_ID":
			case "GROUP_ID":
			case "TPARAM_TYPE":
			case "ID":
				$this->arSqlSearch[] = CTasks::FilterCreate("TT.".$key, $val, "number", $bFullJoin, $cOperationType);
				break;

			case "RESPONSIBLE":
				$this->arSqlSearch[] = CTasks::FilterCreate("TT.RESPONSIBLE_ID", $val, "number", $bFullJoin, $cOperationType);
				break;

			case 'TAGS':
				if (!is_array($val))
				{
					$val = [$val];
				}
				global $DB;
				$tags = array_filter(
					array_map(
						function ($tag) use ($DB) {
							return ($tag ? $DB->ForSql($tag) : false);
						},
						$val
					)
				);
				$tagsCount = count($tags);
				if ($tagsCount)
				{
					$tags = "('" . implode("','", $tags) . "')";
					$this->arSqlSearch[] = trim("
						TT.ID IN (
							SELECT TTT.TEMPLATE_ID
							FROM (
								SELECT TEMPLATE_ID, COUNT(TEMPLATE_ID) AS CNT
								FROM b_tasks_template_tag
								WHERE NAME IN {$tags}
								GROUP BY TEMPLATE_ID
								HAVING CNT = {$tagsCount}
							) TTT
						)
					");
				}
				break;

			case "SCENARIO":
				$scenarios = !is_array($val) ? [$val] : $val;
				$filteredValue = [];
				foreach ($scenarios as $scenario)
				{
					if (ScenarioTable::isValidScenario($scenario))
					{
						$filteredValue[] = $scenario;
					}
				}
				$this->arSqlSearch[] = CTasks::FilterCreate("TS." . $key, $filteredValue, "string_equal", $bFullJoin);
				break;

			case "TITLE":
			case "ZOMBIE":
			case "XML_ID":
				$this->arSqlSearch[] = CTasks::FilterCreate("TT.".$key, $val, "string", $bFullJoin, $cOperationType);
				break;

			case "REPLICATE":
			case "PRIORITY":
				$this->arSqlSearch[] = CTasks::FilterCreate("TT.".$key, $val, "string_equal", $bFullJoin, $cOperationType);
				break;

			case 'SEARCH_INDEX':
				$fieldsToLike = array(
					"TT.TITLE",
					"TT.DESCRIPTION",
					"CONCAT_WS(' ', CU.NAME, CU.LAST_NAME, CU.SECOND_NAME, CU.LOGIN, RU.NAME, RU.LAST_NAME, RU.SECOND_NAME, RU.LOGIN)"
				);

				$filter = '(';
				$filter .= CTasks::FilterCreate("TT.ID", (int)$val, "number", $bFullJoin, $cOperationType);

				foreach ($fieldsToLike as $field)
				{
					$filter .= " OR ".CTasks::FilterCreate($field, $val, "string", $bFullJoin, "S");
				}
				$filter .= ')';

				$this->arSqlSearch[] = $filter;

				break;

			case "BASE_TEMPLATE_ID":

				$parentColumnName = DependencyTable::getPARENTIDColumnName();
				$columnName = DependencyTable::getIDColumnName();

				$val = (string) $val;
				if($val === '' || $val === '0')
				{
					$val = false;
				}

				$excludeSubtree = (
					isset($this->arParams['EXCLUDE_TEMPLATE_SUBTREE'])
					&& (
						$this->arParams['EXCLUDE_TEMPLATE_SUBTREE'] === true
						|| $this->arParams['EXCLUDE_TEMPLATE_SUBTREE'] === 'Y'
					)
				);

				if($excludeSubtree)
				{
					$this->arSqlSearch[] = "TT.ID NOT IN (SELECT " . $columnName . " FROM ". DependencyTable::getTableName() ." WHERE " . $parentColumnName . " = '" . intval($val) . "')";
				}
				else
				{
					$this->arSqlSearch[] = '('.($val ? "TD." . $parentColumnName . " = '".intval($val)."'" : "TD." . $parentColumnName . " = 0 OR TD." . $parentColumnName . " IS NULL").')';
				}

				break;
		}
	}
}