예제 #1
0
 function _AttemptExists($testID, $attemptID = false)
 {
     $arFields = array("STUDENT_ID" => intval($GLOBALS["USER"]->GetID()), "TEST_ID" => $testID, "STATUS" => "B");
     if ($attemptID !== false) {
         $arFields["ID"] = $attemptID;
     }
     $rsAttempt = CTestAttempt::GetList(array(), $arFields);
     return $rsAttempt->GetNext();
 }
예제 #2
0
    $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;
    $attempts = CTestAttempt::GetList(array('ID' => 'DESC'), array('TEST_ID' => $testId, 'STUDENT_ID' => (int) $USER->getId()), array('ID', 'TEST_ID', 'STUDENT_ID', 'SCORE', 'COMPLETED'), array('NAV_PARAMS' => array('nPageTop' => 1)));
    $lastScore = false;
    $lastCompleted = false;
    if ($arAttempt = $attempts->fetch()) {
        $lastScore = $arAttempt['SCORE'];
        $lastCompleted = $arAttempt['COMPLETED'];
    }
    $arResult['LAST_TEST_INFO'][$testId] = array('LAST_SCORE' => $lastScore, 'LAST_COMPLETED' => $lastCompleted);
}
unset($rsGradebook);
unset($arGradebook);
//Attempts
if (array_key_exists($arParams["TEST_ID_VARIABLE"], $_REQUEST) && intval($_REQUEST[$arParams["TEST_ID_VARIABLE"]]) > 0) {
    $rsAttempt = CTestAttempt::GetList(array("ID" => "DESC"), array("TEST_ID" => intval($_REQUEST[$arParams["TEST_ID_VARIABLE"]]), "STUDENT_ID" => intval($USER->GetID())));
    while ($arAttempt = $rsAttempt->GetNext()) {
        $arResult["ATTEMPTS"][] = $arAttempt;
    }
    unset($arAttempt);
    unset($rsAttempt);
}
$this->IncludeComponentTemplate();
예제 #3
0
	/**
	 * <p>Метод удаляет запись в журнале с идентификатором ID.</p>
	 *
	 *
	 *
	 *
	 * @param int $ID  Идентификатор записи.
	 *
	 *
	 *
	 * @return bool <p>Метод возвращает <i>true</i> в случае успешного удаления записи, в
	 * противном случае возвращает <i>false</i>.</p><a name="examples"></a>
	 *
	 *
	 * <h4>Example</h4> 
	 * <pre>
	 * &lt;?
	 * if (CModule::IncludeModule("learning"))
	 * {
	 *     $RECORD_ID = 96;
	 * 
	 *     @set_time_limit(0);
	 *     $DB-&gt;StartTransaction();
	 *     if (!CGradeBook::Delete($RECORD_ID))
	 *     {
	 *         echo "Error!";
	 *         $DB-&gt;Rollback();
	 *     }
	 *     else
	 *         $DB-&gt;Commit();
	 * 
	 * }
	 * ?&gt;
	 * </pre>
	 *
	 *
	 * @static
	 * @link http://dev.1c-bitrix.ru/api_help/learning/classes/cgradebook/delete.php
	 * @author Bitrix
	 */
	public static function Delete($ID)
	{
		global $DB;

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

		$strSql = "SELECT TEST_ID, STUDENT_ID FROM b_learn_gradebook WHERE ID = ".$ID;
		$res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
		if (!$arGBook = $res->Fetch())
			return false;

		$attempts = CTestAttempt::GetList(Array(), Array("TEST_ID" => $arGBook["TEST_ID"], "STUDENT_ID" => $arGBook["STUDENT_ID"]));
		while($arAttempt = $attempts->Fetch())
		{
			if(!CTestAttempt::Delete($arAttempt["ID"]))
				return false;
		}

		$strSql = "DELETE FROM b_learn_gradebook WHERE ID = ".$ID;

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

		return true;

	}
