public static function GetList($arOrder = array(), $arFilter = array(), $arNavParams = array()) { global $DB, $USER; if (!is_array($arFilter)) { $arFilter = array(); } $oPermParser = new CLearnParsePermissionsFromFilter($arFilter); $arSqlSearch = CTest::GetFilter($arFilter); // Remove empty strings from array $arSqlSearch = array_filter($arSqlSearch); if ($oPermParser->IsNeedCheckPerm()) { $arSqlSearch[] = " C.LINKED_LESSON_ID IN (" . $oPermParser->SQLForAccessibleLessons() . ") "; } $strSqlSearch = ' '; if (!empty($arSqlSearch)) { $strSqlSearch = ' WHERE '; $strSqlSearch .= implode(' AND ', $arSqlSearch); } $strSqlFrom = "FROM b_learn_test LT " . "INNER JOIN b_learn_course C ON LT.COURSE_ID = C.ID " . $strSqlSearch; $strSql = "SELECT LT.ID, LT.COURSE_ID, LT.SORT, LT.ACTIVE, LT.NAME, \n\t\t\t\tLT.DESCRIPTION, LT.DESCRIPTION_TYPE, LT.ATTEMPT_LIMIT, \n\t\t\t\tLT.TIME_LIMIT, LT.COMPLETED_SCORE, LT.QUESTIONS_FROM, \n\t\t\t\tLT.QUESTIONS_FROM_ID, LT.QUESTIONS_AMOUNT, LT.RANDOM_QUESTIONS, \n\t\t\t\tLT.RANDOM_ANSWERS, LT.APPROVED, LT.INCLUDE_SELF_TEST, \n\t\t\t\tLT.PASSAGE_TYPE, LT.PREVIOUS_TEST_ID, LT.PREVIOUS_TEST_SCORE, \n\t\t\t\tLT.INCORRECT_CONTROL, LT.CURRENT_INDICATION, \n\t\t\t\tLT.FINAL_INDICATION, LT.MIN_TIME_BETWEEN_ATTEMPTS, \n\t\t\t\tLT.SHOW_ERRORS, LT.NEXT_QUESTION_ON_ERROR, " . $DB->DateToCharFunction("LT.TIMESTAMP_X") . " as TIMESTAMP_X " . $strSqlFrom; if (!is_array($arOrder)) { $arOrder = array(); } foreach ($arOrder as $by => $order) { $by = strtolower($by); $order = strtolower($order); if ($order != "asc") { $order = "desc"; } if ($by == "id") { $arSqlOrder[] = " LT.ID " . $order . " "; } elseif ($by == "name") { $arSqlOrder[] = " LT.NAME " . $order . " "; } elseif ($by == "active") { $arSqlOrder[] = " LT.ACTIVE " . $order . " "; } elseif ($by == "sort") { $arSqlOrder[] = " LT.SORT " . $order . " "; } else { $arSqlOrder[] = " LT.TIMESTAMP_X " . $order . " "; $by = "timestamp_x"; } } $strSqlOrder = ""; DelDuplicateSort($arSqlOrder); if (!empty($arSqlOrder)) { $strSqlOrder .= ' ORDER BY ' . implode(', ', $arSqlOrder) . ' '; } $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__ . "<br>Line: " . __LINE__); } else { $res_cnt = $DB->Query("SELECT COUNT(LT.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__ . "<br>Line: " . __LINE__); } return $res; }
function GetList($arOrder = array(), $arFilter = array()) { global $DB, $USER; if (!is_array($arFilter)) { $arFilter = array(); } $oPermParser = new CLearnParsePermissionsFromFilter($arFilter); $arSqlSearch = CTest::GetFilter($arFilter); $strSqlSearch = ""; for ($i = 0; $i < count($arSqlSearch); $i++) { if (strlen($arSqlSearch[$i]) > 0) { $strSqlSearch .= " AND " . $arSqlSearch[$i] . " "; } } $strSql = "SELECT DISTINCT T.*, " . $DB->DateToCharFunction("T.TIMESTAMP_X") . " as TIMESTAMP_X " . "FROM b_learn_test T " . "INNER JOIN b_learn_course C ON T.COURSE_ID = C.ID " . "WHERE 1=1 "; if ($oPermParser->IsNeedCheckPerm()) { $strSql .= " AND C.LINKED_LESSON_ID IN (" . $oPermParser->SQLForAccessibleLessons() . ") "; } $strSql .= $strSqlSearch; /* was: $bCheckPerm = ($APPLICATION->GetUserRight("learning") < "W" && !$USER->IsAdmin() && $arFilter["CHECK_PERMISSIONS"] != "N"); $userID = $USER->GetID() ? $USER->GetID() : 0; $strSql = "SELECT DISTINCT T.*, ". $DB->DateToCharFunction("T.TIMESTAMP_X")." as TIMESTAMP_X ". "FROM b_learn_test T ". "INNER JOIN b_learn_course C ON T.COURSE_ID = C.ID ". ($bCheckPerm ? "LEFT JOIN b_learn_course_permission CP ON CP.COURSE_ID = C.ID " : ""). "WHERE 1=1 ". ($bCheckPerm ? "AND CP.USER_GROUP_ID IN (".$USER->GetGroups().") ". "AND CP.PERMISSION >= '".(strlen($arFilter["MIN_PERMISSION"])==1 ? $arFilter["MIN_PERMISSION"] : "R")."' ". "AND (CP.PERMISSION='X' OR C.ACTIVE='Y') " :""). $strSqlSearch; */ if (!is_array($arOrder)) { $arOrder = array(); } foreach ($arOrder as $by => $order) { $by = strtolower($by); $order = strtolower($order); if ($order != "asc") { $order = "desc"; } if ($by == "id") { $arSqlOrder[] = " T.ID " . $order . " "; } elseif ($by == "name") { $arSqlOrder[] = " T.NAME " . $order . " "; } elseif ($by == "active") { $arSqlOrder[] = " T.ACTIVE " . $order . " "; } elseif ($by == "sort") { $arSqlOrder[] = " T.SORT " . $order . " "; } else { $arSqlOrder[] = " T.TIMESTAMP_X " . $order . " "; $by = "timestamp_x"; } } $strSqlOrder = ""; DelDuplicateSort($arSqlOrder); for ($i = 0; $i < count($arSqlOrder); $i++) { if ($i == 0) { $strSqlOrder = " ORDER BY "; } else { $strSqlOrder .= ","; } $strSqlOrder .= $arSqlOrder[$i]; } $strSql .= $strSqlOrder; //echo $strSql; return $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); }
/** * <p>Возвращает количество тестов по заданному фильтру.</p> * * * * * @param array $arrayarFilter = Array() Массив вида <i> array("фильтруемое поле"=>"значение фильтра" [, ...])</i>. * Описание фильтра см. в <a * href="http://dev.1c-bitrix.ru/api_help/learning/classes/ctest/getlist.php">CTest::GetList</a>.<br> По * умолчанию тесты не фильтруются. * * * * @return int <p>Число - количество тестов.</p> * * * <h4>Example</h4> * <pre> * <? * if (CModule::IncludeModule("learning")) * { * $COURSE_ID = 97; * * $cnt = CTest::GetCount(Array("ACTIVE" => "Y", "COURSE_ID" => $COURSE_ID)); * * echo "Number of tests: ".$cnt; * } * * ?> * * <? * if (CModule::IncludeModule("learning")) * { * $COURSE_ID = 97; * * $cnt = CTest::GetCount(Array("CHECK_PERMISSIONS" => "N", "COURSE_ID" => $COURSE_ID)); * * echo "Number of tests: ".$cnt; * } * * ?> * </pre> * * * * <h4>See Also</h4> * <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/learning/classes/ctest/index.php">CTest</a>::<a * href="http://dev.1c-bitrix.ru/api_help/learning/classes/ctest/getlist.php">GetList</a> </li> </ul><a * name="examples"></a> * * * @static * @link http://dev.1c-bitrix.ru/api_help/learning/classes/ctest/getcount.php * @author Bitrix */ public static function GetCount($arFilter = Array()) { global $DB, $USER, $APPLICATION; if (!is_array($arFilter)) $arFilter = Array(); $oPermParser = new CLearnParsePermissionsFromFilter ($arFilter); $arSqlSearch = CTest::GetFilter($arFilter); $strSqlSearch = ""; for($i=0; $i<count($arSqlSearch); $i++) if(strlen($arSqlSearch[$i])>0) $strSqlSearch .= " AND ".$arSqlSearch[$i]." "; $strSql = "SELECT COUNT(*) as CNT FROM b_learn_test T INNER JOIN b_learn_course C ON T.COURSE_ID = C.ID WHERE 1=1"; if ($oPermParser->IsNeedCheckPerm()) $strSql .= " AND C.LINKED_LESSON_ID IN (" . $oPermParser->SQLForAccessibleLessons() . ") "; $strSql .= $strSqlSearch; /* was: $strSql = "SELECT COUNT(*) as CNT ". "FROM b_learn_test T ". "INNER JOIN b_learn_course C ON T.COURSE_ID = C.ID ". ($bCheckPerm ? "LEFT JOIN b_learn_course_permission CP ON CP.COURSE_ID = C.ID " : ""). "WHERE 1=1 ". ($bCheckPerm ? "AND CP.USER_GROUP_ID IN (".$USER->GetGroups().") ". "AND CP.PERMISSION >= '".(strlen($arFilter["MIN_PERMISSION"])==1 ? $arFilter["MIN_PERMISSION"] : "R")."' ". "AND (CP.PERMISSION='X' OR C.ACTIVE='Y')" :""). $strSqlSearch; */ $res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($ar = $res->Fetch()) return intval($ar["CNT"]); else return 0; }