}
$aTabs = array(array("DIV" => "edit1", "TAB" => GetMessage("LEARNING_ADMIN_TAB1"), "ICON" => "main_user_edit", "TITLE" => GetMessage("LEARNING_ADMIN_TAB1_EX")));
$tabControl = new CAdminForm("testResultTabControl", $aTabs);
if ($_SERVER["REQUEST_METHOD"] == "POST" && strlen($Update) > 0 && check_bitrix_sessid()) {
    if ($ANSWERED != "Y") {
        $ANSWERED = "N";
        $RESPONSE = "";
        $POINT = 0;
    } elseif ($CORRECT != "Y") {
        $CORRECT = "N";
        $POINT = 0;
    }
    $arFields = array("ANSWERED" => $ANSWERED, "CORRECT" => $CORRECT, "RESPONSE" => $RESPONSE, "POINT" => $POINT);
    $DB->StartTransaction();
    $tr = new CTestResult();
    $res = $tr->Update($ID, $arFields);
    if (!$res) {
        $DB->Rollback();
        if ($e = $APPLICATION->GetException()) {
            $message = new CAdminMessage(GetMessage("LEARNING_ERROR"), $e);
        }
        $bVarsFromForm = true;
    } else {
        $tr->OnTestResultChange($ID);
        $DB->Commit();
        if (strlen($apply) <= 0) {
            if (strlen($return_url) > 0) {
                LocalRedirect($return_url);
            } else {
                LocalRedirect("/bitrix/admin/learn_test_result_admin.php?lang=" . LANG . "&ATTEMPT_ID=" . $ATTEMPT_ID . GetFilterParams("filter_", false));
            }
Beispiel #2
0
	/**
	 * <p>Сохраняет ответ учащегося и устанавливает, отвечен ли вопрос правильно.</p>
	 *
	 *
	 *
	 *
	 * @param int $TEST_RESULT_ID  Идентификатор вопроса в плане тестирования.
	 *
	 *
	 *
	 * @param mixed $RESPONSE  Идентификатор или массив идентификаторов <a
	 * href="../../fields.php#answer">ответов на вопрос</a>.
	 *
	 *
	 *
	 * @return bool <p>Метод возвращает <i>true</i>, если изменение прошло успешно, при
	 * возникновении ошибки функция вернёт <i>false</i>. При возникновении
	 * ошибки в исключениях будет содержаться текст ошибки.</p>
	 *
	 *
	 * <h4>Example</h4> 
	 * <pre>
	 * if (CModule::IncludeModule("learning"))
	 * {
	 *     $TEST_TESULT_ID = 2962;
	 *     $RESPONSE = 186; //< or Array(186,187); >//
	 * 
	 *     $res = CTestResult::AddResponse($TEST_RESULT_ID, $RESPONSE);
	 *     if($res)
	 *      echo "Response has been added ";
	 *     else
	 *      echo "Error";
	 * }
	 * </pre>
	 *
	 *
	 *
	 * <h4>See Also</h4> 
	 * <ul> <li> <a href="index.php">CTestResult</a>::<a href="update.php">Update</a> </li> </ul><a name="examples"></a>
	 *
	 *
	 * @static
	 * @link http://dev.1c-bitrix.ru/api_help/learning/classes/ctestresult/addresponse.php
	 * @author Bitrix
	 */
	public static function AddResponse($TEST_RESULT_ID, $RESPONSE)
	{
		global $DB;

		$TEST_RESULT_ID = intval($TEST_RESULT_ID);
		if ($TEST_RESULT_ID < 1) return false;

		$rsTestResult = CTestResult::GetList(Array(), Array("ID" => $TEST_RESULT_ID, 'CHECK_PERMISSIONS' => 'N'));

		if ($arTestResult = $rsTestResult->GetNext())
		{
			if ($arTestResult["QUESTION_TYPE"] == "T")
			{
				$arFields = Array(
					"ANSWERED" => "Y",
					"RESPONSE" => $RESPONSE,
					"POINT"=> 0,
					"CORRECT"=> "N",
				);
			}
			else
			{
				if (!is_array($RESPONSE))
					$RESPONSE = Array($RESPONSE);

				$strSql =
				"SELECT A.ID, Q.POINT ".
				"FROM b_learn_test_result TR ".
				"INNER JOIN b_learn_question Q ON TR.QUESTION_ID = Q.ID ".
				"INNER JOIN b_learn_answer A ON Q.ID = A.QUESTION_ID ".
				"WHERE TR.ID = '".$TEST_RESULT_ID."' ".
				($arTestResult["QUESTION_TYPE"] != "R" ? "AND A.CORRECT = 'Y' " : "").
				"ORDER BY A.SORT ASC, A.ID ASC";

				if (!$res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__))
					return false;

				$arAnswer = Array();
				while ($arRes = $res->Fetch())
				{
					$arAnswer[] = $arRes["ID"];
					$str_POINT = $arRes["POINT"];
				}

				if ($arTestResult["QUESTION_TYPE"] == "R")
				{
					if ($arAnswer != $RESPONSE)
						$str_POINT = "0";
				}
				else
				{
					$t1 = array_diff($arAnswer,$RESPONSE);
					$t2 = array_diff($RESPONSE,$arAnswer);
					if ($t1!=$t2 || $t2 != Array())
						$str_POINT = "0";
				}

				//echo "!".$str_POINT."!";

				$arFields = Array(
					"ANSWERED" => "Y",
					"RESPONSE" => $RESPONSE,
					"POINT"=> $str_POINT,
					"CORRECT"=> ($str_POINT == "0" ? "N" : "Y"),
				);
			}

			$tr = new CTestResult;
			if (!$res = $tr->Update($TEST_RESULT_ID, $arFields))
				return false;

			return $arFields;
		}
		else
		{
			return false;
		}
	}
$arFilterFields = array("filter_question_name", "filter_id", "filter_answered", "filter_correct");
$lAdmin->InitFilter($arFilterFields);
// filter initializing
$arFilter = array("ID" => $filter_id, "ANSWERED" => $filter_answered, "CORRECT" => $filter_correct, "?QUESTION_NAME" => $filter_question_name);
if ($ATTEMPT_ID > 0) {
    $arFilter["ATTEMPT_ID"] = $ATTEMPT_ID;
}
if ($lAdmin->EditAction()) {
    foreach ($FIELDS as $ID => $arFields) {
        if (!$lAdmin->IsUpdated($ID)) {
            continue;
        }
        $DB->StartTransaction();
        $ID = IntVal($ID);
        $ob = new CTestResult();
        if (!$ob->Update($ID, $arFields)) {
            if ($e = $APPLICATION->GetException()) {
                $lAdmin->AddUpdateError(GetMessage("SAVE_ERROR") . $ID . ": " . $e->GetString(), $ID);
                $DB->Rollback();
            }
        } else {
            $ob->OnTestResultChange($ID);
        }
        $DB->Commit();
    }
}
// group and single actions processing
if ($arID = $lAdmin->GroupAction()) {
    if ($_REQUEST['action_target'] == 'selected') {
        $rsData = CTestResult::GetList(array($by => $order), $arFilter);
        while ($arRes = $rsData->Fetch()) {