예제 #4
0
	public static function OnTestResultChange($TEST_RESULT_ID)
	{
		global $DB;

		$TEST_RESULT_ID = intval($TEST_RESULT_ID);

		if ($TEST_RESULT_ID < 1)
			return false;

		$strSql =
		"SELECT TR.* ".
		"FROM b_learn_test_result TR ".
		"WHERE TR.ID = '".$TEST_RESULT_ID."'";

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

		$strSql =
		"SELECT SUM(TR.POINT) as SUM_POINT, SUM( Q.POINT ) MAX_POINT ".
		"FROM b_learn_test_result TR ".
		"INNER JOIN b_learn_question Q ON TR.QUESTION_ID = Q.ID ".
		"WHERE TR.ATTEMPT_ID = '".$arAttemptResult["ATTEMPT_ID"]."'";

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

		$strSql =
		"UPDATE b_learn_attempt SET SCORE = '".$arSum["SUM_POINT"]."', MAX_SCORE ='".$arSum["MAX_POINT"]."' ".
		"WHERE ID = '".$arAttemptResult["ATTEMPT_ID"]."'";

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

		return CTestAttempt::OnAttemptChange($arAttemptResult["ATTEMPT_ID"]);
	}
예제 #5
0
    $APPLICATION->SetTitle(GetMessage("LEARNING_TESTS_LIST"));
}
//arResult
$arResult = array("TESTS" => array(), "TESTS_COUNT" => 0, "ERROR_MESSAGE" => "", "NAV_SRTING" => "", "NAV_RESULT" => null);
$rsTest = CTest::GetList(array("SORT" => "ASC"), array("COURSE_ID" => $arParams["COURSE_ID"], "ACTIVE" => "Y", "CHECK_PERMISSIONS" => $arParams["CHECK_PERMISSIONS"]));
CPageOption::SetOptionString("main", "nav_page_in_session", "N");
$rsTest->NavStart($arParams["TESTS_PER_PAGE"]);
$arResult["NAV_STRING"] = $rsTest->GetPageNavString(GetMessage("LEARNING_TESTS_NAV"));
$arResult["NAV_RESULT"] = $rsTest;
while ($arTest = $rsTest->GetNext()) {
    //Test URL
    $arTest["TEST_DETAIL_URL"] = CComponentEngine::MakePathFromTemplate($arParams["TEST_DETAIL_TEMPLATE"], array("TEST_ID" => $arTest["ID"], "COURSE_ID" => $arTest["COURSE_ID"]));
    if ($_SERVER['REDIRECT_STATUS'] == '404' || isset($_REQUEST["SEF_APPLICATION_CUR_PAGE_URL"])) {
        $arTest["TEST_DETAIL_URL"] = "/bitrix/urlrewrite.php?SEF_APPLICATION_CUR_PAGE_URL=" . urlencode($arTest["TEST_DETAIL_URL"]);
    }
    //Unfinished attempt exists?
    $arTest["ATTEMPT"] = false;
    if ($USER->IsAuthorized()) {
        $rsAttempt = CTestAttempt::GetList(array(), array("TEST_ID" => $arTest["ID"], "STATUS" => "B", "STUDENT_ID" => intval($USER->GetID())));
        $arTest["ATTEMPT"] = $rsAttempt->GetNext();
    }
    $arResult["TESTS"][] = $arTest;
}
$arResult["TESTS_COUNT"] = count($arResult["TESTS"]);
if ($arResult["TESTS_COUNT"] <= 0) {
    $arResult["ERROR_MESSAGE"] = GetMessage("LEARNING_BAD_TEST_LIST");
}
unset($rsTest);
unset($arTest);
unset($rsAttempt);
$this->IncludeComponentTemplate();
        CAdminMessage::ShowMessage(GetMessage('LEARNING_MODULE_NOT_FOUND'));
    }
    require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_admin.php';
    // system's epilog
    exit;
}
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/learning/prolog.php";
IncludeModuleLangFile(__FILE__);
ClearVars();
$ATTEMPT_ID = intval($ATTEMPT_ID);
$ID = intval($ID);
$bBadResult = false;
$message = null;
//$r = CTestAttempt::GetByID($ATTEMPT_ID);
// was: $r = CTestAttempt::GetList(Array(), Array("ID" => $ATTEMPT_ID, "MIN_PERMISSION" => "W"));
$r = CTestAttempt::GetList(array(), array("ID" => $ATTEMPT_ID, 'ACCESS_OPERATIONS' => CLearnAccess::OP_LESSON_READ | CLearnAccess::OP_LESSON_WRITE));
if (!($arAttempt = $r->GetNext())) {
    $bBadResult = true;
}
if (!$bBadResult) {
    $r = CTestResult::GetByID($ID);
    if (!$r->ExtractFields("str_")) {
        $bBadResult = true;
    }
}
if ($bBadResult) {
    $APPLICATION->SetTitle(GetMessage("LEARNING_ADMIN_TITLE"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
    $aContext = array(array("ICON" => "btn_list", "TEXT" => GetMessage("LEARNING_BACK_TO_ADMIN"), "LINK" => "learn_unilesson_admin.php?lang=" . LANG, "TITLE" => GetMessage("LEARNING_BACK_TO_ADMIN")));
    $context = new CAdminContextMenu($aContext);
    $context->Show();
예제 #7
0
 /**
  * <p>Метод удаляет вопрос с идентификатором ID.</p>
  *
  *
  * @param int $ID  Идентификатор вопроса.
  *
  * @return bool <p>Метод возвращает <i>true</i> в случае успешного удаления вопроса, в
  * противном случае возвращает <i>false</i>.</p>
  *
  * <h4>Example</h4> 
  * <pre>
  * &lt;?
  * if (CModule::IncludeModule("learning"))
  * {
  *     $COURSE_ID = 97;
  *     $QUESTION_ID = 600;
  * 
  *     if (CCourse::GetPermission($COURSE_ID) &gt;= 'W')
  *     {
  *         @set_time_limit(0);
  *         $DB-&gt;StartTransaction();
  *         if (!CLQuestion::Delete($QUESTION_ID))
  *         {
  *             echo "Error!";
  *             $DB-&gt;Rollback();
  *         }
  *         else
  *             $DB-&gt;Commit();
  *     }
  * }
  * ?&gt;
  * </pre>
  *
  *
  * <h4>See Also</h4> 
  * <ul><li> <a href="http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/index.php">CLQuestion</a>::<a
  * href="http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/add.php">Add</a> </li></ul><a name="examples"></a>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/delete.php
  * @author Bitrix
  */
 public static function Delete($ID)
 {
     global $DB, $USER_FIELD_MANAGER;
     $ID = intval($ID);
     if ($ID < 1) {
         return false;
     }
     $strSql = "SELECT FILE_ID FROM b_learn_question WHERE ID = " . $ID;
     $r = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if (!($arQuestion = $r->Fetch())) {
         return false;
     }
     $answers = CLAnswer::GetList(array(), array("QUESTION_ID" => $ID));
     while ($arAnswer = $answers->Fetch()) {
         if (!CLAnswer::Delete($arAnswer["ID"])) {
             return false;
         }
     }
     $arAttempts = array();
     $strSql = "SELECT ATTEMPT_ID FROM b_learn_test_result WHERE QUESTION_ID = " . $ID;
     $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     while ($ar = $res->Fetch()) {
         $arAttempts[] = $ar["ATTEMPT_ID"];
     }
     //Attempts to recount
     //Results
     $strSql = "DELETE FROM b_learn_test_result WHERE QUESTION_ID = " . $ID;
     if (!$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__)) {
         return false;
     }
     foreach ($arAttempts as $ATTEMPT_ID) {
         CTestAttempt::RecountQuestions($ATTEMPT_ID);
         CTestAttempt::OnAttemptChange($ATTEMPT_ID);
     }
     $strSql = "DELETE FROM b_learn_question WHERE ID = " . $ID;
     if (!$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__)) {
         return false;
     }
     $USER_FIELD_MANAGER->delete('LEARNING_QUESTIONS', $ID);
     CFile::Delete($arQuestion["FILE_ID"]);
     CEventLog::add(array('AUDIT_TYPE_ID' => 'LEARNING_REMOVE_ITEM', 'MODULE_ID' => 'learning', 'ITEM_ID' => 'Q #' . $ID, 'DESCRIPTION' => 'question removed'));
     foreach (GetModuleEvents('learning', 'OnAfterQuestionDelete', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $arQuestion));
     }
     return true;
 }
