- Модуль: learning
- Путь к файлу: ~/bitrix/modules/learning/classes/general/attempt.php
- Класс: CAllTestAttempt
- Вызов: CAllTestAttempt::OnAttemptChange
static function OnAttemptChange($ATTEMPT_ID, $bCOMPLETED = false)
{
global $DB;
$ATTEMPT_ID = intval($ATTEMPT_ID);
if ($ATTEMPT_ID < 1)
return false;
$strSql = "SELECT A.*, T.APPROVED, T.COMPLETED_SCORE, T.COURSE_ID ".
"FROM b_learn_attempt A ".
"INNER JOIN b_learn_test T ON A.TEST_ID = T.ID ".
"WHERE A.ID = '".$ATTEMPT_ID."' AND A.STATUS = 'F' ";
$res = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
if (!$arAttempt = $res->Fetch())
return false;
$COMPLETED = "N";
if (
$arAttempt["APPROVED"] == "Y" &&
intval($arAttempt["COMPLETED_SCORE"])>0 &&
CTestAttempt::IsTestCompleted($ATTEMPT_ID,$arAttempt["COMPLETED_SCORE"])
)
$COMPLETED = "Y";
if ($bCOMPLETED)
$COMPLETED = "Y";
$strSql =
"UPDATE b_learn_attempt SET COMPLETED = '".$COMPLETED."' ".
"WHERE ID = '".$ATTEMPT_ID."'";
if (!$res = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__))
return false;
$strSql = "SELECT * FROM b_learn_gradebook WHERE STUDENT_ID='".$arAttempt["STUDENT_ID"]."' AND TEST_ID='".$arAttempt["TEST_ID"]."'";
$res = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
if (!$arGradeBook = $res->Fetch())
{
$arFields = Array(
"STUDENT_ID" => $arAttempt["STUDENT_ID"],
"TEST_ID" => $arAttempt["TEST_ID"],
"RESULT" => $arAttempt["SCORE"],
"MAX_RESULT" => intval($arAttempt["MAX_SCORE"]),
"COMPLETED" => $COMPLETED,
);
$at = new CGradeBook;
if (!$res = $at->Add($arFields))
return false;
CCertification::Certificate($arAttempt["STUDENT_ID"], $arAttempt["COURSE_ID"]);
}
else
{
$strSql =
"SELECT A.SCORE, A.MAX_SCORE FROM b_learn_attempt A ".
"WHERE A.STUDENT_ID = '".$arAttempt["STUDENT_ID"]."' AND A.TEST_ID = '".$arAttempt["TEST_ID"]."' ORDER BY COMPLETED DESC, SCORE DESC";
//AND A.COMPLETED = 'Y'
$res = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
if (!$arMaxScore = $res->Fetch())
return false;
if ($arGradeBook["COMPLETED"] == "Y")
$COMPLETED = "Y";
$strSql =
"UPDATE b_learn_gradebook SET RESULT = '".intval($arMaxScore["SCORE"])."', MAX_RESULT = '".intval($arMaxScore["MAX_SCORE"])."',COMPLETED = '".$COMPLETED."' ".
"WHERE ID = '".$arGradeBook["ID"]."'";
if (!$res = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__))
return false;
CCertification::Certificate($arAttempt["STUDENT_ID"], $arAttempt["COURSE_ID"]);
}
return true;
}