Example #1
0
 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__ . "<br>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__ . "<br>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__ . "<br>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__ . "<br>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__ . "<br>Line: " . __LINE__))) {
             return false;
         }
         CCertification::Certificate($arAttempt["STUDENT_ID"], $arAttempt["COURSE_ID"]);
     }
     return true;
 }
            continue;
        }
        $res = CGradeBook::GetByID($ID);
        if (!($ar = $res->Fetch())) {
            continue;
        }
        $DB->StartTransaction();
        $ID = IntVal($ID);
        $ob = new CGradeBook();
        if (!$ob->Update($ID, $arFields)) {
            if ($e = $APPLICATION->GetException()) {
                $lAdmin->AddUpdateError(GetMessage("SAVE_ERROR") . $ID . ": " . $e->GetString(), $ID);
                $DB->Rollback();
            }
        } else {
            CCertification::Certificate($ar["STUDENT_ID"], $ar["COURSE_ID"]);
        }
        $DB->Commit();
    }
}
// group and single actions processing
if ($arID = $lAdmin->GroupAction()) {
    if ($_REQUEST['action_target'] == 'selected') {
        $rsData = CGradeBook::GetList(array($by => $order), $arFilter);
        while ($arRes = $rsData->Fetch()) {
            $arID[] = $arRes['ID'];
        }
    }
    foreach ($arID as $ID) {
        if (strlen($ID) <= 0) {
            continue;