예제 #8
0
	/**
	 * <p>Метод удаляет вопрос с идентификатором ID.</p>
	 *
	 *
	 *
	 *
	 * @param int $ID  Идентификатор вопроса.
	 *
	 *
	 *
	 * @return bool <p>Метод возвращает <i>true</i> в случае успешного удаления вопроса, в
	 * противном случае возвращает <i>false</i>.</p>
	 *
	 *
	 * <h4>Example</h4> 
	 * <pre>
	 * &lt;?
	 * if (CModule::IncludeModule("learning"))
	 * {
	 *     $COURSE_ID = 97;
	 *     $QUESTION_ID = 600;
	 * 
	 *     if (CCourse::GetPermission($COURSE_ID) &gt;= 'W')
	 *     {
	 *         @set_time_limit(0);
	 *         $DB-&gt;StartTransaction();
	 *         if (!CLQuestion::Delete($QUESTION_ID))
	 *         {
	 *             echo "Error!";
	 *             $DB-&gt;Rollback();
	 *         }
	 *         else
	 *             $DB-&gt;Commit();
	 *     }
	 * }
	 * ?&gt;
	 * </pre>
	 *
	 *
	 *
	 * <h4>See Also</h4> 
	 * <ul><li> <a href="http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/index.php">CLQuestion</a>::<a
	 * href="http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/add.php">Add</a> </li></ul><a name="examples"></a>
	 *
	 *
	 * @static
	 * @link http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/delete.php
	 * @author Bitrix
	 */
	public static function Delete($ID)
	{
		global $DB;

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

		$strSql = "SELECT FILE_ID FROM b_learn_question WHERE ID = ".$ID;
		$r = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
		if (!$arQuestion = $r->Fetch())
			return false;

		$answers = CLAnswer::GetList(Array(), Array("QUESTION_ID" => $ID));
		while($arAnswer = $answers->Fetch())
		{
			if(!CLAnswer::Delete($arAnswer["ID"]))
				return false;
		}

		$arAttempts = Array();
		$strSql = "SELECT ATTEMPT_ID FROM b_learn_test_result WHERE QUESTION_ID = ".$ID;
		$res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
		while($ar = $res->Fetch())
			$arAttempts[] = $ar["ATTEMPT_ID"]; //Attempts to recount

		//Results
		$strSql = "DELETE FROM b_learn_test_result WHERE QUESTION_ID = ".$ID;
		if (!$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__))
			return false;

		foreach($arAttempts as $ATTEMPT_ID)
		{
			CTestAttempt::RecountQuestions($ATTEMPT_ID);
			CTestAttempt::OnAttemptChange($ATTEMPT_ID);
		}

		$strSql = "DELETE FROM b_learn_question WHERE ID = ".$ID;

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

		CFile::Delete($arQuestion["FILE_ID"]);

		return true;
	}
