function CheckFields(&$arFields, $ID = false) { global $DB, $APPLICATION; if ($ID === false && !is_set($arFields, "STUDENT_ID")) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_USER_ID"), "EMPTY_STUDENT_ID"); return false; } elseif (is_set($arFields, "STUDENT_ID")) { $dbResult = CUser::GetByID($arFields["STUDENT_ID"]); if (!$dbResult->Fetch()) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_USER_ID_EX"), "ERROR_NO_STUDENT_ID"); return false; } } if ($ID === false && !is_set($arFields, "TEST_ID")) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_TEST_ID"), "EMPTY_TEST_ID"); return false; } elseif (is_set($arFields, "TEST_ID")) { $r = CTest::GetByID($arFields["TEST_ID"]); if (!$r->Fetch()) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_TEST_ID_EX"), "ERROR_NO_TEST_ID"); return false; } } if (is_set($arFields, "STUDENT_ID") && is_set($arFields, "TEST_ID")) { $res = CGradeBook::GetList(array(), array("STUDENT_ID" => $arFields["STUDENT_ID"], "TEST_ID" => $arFields["TEST_ID"])); if ($res->Fetch()) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_GRADEBOOK_DUPLICATE"), "ERROR_GRADEBOOK_DUPLICATE"); return false; } } if (is_set($arFields, "COMPLETED") && $arFields["COMPLETED"] != "Y") { $arFields["COMPLETED"] = "N"; } return true; }
function CheckFields(&$arFields, $ID = false) { global $DB; $arMsg = array(); if ((is_set($arFields, "MARK") || $ID === false) && strlen($arFields["MARK"]) <= 0) { $arMsg[] = array("id" => "MARK", "text" => GetMessage("LEARNING_BAD_MARK")); } if ($ID === false && !is_set($arFields, "TEST_ID") || is_set($arFields, "TEST_ID") && intval($arFields["TEST_ID"]) < 1) { $arMsg[] = array("id" => "TEST_ID", "text" => GetMessage("LEARNING_BAD_TEST_ID")); } elseif (is_set($arFields, "TEST_ID")) { $res = CTest::GetByID($arFields["TEST_ID"]); if (!($arRes = $res->Fetch())) { $arMsg[] = array("id" => "TEST_ID", "text" => GetMessage("LEARNING_BAD_TEST_ID")); } } if (!is_set($arFields, "SCORE") || intval($arFields["SCORE"]) > 100 || intval($arFields["SCORE"]) < 1) { $arMsg[] = array("id" => "SCORE", "text" => GetMessage("LEARNING_BAD_MARK_SCORE")); } if (!empty($arMsg)) { $e = new CAdminException($arMsg); $GLOBALS["APPLICATION"]->ThrowException($e); return false; } return true; }
protected function _MakeItems($TITLE, $TYPE, $RES_ID, $PARENT_ID) { global $APPLICATION; if ($PARENT_ID === 0) { $linkToParentLessonId = CCourse::CourseGetLinkedLesson($this->COURSE_ID); } else { $linkToParentLessonId = (int) $PARENT_ID; } $createUnilesson = false; if ($TYPE == "LES") { $arFields = array('NAME' => $TITLE); $createUnilesson = true; } elseif ($TYPE == "CHA") { $arFields = array('NAME' => $TITLE); $createUnilesson = true; } elseif ($TYPE == "QUE") { $arFields = array("NAME" => $TITLE, "LESSON_ID" => $linkToParentLessonId); $cl = new CLQuestion(); } elseif ($TYPE == "TES") { $arFields = array("NAME" => $TITLE, "COURSE_ID" => $this->COURSE_ID); $cl = new CTest(); } elseif ($TYPE === 'TMK') { $arFields = array(); $cl = new CLTestMark(); } else { return $PARENT_ID; } $r = new CDataXML(); if (!$r->Load($this->package_dir . "/" . strtolower($RES_ID) . ".xml")) { $r = false; } if ($r !== false) { if ($TYPE == "QUE") { if (($data = $r->SelectNodes("/questestinterop/item/presentation/")) && ($resp = $r->SelectNodes("/questestinterop/item/resprocessing/"))) { $arQ = array(); $arData = $data->__toArray(); $arResp = $resp->__toArray(); if (is_set($arData["#"]["material"][0]["#"], "mattext")) { $arQ["NAME"] = $arData["#"]["material"][0]["#"]["mattext"][0]["#"]; } if (is_set($arData["#"]["material"][0]["#"], "matimage")) { $imageDescription = ''; if (is_set($arData["#"]["material"][0]["#"], 'image_description')) { $imageDescription = $arData["#"]["material"][0]["#"]['image_description'][0]['#']; } $arQ["FILE_ID"] = array("MODULE_ID" => "learning", "name" => basename($arData["#"]["material"][0]["#"]["matimage"][0]["@"]["uri"]), "tmp_name" => $this->package_dir . "/" . $arData["#"]["material"][0]["#"]["matimage"][0]["@"]["uri"], "size" => @filesize($this->package_dir . "/" . $arData["#"]["material"][0]["#"]["matimage"][0]["@"]["uri"]), "type" => $arData["#"]["material"][0]["#"]["matimage"][0]["@"]["imagtype"], 'description' => $imageDescription); } if (is_set($arData["#"]["response_lid"][0]["@"], "rcardinality")) { switch ($arData["#"]["response_lid"][0]["@"]["rcardinality"]) { case "Multiple": $arQ["QUESTION_TYPE"] = 'M'; break; case "Text": $arQ["QUESTION_TYPE"] = 'T'; break; case "Sort": $arQ["QUESTION_TYPE"] = 'R'; break; default: $arQ["QUESTION_TYPE"] = 'S'; break; } } if (is_set($arResp["#"]["respcondition"][0]["#"], "setvar")) { $arQ["POINT"] = $arResp["#"]["respcondition"][0]["#"]["setvar"][0]['#']; } //Additional if ($bx = $r->SelectNodes("/questestinterop/item/bitrix/")) { $arQ = array_merge($arQ, $this->_MakeFields($bx->__toArray(), $TYPE)); unset($bx); } $arFields = array_merge($arFields, $arQ); $cl = new CLQuestion(); $ID = $cl->Add($arFields); if ($ID > 0) { $PARENT_ID = $ID; $arCorrect = array(); if (is_set($arResp["#"]["respcondition"][0]["#"], "conditionvar") && is_set($arResp["#"]["respcondition"][0]["#"]["conditionvar"][0]["#"], "varequal")) { foreach ($arResp["#"]["respcondition"][0]["#"]["conditionvar"][0]["#"]["varequal"] as $ar) { $arCorrect[] = $ar["#"]; } } if (is_set($arData["#"]["response_lid"][0]["#"], "render_choice") && is_set($arData["#"]["response_lid"][0]["#"]["render_choice"][0]["#"], "response_label")) { $i = 0; foreach ($arData["#"]["response_lid"][0]["#"]["render_choice"][0]["#"]["response_label"] as $ar) { $i += 10; $cl = new CLAnswer(); $arFields = array("QUESTION_ID" => $PARENT_ID, "SORT" => $i, "CORRECT" => in_array($ar["@"]["ident"], $arCorrect) ? "Y" : "N", "ANSWER" => $ar["#"]["material"][0]["#"]["mattext"][0]["#"]); $AswerID = $cl->Add($arFields); $res = $AswerID > 0; if (!$res) { if ($e = $APPLICATION->GetException()) { $this->arWarnings[$TYPE][] = array("TITLE" => $TITLE, "TEXT" => $e->GetString()); } } } } } else { if ($e = $APPLICATION->GetException()) { $this->arWarnings[$TYPE][] = array("TITLE" => $TITLE, "TEXT" => $e->GetString()); } } unset($cl); unset($data); unset($arQ); unset($resp); unset($arData); unset($arResp); return $PARENT_ID; } } else { if ($data = $r->SelectNodes("/content/")) { $ar = $data->__toArray(); $arFields = array_merge($arFields, $this->_MakeFields($ar, $TYPE)); if ($TYPE === 'TMK') { $arFields['TEST_ID'] = (int) $PARENT_ID; } if (is_set($arFields, "COMPLETED_SCORE") && intval($arFields["COMPLETED_SCORE"]) <= 0) { unset($arFields["COMPLETED_SCORE"]); } if (is_set($arFields, "PREVIOUS_TEST_ID") && intval($arFields["PREVIOUS_TEST_ID"]) <= 0 || !CTest::GetByID($arFields["PREVIOUS_TEST_ID"])->Fetch()) { unset($arFields["PREVIOUS_TEST_ID"], $arFields["PREVIOUS_TEST_SCORE"]); } } } } if ($createUnilesson === false) { $ID = $cl->Add($arFields); unset($cl); } else { $bProhibitPublish = false; // properties (in context of parent) by default $arProperties = array('SORT' => 500); // Lesson's sort order in context of parent if (isset($arFields['EDGE_SORT'])) { $arFields['SORT'] = (int) $arFields['EDGE_SORT']; unset($arFields['EDGE_SORT']); } if (isset($arFields['SORT'])) { $arProperties['SORT'] = (int) $arFields['SORT']; // Lessons doesn't have more SORT field unset($arFields['SORT']); } if (isset($arFields['META_PUBLISH_PROHIBITED'])) { if ($arFields['META_PUBLISH_PROHIBITED'] === 'Y') { $bProhibitPublish = true; } unset($arFields['META_PUBLISH_PROHIBITED']); } // unset fields, that are absent in unilesson $arUnilessonFields = $arFields; $arFieldsNames = array_keys($arUnilessonFields); foreach ($arFieldsNames as $fieldName) { if (!in_array(strtoupper($fieldName), $this->arLessonWritableFields)) { unset($arUnilessonFields[$fieldName]); } } $ID = CLearnLesson::Add($arUnilessonFields, false, $linkToParentLessonId, $arProperties); if ($bProhibitPublish && $ID > 0) { CLearnLesson::PublishProhibitionSetTo($ID, $linkToParentLessonId, $bProhibitPublish); } } if ($ID > 0) { return $ID; } else { if ($e = $APPLICATION->GetException()) { $this->arWarnings[$TYPE][] = array("TITLE" => $TITLE, "TEXT" => $e->GetString()); } } }
protected static function _CreateAttemptQuestions($arCallbackSqlFormer, $ATTEMPT_ID) { global $APPLICATION, $DB, $DBType; $ATTEMPT_ID = intval($ATTEMPT_ID); $attempt = CTestAttempt::GetByID($ATTEMPT_ID); if (!($arAttempt = $attempt->Fetch())) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_ATTEMPT_ID_EX"), "ERROR_NO_ATTEMPT_ID"); return false; } $test = CTest::GetByID($arAttempt["TEST_ID"]); if (!($arTest = $test->Fetch())) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_TEST_ID_EX"), "ERROR_NO_TEST_ID"); return false; } $strSql = "DELETE FROM b_learn_test_result WHERE ATTEMPT_ID = " . $ATTEMPT_ID; if (!$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__)) { return false; } /** * QUESTIONS_FROM values: * 'L' - X questions from every lesson in course * 'C' - X questions from every lesson from every chapter in the course * In this case questions taken from immediate lessons of all chapters (X per chapter) in the course. * In new data model it means, get X questions from every lesson in the course, except * 1) immediate lessons-childs of the course and * 2) lessons, contains other lessons (because, in old data model chapters doesn't contains questions) * * 'H' - all questions from the selected chapter (recursive) in the course * This case must be ignored, because converter to new data model updates 'H' to 'R', but in case * when chapter is not exists updates didn't become. So QUESTIONS_FROM stayed in 'H' value. And it means, * that there is no chapter exists with QUESTIONS_FROM_ID, so we can't do work. And we should just * ignore, for backward compatibility (so, don't throw an error). * 'S' - all questions from the selected lesson (unilesson_id in QUESTIONS_FROM_ID) * 'A' - all questions of the course (nothing interesting in QUESTIONS_FROM_ID) * * new values: * 'R' - all questions from the tree with root at selected lesson (include questions of selected lesson) * in the course (unilesson_id in QUESTIONS_FROM_ID) */ if ($arTest["QUESTIONS_FROM"] == "C" || $arTest["QUESTIONS_FROM"] == "L") { $courseId = $arTest['COURSE_ID'] + 0; $courseLessonId = CCourse::CourseGetLinkedLesson($courseId); if ($courseLessonId === false) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_TEST_IS_EMPTY"), "ERROR_TEST_IS_EMPTY"); return false; } $clauseAllChildsLessons = CLearnHelper::SQLClauseForAllSubLessons($courseLessonId); if ($arTest["QUESTIONS_FROM"] == "C") { $strSql = "SELECT Q.ID as QUESTION_ID, TLEUP.SOURCE_NODE as FROM_ID\n\t\t\t\tFROM b_learn_lesson L\n\t\t\t\tINNER JOIN b_learn_question Q ON L.ID = Q.LESSON_ID\n\t\t\t\tINNER JOIN b_learn_lesson_edges TLEUP ON L.ID = TLEUP.TARGET_NODE\n\t\t\t\tLEFT OUTER JOIN b_learn_lesson_edges TLEDOWN ON L.ID = TLEDOWN.SOURCE_NODE " . "WHERE L.ID IN (" . $clauseAllChildsLessons . ") \n" . " AND TLEDOWN.SOURCE_NODE IS NULL \n" . " AND TLEUP.SOURCE_NODE IN (" . $clauseAllChildsLessons . ") \n" . " AND Q.ACTIVE = 'Y' " . ($arTest["INCLUDE_SELF_TEST"] != "Y" ? "AND Q.SELF = 'N' " : "") . "ORDER BY " . ($arTest["RANDOM_QUESTIONS"] == "Y" ? CTest::GetRandFunction() : "L.SORT, Q.SORT"); } else { $strSql = "SELECT Q.ID as QUESTION_ID, L.ID as FROM_ID " . "FROM b_learn_lesson L " . "INNER JOIN b_learn_question Q ON L.ID = Q.LESSON_ID " . "WHERE L.ID IN (" . $clauseAllChildsLessons . ") AND Q.ACTIVE = 'Y' " . ($arTest["INCLUDE_SELF_TEST"] != "Y" ? "AND Q.SELF = 'N' " : "") . "ORDER BY " . ($arTest["RANDOM_QUESTIONS"] == "Y" ? CTest::GetRandFunction() : "L.SORT, Q.SORT"); } if (!($res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__))) { return false; } $Values = array(); $tmp = array(); while ($arRecord = $res->Fetch()) { if (is_set($tmp, $arRecord["FROM_ID"])) { if ($tmp[$arRecord["FROM_ID"]] < $arTest["QUESTIONS_AMOUNT"]) { $tmp[$arRecord["FROM_ID"]]++; } else { continue; } } else { $tmp[$arRecord["FROM_ID"]] = 1; } $Values[] = $arRecord["QUESTION_ID"]; } if (empty($Values)) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_TEST_IS_EMPTY"), "ERROR_TEST_IS_EMPTY"); return false; } $DB->StartTransaction(); foreach ($Values as $ID) { $strSql = "INSERT INTO b_learn_test_result (ATTEMPT_ID, QUESTION_ID) VALUES (" . $ATTEMPT_ID . "," . $ID . ")"; if (!$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__)) { $DB->Rollback(); return false; } } $DB->Commit(); } elseif (($arTest["QUESTIONS_FROM"] == "H" || $arTest["QUESTIONS_FROM"] == "S" || $arTest["QUESTIONS_FROM"] == "R") && $arTest["QUESTIONS_FROM_ID"]) { $WHERE = ''; if ($arTest["QUESTIONS_FROM"] == "H") { /** * 'H' - all questions from the selected chapter (recursive) in the course * This case must be ignored, because converter to new data model updates 'H' to 'R', but in case * when chapter is not exists updates didn't become. So QUESTIONS_FROM stayed in 'H' value. And it means, * that there is no chapter exists with QUESTIONS_FROM_ID, so we can't do work. And we should just * ignore, for backward compatibility (so, don't throw an error). */ $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_TEST_IS_EMPTY"), "ERROR_TEST_IS_EMPTY"); return false; } elseif ($arTest["QUESTIONS_FROM"] == 'R') { $clauseAllChildsLessons = CLearnHelper::SQLClauseForAllSubLessons($arTest['QUESTIONS_FROM_ID']); $WHERE = " (L.ID IN(" . $clauseAllChildsLessons . ") OR (L.ID = " . ($arTest['QUESTIONS_FROM_ID'] + 0) . ")) "; } elseif ($arTest["QUESTIONS_FROM"] == 'S') { $clauseAllChildsLessons = $arTest["QUESTIONS_FROM_ID"] + 0; $WHERE = " (L.ID IN(" . $clauseAllChildsLessons . ") OR (L.ID = " . ($arTest['QUESTIONS_FROM_ID'] + 0) . ")) "; } else { return false; } $strSql = "INSERT INTO b_learn_test_result (ATTEMPT_ID, QUESTION_ID) " . "SELECT " . $ATTEMPT_ID . " ,Q.ID " . "FROM b_learn_lesson L " . "INNER JOIN b_learn_question Q ON L.ID = Q.LESSON_ID " . "WHERE " . $WHERE . " AND Q.ACTIVE = 'Y' " . ($arTest["INCLUDE_SELF_TEST"] != "Y" ? "AND Q.SELF = 'N' " : "") . "ORDER BY " . ($arTest["RANDOM_QUESTIONS"] == "Y" ? CTest::GetRandFunction() : "Q.SORT ") . ($arTest["QUESTIONS_AMOUNT"] > 0 ? "LIMIT " . $arTest["QUESTIONS_AMOUNT"] : ""); //echo $strSql;exit; $q = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if (!$q || intval($q->AffectedRowsCount()) <= 0) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_TEST_IS_EMPTY"), "ERROR_TEST_IS_EMPTY"); return false; } } elseif ($arTest["QUESTIONS_FROM"] == 'A') { $courseId = $arTest['COURSE_ID'] + 0; $courseLessonId = CCourse::CourseGetLinkedLesson($courseId); if ($courseLessonId === false) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_TEST_IS_EMPTY"), "ERROR_TEST_IS_EMPTY"); return false; } $clauseAllChildsLessons = CLearnHelper::SQLClauseForAllSubLessons($courseLessonId); $strSql = call_user_func($arCallbackSqlFormer, $ATTEMPT_ID, $arTest, $clauseAllChildsLessons, $courseLessonId); //echo $strSql; exit; $q = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if (!$q || intval($q->AffectedRowsCount()) <= 0) { $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_TEST_IS_EMPTY"), "ERROR_TEST_IS_EMPTY"); return false; } } else { return false; } $strSql = "UPDATE b_learn_attempt SET QUESTIONS = '" . CTestResult::GetCount($ATTEMPT_ID) . "' WHERE ID = " . $ATTEMPT_ID; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); return true; }
$str_PASSAGE_TYPE = "0"; $str_PREVIOUS_TEST_ID = "0"; $str_PREVIOUS_TEST_SCORE = "95"; $str_INCORRECT_CONTROL = "N"; $str_CURRENT_INDICATION_PERCENT = "N"; $str_CURRENT_INDICATION_MARK = "N"; $str_CURRENT_INDICATION = "N"; $str_FINAL_INDICATION_CORRECT_COUNT = "N"; $str_FINAL_INDICATION_SCORE = "N"; $str_FINAL_INDICATION_MARK = "N"; $str_FINAL_INDICATION_MESSAGE = "N"; $str_FINAL_INDICATION = "N"; $str_SHOW_ERRORS = "N"; $str_NEXT_QUESTION_ON_ERROR = "Y"; $test = new CTest(); $res = $test->GetByID($ID); if (!$res->ExtractFields("str_")) { $ID = 0; } else { if ($str_CURRENT_INDICATION > 0) { $str_CURRENT_INDICATION_PERCENT = $str_CURRENT_INDICATION & 1 ? "Y" : "N"; $str_CURRENT_INDICATION_MARK = ($str_CURRENT_INDICATION & 2) >> 1 ? "Y" : "N"; $str_CURRENT_INDICATION = "Y"; } if ($str_FINAL_INDICATION > 0) { $str_FINAL_INDICATION_CORRECT_COUNT = $str_FINAL_INDICATION & 1 ? "Y" : "N"; $str_FINAL_INDICATION_SCORE = ($str_FINAL_INDICATION & 2) >> 1 ? "Y" : "N"; $str_FINAL_INDICATION_MARK = ($str_FINAL_INDICATION & 4) >> 2 ? "Y" : "N"; $str_FINAL_INDICATION_MESSAGE = ($str_FINAL_INDICATION & 8) >> 3 ? "Y" : "N"; $str_FINAL_INDICATION = "Y"; }
//Set Title $arParams["SET_TITLE"] = $arParams["SET_TITLE"] == "N" ? "N" : "Y"; if ($arParams["SET_TITLE"] == "Y") { $APPLICATION->SetTitle(GetMessage("LEARNING_PROFILE_TITLE")); } $currentPage = GetPagePath(false, false); $queryString = htmlspecialcharsbx(DeleteParam(array($arParams["TEST_ID_VARIABLE"]))); $arResult = array("RECORDS" => array(), "ATTEMPTS" => array(), "CURRENT_PAGE" => $currentPage . ($queryString == "" ? "" : "?") . $queryString); //GradeBook $rsGradebook = CGradeBook::GetList(array("ID" => "DESC"), array("STUDENT_ID" => intval($USER->GetID()), "SITE_ID" => LANG, "TEST_ID" => array_key_exists($arParams["TEST_ID_VARIABLE"], $_REQUEST) ? intval($_REQUEST[$arParams["TEST_ID_VARIABLE"]]) : "")); // Collection of tests' ids $arTestsIds = array(); while ($arGradebook = $rsGradebook->GetNext()) { //Test Url $arGradebook["TEST_DETAIL_URL"] = CComponentEngine::MakePathFromTemplate($arParams["TEST_DETAIL_TEMPLATE"], array("TEST_ID" => $arGradebook["TEST_ID"], "COURSE_ID" => $arGradebook["COURSE_ID"])); $rsTest = CTest::GetByID($arGradebook["TEST_ID"]); $arTest = $rsTest->Fetch(); $arGradebook['APPROVED'] = $arTest['APPROVED']; //Course Url $arGradebook["COURSE_DETAIL_URL"] = CComponentEngine::MakePathFromTemplate($arParams["COURSE_DETAIL_TEMPLATE"], array("COURSE_ID" => $arGradebook["COURSE_ID"])); $arGradebook["ATTEMPT_DETAIL_URL"] = $arResult["CURRENT_PAGE"] . ($queryString == "" ? "?" : "&") . $arParams["TEST_ID_VARIABLE"] . "=" . $arGradebook["TEST_ID"]; $arResult["RECORDS"][] = $arGradebook; // collect tests' ids if (!in_array($arGradebook['TEST_ID'], $arTestsIds)) { $arTestsIds[] = $arGradebook['TEST_ID']; } } // Add info about last tests' attempts for each test $arResult['LAST_TEST_INFO'] = array(); foreach ($arTestsIds as $key => $testId) { $arAttempt = false;
function CheckFields(&$arFields, $ID = false) { global $DB; $arMsg = array(); if ((is_set($arFields, "NAME") || $ID === false) && strlen($arFields["NAME"]) <= 0) { $arMsg[] = array("id" => "NAME", "text" => GetMessage("LEARNING_BAD_NAME")); } if ($ID === false && !is_set($arFields, "COURSE_ID")) { $arMsg[] = array("id" => "COURSE_ID", "text" => GetMessage("LEARNING_BAD_COURSE_ID")); } if (is_set($arFields, "COURSE_ID")) { $r = CCourse::GetByID($arFields["COURSE_ID"]); if (!$r->Fetch()) { $arMsg[] = array("id" => "COURSE_ID", "text" => GetMessage("LEARNING_BAD_COURSE_ID_EX")); } } if ($arFields["APPROVED"] == "Y" && is_set($arFields, "COMPLETED_SCORE") && (intval($arFields["COMPLETED_SCORE"]) <= 0 || intval($arFields["COMPLETED_SCORE"]) > 100)) { $arMsg[] = array("id" => "COMPLETED_SCORE", "text" => GetMessage("LEARNING_BAD_COMPLETED_SCORE")); } if (is_set($arFields, "PREVIOUS_TEST_ID") && intval($arFields["PREVIOUS_TEST_ID"]) != 0) { $r = CTest::GetByID($arFields["PREVIOUS_TEST_ID"]); if (!$r->Fetch()) { $arMsg[] = array("id" => "PREVIOUS_TEST_ID", "text" => GetMessage("LEARNING_BAD_PREVIOUS_TEST")); } } if (is_set($arFields, "PREVIOUS_TEST_SCORE") && (intval($arFields["PREVIOUS_TEST_SCORE"]) <= 0 || intval($arFields["PREVIOUS_TEST_SCORE"]) > 100) && intval($arFields["PREVIOUS_TEST_ID"]) != 0) { $arMsg[] = array("id" => "PREVIOUS_TEST_SCORE", "text" => GetMessage("LEARNING_BAD_COMPLETED_SCORE")); } if (!empty($arMsg)) { $e = new CAdminException($arMsg); $GLOBALS["APPLICATION"]->ThrowException($e); return false; } //Defaults if (is_set($arFields, "QUESTIONS_FROM") && !in_array($arFields["QUESTIONS_FROM"], array("A", "C", "L", "H", "S", 'R'))) { $arFields["QUESTIONS_FROM"] = "A"; } if (is_set($arFields, "QUESTIONS_AMOUNT") && intval($arFields["QUESTIONS_AMOUNT"]) <= 0) { $arFields["QUESTIONS_AMOUNT"] = "0"; } if (is_set($arFields, "QUESTIONS_FROM_ID") && intval($arFields["QUESTIONS_FROM_ID"]) <= 0) { $arFields["QUESTIONS_FROM_ID"] = "0"; } if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") { $arFields["ACTIVE"] = "N"; } if (is_set($arFields, "APPROVED") && $arFields["APPROVED"] != "Y") { $arFields["APPROVED"] = "N"; } if ($arFields["APPROVED"] == "N") { $arFields["COMPLETED_SCORE"] = ""; } if (is_set($arFields, "INCLUDE_SELF_TEST") && $arFields["INCLUDE_SELF_TEST"] != "Y") { $arFields["INCLUDE_SELF_TEST"] = "N"; } if (is_set($arFields, "RANDOM_QUESTIONS") && $arFields["RANDOM_QUESTIONS"] != "Y") { $arFields["RANDOM_QUESTIONS"] = "N"; } if (is_set($arFields, "RANDOM_ANSWERS") && $arFields["RANDOM_ANSWERS"] != "Y") { $arFields["RANDOM_ANSWERS"] = "N"; } if (is_set($arFields, "DESCRIPTION_TYPE") && $arFields["DESCRIPTION_TYPE"] != "html") { $arFields["DESCRIPTION_TYPE"] = "text"; } if (is_set($arFields, "PASSAGE_TYPE") && !in_array($arFields["PASSAGE_TYPE"], array("0", "1", "2"))) { $arFields["PASSAGE_TYPE"] = "0"; } if (is_set($arFields, "INCORRECT_CONTROL") && $arFields["INCORRECT_CONTROL"] != "Y") { $arFields["INCORRECT_CONTROL"] = "N"; } if (is_set($arFields, "SHOW_ERRORS") && $arFields["SHOW_ERRORS"] != "Y") { $arFields["SHOW_ERRORS"] = "N"; $arFields["NEXT_QUESTION_ON_ERROR"] = "Y"; } if (is_set($arFields, "NEXT_QUESTION_ON_ERROR") && $arFields["NEXT_QUESTION_ON_ERROR"] != "Y") { $arFields["NEXT_QUESTION_ON_ERROR"] = "N"; } return true; }