- Модуль: learning
- Путь к файлу: ~/bitrix/modules/learning/classes/general/gradebook.php
- Класс: CAllGradeBook
- Вызов: CAllGradeBook::GetList
static function GetList($arOrder = array(), $arFilter = array(), $arNavParams = array())
{
global $DB;
$oPermParser = new CLearnParsePermissionsFromFilter ($arFilter);
$arSqlSearch = array_filter(CGradeBook::GetFilter($arFilter));
$strSqlSearch = '';
if ( ! empty($arSqlSearch) )
$strSqlSearch .= implode(' AND ', $arSqlSearch);
//Sites
$SqlSearchLang = "''";
if (array_key_exists("SITE_ID", $arFilter))
{
$arLID = Array();
if(is_array($arFilter["SITE_ID"]))
$arLID = $arFilter["SITE_ID"];
else
{
if ($arFilter["SITE_ID"] <> '')
$arLID[] = $arFilter["SITE_ID"];
}
foreach($arLID as $v)
$SqlSearchLang .= ", '".$DB->ForSql($v, 2)."'";
}
$strSqlFrom = static::__getSqlFromClause($SqlSearchLang);
if ($oPermParser->IsNeedCheckPerm())
$strSqlFrom .= " AND TUL.ID IN (" . $oPermParser->SQLForAccessibleLessons() . ") ";
if ($strSqlSearch !== '')
$strSqlFrom .= ' AND ' . $strSqlSearch;
$strSql =
"SELECT G.*, T.NAME as TEST_NAME, T.COURSE_ID as COURSE_ID,
T.APPROVED as TEST_APPROVED,
(T.ATTEMPT_LIMIT + G.EXTRA_ATTEMPTS) AS ATTEMPT_LIMIT, TUL.NAME as COURSE_NAME,
C.LINKED_LESSON_ID AS LINKED_LESSON_ID, ".
$DB->Concat("'('",'U.LOGIN',"') '","CASE WHEN U.NAME IS NULL THEN '' ELSE U.NAME END","' '", "CASE WHEN U.LAST_NAME IS NULL THEN '' ELSE U.LAST_NAME END")." as USER_NAME, U.ID as USER_ID ".
$strSqlFrom;
if (!is_array($arOrder))
$arOrder = array();
$arSqlOrder = [];
foreach($arOrder as $by=>$order)
{
$by = mb_strtolower($by);
$order = mb_strtolower($order);
if ($order!="asc")
$order = "desc";
if ($by == "id")
$arSqlOrder[] = " G.ID ".$order." ";
elseif ($by == "student_id")
$arSqlOrder[] = " G.STUDENT_ID ".$order." ";
elseif ($by == "test_id")
$arSqlOrder[] = " G.TEST_ID ".$order." ";
elseif ($by == "completed")
$arSqlOrder[] = " G.COMPLETED ".$order." ";
elseif ($by == "result")
$arSqlOrder[] = " G.RESULT ".$order." ";
elseif ($by == "max_result")
$arSqlOrder[] = " G.MAX_RESULT ".$order." ";
elseif ($by == "user_name")
$arSqlOrder[] = " USER_NAME ".$order." ";
elseif ($by == "test_name")
$arSqlOrder[] = " TEST_NAME ".$order." ";
else
$arSqlOrder[] = " G.ID ".$order." ";
}
$strSqlOrder = "";
DelDuplicateSort($arSqlOrder);
if (!empty($arSqlOrder))
{
for ($i=0, $len = count($arSqlOrder); $i < $len; $i++)
{
if($i==0)
$strSqlOrder = " ORDER BY ";
else
$strSqlOrder .= ",";
$strSqlOrder .= $arSqlOrder[$i];
}
}
$strSql .= $strSqlOrder;
if (is_array($arNavParams) && ( ! empty($arNavParams) ) )
{
if (isset($arNavParams['nTopCount']) && ((int) $arNavParams['nTopCount'] > 0))
{
$strSql = $DB->TopSql($strSql, (int) $arNavParams['nTopCount']);
$res = $DB->Query($strSql, false, "File: " . __FILE__ . "
Line: " . __LINE__);
}
else
{
$res_cnt = $DB->Query("SELECT COUNT(G.ID) as C " . $strSqlFrom);
$res_cnt = $res_cnt->fetch();
$res = new CDBResult();
$res->NavQuery($strSql, $res_cnt['C'], $arNavParams);
}
}
else
$res = $DB->Query($strSql, false, "File: " . __FILE__ . "
Line: " . __LINE__);
return $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
}