예제 #9
0
 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;
 }
예제 #10
0
}
if (!empty($filter_user)) {
    $arFilter["USER"] = $filter_user;
}
if ($lAdmin->EditAction()) {
    foreach ($FIELDS as $ID => $arFields) {
        if (!$lAdmin->IsUpdated($ID)) {
            continue;
        }
        $ID = IntVal($ID);
        $res = CTestAttempt::GetList(array(), array('ID' => $ID, 'ACCESS_OPERATIONS' => CLearnAccess::OP_LESSON_READ | CLearnAccess::OP_LESSON_WRITE));
        if (!$res->Fetch()) {
            continue;
        }
        $DB->StartTransaction();
        $ob = new CTestAttempt();
        if (!$ob->Update($ID, $arFields)) {
            if ($e = $APPLICATION->GetException()) {
                $lAdmin->AddUpdateError(GetMessage("SAVE_ERROR") . $ID . ": " . $e->GetString(), $ID);
                $DB->Rollback();
            }
        } else {
            $bCOMPLETED = false;
            if (is_set($arFields, "COMPLETED") && $arFields["COMPLETED"] == "Y") {
                $bCOMPLETED = true;
            }
            $ob->OnAttemptChange($ID, $bCOMPLETED);
        }
        $DB->Commit();
    }
}
예제 #11
0
         if (($arAtt = $rsAtt->GetNext()) && $arTest["APPROVED"] == "Y") {
             $arAtt["CORRECT_COUNT"] = CTestResult::GetCorrectCount($arAtt["ID"]);
             $sessAttempt = $arAtt;
         }
         $sessAttemptID = null;
         $sessAttemptFinished = true;
         LocalRedirect($arResult["REDIRECT_PAGE"]);
     }
 }
 //Get questions
 $rsTestResult = CTestResult::GetList(array("ID" => "ASC"), array("ATTEMPT_ID" => $sessAttemptID, 'CHECK_PERMISSIONS' => 'N'));
 $rsTestResult->NavStart(10000);
 $arResult["NAV"]["PAGE_COUNT"] = $rsTestResult->SelectedRowsCount();
 //If no questions
 if ($arResult["NAV"]["PAGE_COUNT"] <= 0) {
     $rsTestAttempt = new CTestAttempt();
     $rsTestAttempt->AttemptFinished($sessAttemptID);
     $sessAttemptID = null;
     $sessAttemptFinished = true;
     LocalRedirect($arResult["REDIRECT_PAGE"]);
 }
 if ($arResult["NAV"]["PAGE_NUMBER"] > $arResult["NAV"]["PAGE_COUNT"]) {
     $arResult["NAV"]["PAGE_NUMBER"] = 1;
     $arResult["REDIRECT_PAGE"] = str_replace("#PAGE_ID#", $arResult["NAV"]["PAGE_NUMBER"] + 1, $arResult["PAGE_TEMPLATE"]);
 }
 $questionPageIndex = 1;
 while ($arAttemptQuestion = $rsTestResult->GetNext()) {
     if (!$arResult["NAV"]["FIRST_NOANSWER"] && $arAttemptQuestion["ANSWERED"] == "N") {
         $arResult["NAV"]["FIRST_NOANSWER"] = $questionPageIndex;
     }
     $inaccessible = $arTest["PASSAGE_TYPE"] < 2 && $arAttemptQuestion["ANSWERED"] == "Y" || $arTest["PASSAGE_TYPE"] == 0 && $arAttemptQuestion["ANSWERED"] == "N";
    }
    foreach ($arID as $ID) {
        if (strlen($ID) <= 0) {
            continue;
        }
        $ID = intval($ID);
        switch ($_REQUEST['action']) {
            case "delete":
                @set_time_limit(0);
                $DB->StartTransaction();
                if (!CTestResult::Delete($ID)) {
                    $DB->Rollback();
                    $lAdmin->AddGroupError(GetMessage("LEARNING_DELETE_ERROR"), $ID);
                } else {
                    CTestAttempt::RecountQuestions($ATTEMPT_ID);
                    CTestAttempt::OnAttemptChange($ATTEMPT_ID);
                }
                $DB->Commit();
                break;
        }
    }
}
// fetch data
$rsData = CTestResult::GetList(array($by => $order), $arFilter);
$rsData = new CAdminResult($rsData, $sTableID);
$rsData->NavStart();
// navigation string setup
$lAdmin->NavText($rsData->GetNavPrint(GetMessage("LEARNING_ADMIN_RESULTS")));
// list header
$lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "id", "default" => true), array("id" => "QUESTION_NAME", "content" => GetMessage('LEARNING_ADMIN_QUESTION_NAME'), "sort" => "question_name", "default" => true), array("id" => "ANSWERED", "content" => GetMessage('LEARNING_ADMIN_ANSWERED'), "sort" => "answered", "default" => true), array("id" => "CORRECT", "content" => GetMessage('LEARNING_ADMIN_CORRECT'), "sort" => "correct", "default" => true), array("id" => "POINT", "content" => GetMessage('LEARNING_ADMIN_POINT'), "sort" => "point", "default" => true), array("id" => "RESPONSE_TEXT", "content" => GetMessage('LEARNING_ADMIN_USER_RESPONSE_TEXT'), "sort" => "point", "default" => true)));
// building list
예제 #13
0
$arResult["NAV_RESULT"] = $rsTest;
while ($arTest = $rsTest->GetNext()) {
    // Resolve links "?COURSE_ID={SELF}". Don't relay on it, this behaviour
    // can be changed in future without any notifications.
    if (isset($arTest['DESCRIPTION'])) {
        $arTest['DESCRIPTION'] = CLearnHelper::PatchLessonContentLinks($arTest['DESCRIPTION'], $arParams['COURSE_ID']);
    }
    //Test URL
    $arTest["TEST_DETAIL_URL"] = CComponentEngine::MakePathFromTemplate($arParams["TEST_DETAIL_TEMPLATE"], array("TEST_ID" => $arTest["ID"], "COURSE_ID" => $arTest["COURSE_ID"]));
    if ($_SERVER['REDIRECT_STATUS'] == '404' || isset($_REQUEST["SEF_APPLICATION_CUR_PAGE_URL"])) {
        $arTest["TEST_DETAIL_URL"] = "/bitrix/urlrewrite.php?SEF_APPLICATION_CUR_PAGE_URL=" . urlencode($arTest["TEST_DETAIL_URL"]);
    }
    //Unfinished attempt exists?
    $arTest["ATTEMPT"] = false;
    if ($USER->IsAuthorized()) {
        $rsAttempt = CTestAttempt::GetList(array(), array("TEST_ID" => $arTest["ID"], "STATUS" => "B", "STUDENT_ID" => intval($USER->GetID()), "CHECK_PERMISSIONS" => $arParams["CHECK_PERMISSIONS"]));
        $arTest["ATTEMPT"] = $rsAttempt->GetNext();
    }
    if ($arTest["PREVIOUS_TEST_ID"] > 0 && $arTest["PREVIOUS_TEST_SCORE"] > 0) {
        $rsPrevTest = CTest::GetList(array(), array("ID" => $arTest["PREVIOUS_TEST_ID"], 'CHECK_PERMISSIONS' => 'N'));
        if ($arPrevTest = $rsPrevTest->GetNext()) {
            if ($parent = $this->GetParent()) {
                $testUrlTemplate = CComponentEngine::MakePathFromTemplate($parent->arResult["URL_TEMPLATES"]["test"], array("TEST_ID" => $arPrevTest["ID"], "COURSE_ID" => $arPrevTest["COURSE_ID"]));
                $arTest["PREVIOUS_TEST_LINK"] = "<a href=\"" . $testUrlTemplate . "\">" . $arPrevTest["NAME"] . "</a>";
            }
        }
    }
    $arResult["TESTS"][] = $arTest;
}
$arResult["TESTS_COUNT"] = count($arResult["TESTS"]);
if ($arResult["TESTS_COUNT"] <= 0) {
예제 #14
0
}
if ($bBadAttempt) {
    $APPLICATION->SetTitle(GetMessage("LEARNING_ADMIN_TITLE"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
    $aContext = array(array("ICON" => "btn_list", "TEXT" => GetMessage("LEARNING_BACK_TO_ADMIN"), "LINK" => "learn_attempt_admin.php?lang=" . LANG, "TITLE" => GetMessage("LEARNING_BACK_TO_ADMIN")));
    $context = new CAdminContextMenu($aContext);
    $context->Show();
    CAdminMessage::ShowMessage(GetMessage("LEARNING_BAD_ATTEMPT_ID_EX"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
    die;
}
$aTabs = array(array("DIV" => "edit1", "ICON" => "main_user_edit", "TAB" => GetMessage("LEARNING_ADMIN_TAB1"), "TITLE" => GetMessage("LEARNING_ADMIN_TAB1_EX")));
$aTabs[] = $USER_FIELD_MANAGER->EditFormTab("LEARN_ATTEMPT");
$tabControl = new CAdminForm("attemptTabControl", $aTabs);
if (!$bBadAttempt && $_SERVER["REQUEST_METHOD"] == "POST" && strlen($Update) > 0 && check_bitrix_sessid()) {
    $ta = new CTestAttempt();
    $arFields = array("SCORE" => $SCORE, "MAX_SCORE" => $MAX_SCORE, "COMPLETED" => $COMPLETED == "Y" ? "Y" : "N", "STATUS" => $STATUS, "DATE_START" => $DATE_START, "DATE_END" => $DATE_END);
    $USER_FIELD_MANAGER->EditFormAddFields("LEARN_ATTEMPT", $arFields);
    $res = $ta->Update($ID, $arFields);
    if (!$res) {
        if ($e = $APPLICATION->GetException()) {
            $message = new CAdminMessage(GetMessage("LEARNING_ERROR"), $e);
        }
        $bVarsFromForm = true;
    } else {
        if (strlen($apply) <= 0) {
            if (strlen($return_url) > 0) {
                LocalRedirect($return_url);
            } else {
                LocalRedirect("/bitrix/admin/learn_attempt_admin.php?lang=" . LANG . GetFilterParams("filter_", false));
            }
예제 #15
0
 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;
 }
예제 #16
0
파일: test.php 프로젝트: ASDAFF/bxApiDocs
	/**
	 * <p>Метод удаляет тест с идентификатором ID.</p>
	 *
	 *
	 *
	 *
	 * @param int $ID  Идентификатор теста.
	 *
	 *
	 *
	 * @return bool <p>Метод возвращает <i>true</i> в случае успешного удаления теста, в
	 * противном случае возвращает <i>false</i>.</p><a name="examples"></a>
	 *
	 *
	 * <h4>Example</h4> 
	 * <pre>
	 * &lt;?
	 * if (CModule::IncludeModule("learning"))
	 * {
	 * 
	 *     $TEST_ID = 99;
	 *     $COURSE_ID = 97;
	 * 
	 *     if (CCourse::GetPermission($COURSE_ID) &gt;= 'W')
	 *     {
	 *         @set_time_limit(0);
	 *         $DB-&gt;StartTransaction();
	 *         if (!CTest::Delete($TEST_ID))
	 *         {
	 *             echo "Error!";
	 *             $DB-&gt;Rollback();
	 *         }
	 *         else
	 *             $DB-&gt;Commit();
	 *     }
	 * }
	 * ?&gt;
	 * </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;

	}