function Delete($ID) { global $DB; $ID = intval($ID); if ($ID < 1) { return false; } CLearnHelper::FireEvent('OnBeforeTestDelete', $ID); //Gradebook $records = CGradeBook::GetList(array(), array("TEST_ID" => $ID)); while ($arRecord = $records->Fetch()) { if (!CGradeBook::Delete($arRecord["ID"])) { return false; } } //Attempts $attempts = CTestAttempt::GetList(array(), array("TEST_ID" => $ID)); while ($arAttempt = $attempts->Fetch()) { if (!CTestAttempt::Delete($arAttempt["ID"])) { return false; } } //Marks $marks = CLTestMark::GetList(array(), array("TEST_ID" => $ID)); while ($arMark = $marks->Fetch()) { if (!CLTestMark::Delete($arMark["ID"])) { return false; } } $strSql = "DELETE FROM b_learn_test WHERE ID = " . $ID; if (!$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__)) { return false; } CEventLog::add(array('AUDIT_TYPE_ID' => 'LEARNING_REMOVE_ITEM', 'MODULE_ID' => 'learning', 'ITEM_ID' => 'T #' . $ID, 'DESCRIPTION' => 'test removed')); CLearnHelper::FireEvent('OnAfterTestDelete', $ID); return true; }
$ID = $test->Add($arFields); $res = $ID > 0; } if (!$res) { if ($e = $APPLICATION->GetException()) { $message = new CAdminMessage(GetMessage("LEARNING_ERROR"), $e); } $bVarsFromForm = true; } else { //Marks $marks = CLTestMark::GetList(array(), array("TEST_ID" => $ID)); $arMarks = $arScores = array(); while ($m = $marks->GetNext()) { //delete? if (${"MARK_" . $m["ID"] . "_DEL"} == "Y") { if (!CLTestMark::Delete($m["ID"])) { $message = new CAdminMessage(array("MESSAGE" => GetMessage("LEARNING_DELETE_ERROR") . $m["ID"])); $bVarsFromForm = true; } } if (in_array(${"SCORE_" . $m["ID"]}, $arScores)) { $message = new CAdminMessage(array("MESSAGE" => str_replace("##SCORE##", ${"SCORE_" . $m["ID"]}, GetMessage("LEARNING_SCORE_EXISTS_ERROR")))); $bVarsFromForm = true; } elseif (in_array(${"MARK_" . $m["ID"]}, $arMarks)) { $message = new CAdminMessage(array("MESSAGE" => str_replace("##MARK##", ${"MARK_" . $m["ID"]}, GetMessage("LEARNING_MARK_EXISTS_ERROR")))); $bVarsFromForm = true; } else { if (${"MARK_" . $m["ID"] . "_DEL"} != "Y") { $arMarks[] = ${"MARK_" . $m["ID"]}; $arScores[] = ${"SCORE_" . $m["ID"]}; }
/** * <p>Метод удаляет тест с идентификатором ID.</p> * * * * * @param int $ID Идентификатор теста. * * * * @return bool <p>Метод возвращает <i>true</i> в случае успешного удаления теста, в * противном случае возвращает <i>false</i>.</p><a name="examples"></a> * * * <h4>Example</h4> * <pre> * <? * if (CModule::IncludeModule("learning")) * { * * $TEST_ID = 99; * $COURSE_ID = 97; * * if (CCourse::GetPermission($COURSE_ID) >= 'W') * { * @set_time_limit(0); * $DB->StartTransaction(); * if (!CTest::Delete($TEST_ID)) * { * echo "Error!"; * $DB->Rollback(); * } * else * $DB->Commit(); * } * } * ?> * </pre> * * * @static * @link http://dev.1c-bitrix.ru/api_help/learning/classes/ctest/delete.php * @author Bitrix */ public static function Delete($ID) { global $DB; $ID = intval($ID); if ($ID < 1) return false; CLearnHelper::FireEvent('OnBeforeTestDelete', $ID); //Gradebook $records = CGradeBook::GetList(Array(), Array("TEST_ID" => $ID)); while($arRecord = $records->Fetch()) { if(!CGradeBook::Delete($arRecord["ID"])) return false; } //Attempts $attempts = CTestAttempt::GetList(Array(), Array("TEST_ID" => $ID)); while($arAttempt = $attempts->Fetch()) { if(!CTestAttempt::Delete($arAttempt["ID"])) return false; } //Marks $marks = CLTestMark::GetList(Array(), Array("TEST_ID" => $ID)); while($arMark = $marks->Fetch()) { if(!CLTestMark::Delete($arMark["ID"])) return false; } $strSql = "DELETE FROM b_learn_test WHERE ID = ".$ID; if (!$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__)) return false; CLearnHelper::FireEvent('OnAfterTestDelete', $ID); return true; }