• Модуль: learning
  • Путь к файлу: ~/bitrix/modules/learning/classes/general/question.php
  • Класс: CLQuestion
  • Вызов: CLQuestion::GetFilter
static function GetFilter($arFilter)
{
	if (!is_array($arFilter))
		$arFilter = Array();

	$arSqlSearch = Array();

	foreach ($arFilter as $key => $val)
	{
		$res = CLearnHelper::MkOperationFilter($key);
		$key = $res["FIELD"];
		$cOperationType = $res["OPERATION"];

		$key = mb_strtoupper($key);

		switch ($key)
		{
			case "ID":
			case "SORT":
			case "LESSON_ID":
			case "POINT":
				$arSqlSearch[] = CLearnHelper::FilterCreate("CQ.".$key, $val, "number", $bFullJoin, $cOperationType);
				break;

			case "COURSE_ID":
				// was:	$arSqlSearch[] = CLearnHelper::FilterCreate("C.".$key, $val, "number", $bFullJoin, $cOperationType);

				$courseLessonId = CCourse::CourseGetLinkedLesson ($val);
				if ($courseLessonId === false)
					break;	// it is not a course, so skipping

				// MySQL & MSSQL supports "WHERE IN(...)" clause for more than 10 000 elements

				// add to sql "WHERE" constraint: lessons id only from given array
				$sqlCourseLessonsIdsList = '';

				$oTree = CLearnLesson::GetTree($courseLessonId);
				$arChildLessonForCourse = $oTree->GetLessonsIdListInTree();

				// root lesson not in tree, so add it
				$arChildLessonForCourse[] = $courseLessonId;

				// We need escape data for SQL
				$arChildLessonForCourseEscaped = array_map('intval', $arChildLessonForCourse);

				$sqlCourseLessonsIdsList = implode (', ', $arChildLessonForCourseEscaped);

				if ($sqlCourseLessonsIdsList <> '')
					$arSqlSearch[] = 'CQ.LESSON_ID IN (' . $sqlCourseLessonsIdsList . ')';

				break;

			case "NAME":
				$arSqlSearch[] = CLearnHelper::FilterCreate("CQ.".$key, $val, "string", $bFullJoin, $cOperationType);
				break;

			case "QUESTION_TYPE":
			case "ACTIVE":
			case "SELF":
			case "CORRECT_REQUIRED":
				$arSqlSearch[] = CLearnHelper::FilterCreate("CQ.".$key, $val, "string_equal", $bFullJoin, $cOperationType);
				break;
		}

	}

	return $arSqlSearch;
}