Exemplo n.º 1
0
     }
     //add new
     for ($i = 0; $i < 500; $i++) {
         if (strlen(${"ANSWER_n" . $i . "_ANSWER"}) <= 0) {
             continue;
         }
         $arFields = array("SORT" => ${"ANSWER_n" . $i . "_SORT"}, "ANSWER" => ${"ANSWER_n" . $i . "_ANSWER"}, "QUESTION_ID" => $ID);
         switch ($QUESTION_TYPE) {
             case "M":
                 $arFields["CORRECT"] = ${"ANSWER_n" . $i . "_CORRECT"} == "Y" ? "Y" : "N";
                 break;
             case "S":
             default:
                 $arFields["CORRECT"] = "n" . $i == $ANSWER_CORRECT ? "Y" : "N";
         }
         $asw = new CLAnswer();
         $AswerID = $asw->Add($arFields);
         if (intval($AswerID) <= 0) {
             if ($e = $APPLICATION->GetException()) {
                 $message = new CAdminMessage(GetMessage("LEARNING_ERROR"), $e);
             }
             $bVarsFromForm = true;
         }
     }
 } else {
     //Delete answers
     $answers = CLAnswer::GetList(array(), array("QUESTION_ID" => $ID));
     while ($a = $answers->GetNext()) {
         CLAnswer::Delete($a["ID"]);
     }
 }
:</td>
	<td>
		<table>
		<?php 
if ($str_QUESTION_TYPE == "T") {
    ?>
			<tr>
				<td><textarea rows="5" cols="50" name="RESPONSE"><?php 
    echo $str_RESPONSE;
    ?>
</textarea></td>
			</tr>
		<?php 
} else {
    $arR = explode(',', $str_RESPONSE);
    $r = CLAnswer::GetList(array("ID" => "ASC"), array("QUESTION_ID" => $str_QUESTION_ID));
    while ($arAnswers = $r->GetNext()) {
        ?>
				<tr>
					<td>
					<?php 
        if ($str_QUESTION_TYPE == "M") {
            ?>
						<input type="checkbox" name="RESPONSE[]" value="<?php 
            echo $arAnswers["ID"];
            ?>
" <?php 
            if (in_array($arAnswers["ID"], $arR)) {
                echo "checked";
            }
            ?>
Exemplo n.º 3
0
 protected function _MakeItems($TITLE, $TYPE, $RES_ID, $PARENT_ID)
 {
     global $APPLICATION;
     if ($PARENT_ID === 0) {
         $linkToParentLessonId = CCourse::CourseGetLinkedLesson($this->COURSE_ID);
     } else {
         $linkToParentLessonId = (int) $PARENT_ID;
     }
     $createUnilesson = false;
     if ($TYPE == "LES") {
         $arFields = array('NAME' => $TITLE);
         $createUnilesson = true;
     } elseif ($TYPE == "CHA") {
         $arFields = array('NAME' => $TITLE);
         $createUnilesson = true;
     } elseif ($TYPE == "QUE") {
         $arFields = array("NAME" => $TITLE, "LESSON_ID" => $linkToParentLessonId);
         $cl = new CLQuestion();
     } elseif ($TYPE == "TES") {
         $arFields = array("NAME" => $TITLE, "COURSE_ID" => $this->COURSE_ID);
         $cl = new CTest();
     } elseif ($TYPE === 'TMK') {
         $arFields = array();
         $cl = new CLTestMark();
     } else {
         return $PARENT_ID;
     }
     $r = new CDataXML();
     if (!$r->Load($this->package_dir . "/" . strtolower($RES_ID) . ".xml")) {
         $r = false;
     }
     if ($r !== false) {
         if ($TYPE == "QUE") {
             if (($data = $r->SelectNodes("/questestinterop/item/presentation/")) && ($resp = $r->SelectNodes("/questestinterop/item/resprocessing/"))) {
                 $arQ = array();
                 $arData = $data->__toArray();
                 $arResp = $resp->__toArray();
                 if (is_set($arData["#"]["material"][0]["#"], "mattext")) {
                     $arQ["NAME"] = $arData["#"]["material"][0]["#"]["mattext"][0]["#"];
                 }
                 if (is_set($arData["#"]["material"][0]["#"], "matimage")) {
                     $imageDescription = '';
                     if (is_set($arData["#"]["material"][0]["#"], 'image_description')) {
                         $imageDescription = $arData["#"]["material"][0]["#"]['image_description'][0]['#'];
                     }
                     $arQ["FILE_ID"] = array("MODULE_ID" => "learning", "name" => basename($arData["#"]["material"][0]["#"]["matimage"][0]["@"]["uri"]), "tmp_name" => $this->package_dir . "/" . $arData["#"]["material"][0]["#"]["matimage"][0]["@"]["uri"], "size" => @filesize($this->package_dir . "/" . $arData["#"]["material"][0]["#"]["matimage"][0]["@"]["uri"]), "type" => $arData["#"]["material"][0]["#"]["matimage"][0]["@"]["imagtype"], 'description' => $imageDescription);
                 }
                 if (is_set($arData["#"]["response_lid"][0]["@"], "rcardinality")) {
                     switch ($arData["#"]["response_lid"][0]["@"]["rcardinality"]) {
                         case "Multiple":
                             $arQ["QUESTION_TYPE"] = 'M';
                             break;
                         case "Text":
                             $arQ["QUESTION_TYPE"] = 'T';
                             break;
                         case "Sort":
                             $arQ["QUESTION_TYPE"] = 'R';
                             break;
                         default:
                             $arQ["QUESTION_TYPE"] = 'S';
                             break;
                     }
                 }
                 if (is_set($arResp["#"]["respcondition"][0]["#"], "setvar")) {
                     $arQ["POINT"] = $arResp["#"]["respcondition"][0]["#"]["setvar"][0]['#'];
                 }
                 //Additional
                 if ($bx = $r->SelectNodes("/questestinterop/item/bitrix/")) {
                     $arQ = array_merge($arQ, $this->_MakeFields($bx->__toArray(), $TYPE));
                     unset($bx);
                 }
                 $arFields = array_merge($arFields, $arQ);
                 $cl = new CLQuestion();
                 $ID = $cl->Add($arFields);
                 if ($ID > 0) {
                     $PARENT_ID = $ID;
                     $arCorrect = array();
                     if (is_set($arResp["#"]["respcondition"][0]["#"], "conditionvar") && is_set($arResp["#"]["respcondition"][0]["#"]["conditionvar"][0]["#"], "varequal")) {
                         foreach ($arResp["#"]["respcondition"][0]["#"]["conditionvar"][0]["#"]["varequal"] as $ar) {
                             $arCorrect[] = $ar["#"];
                         }
                     }
                     if (is_set($arData["#"]["response_lid"][0]["#"], "render_choice") && is_set($arData["#"]["response_lid"][0]["#"]["render_choice"][0]["#"], "response_label")) {
                         $i = 0;
                         foreach ($arData["#"]["response_lid"][0]["#"]["render_choice"][0]["#"]["response_label"] as $ar) {
                             $i += 10;
                             $cl = new CLAnswer();
                             $arFields = array("QUESTION_ID" => $PARENT_ID, "SORT" => $i, "CORRECT" => in_array($ar["@"]["ident"], $arCorrect) ? "Y" : "N", "ANSWER" => $ar["#"]["material"][0]["#"]["mattext"][0]["#"]);
                             $AswerID = $cl->Add($arFields);
                             $res = $AswerID > 0;
                             if (!$res) {
                                 if ($e = $APPLICATION->GetException()) {
                                     $this->arWarnings[$TYPE][] = array("TITLE" => $TITLE, "TEXT" => $e->GetString());
                                 }
                             }
                         }
                     }
                 } else {
                     if ($e = $APPLICATION->GetException()) {
                         $this->arWarnings[$TYPE][] = array("TITLE" => $TITLE, "TEXT" => $e->GetString());
                     }
                 }
                 unset($cl);
                 unset($data);
                 unset($arQ);
                 unset($resp);
                 unset($arData);
                 unset($arResp);
                 return $PARENT_ID;
             }
         } else {
             if ($data = $r->SelectNodes("/content/")) {
                 $ar = $data->__toArray();
                 $arFields = array_merge($arFields, $this->_MakeFields($ar, $TYPE));
                 if ($TYPE === 'TMK') {
                     $arFields['TEST_ID'] = (int) $PARENT_ID;
                 }
                 if (is_set($arFields, "COMPLETED_SCORE") && intval($arFields["COMPLETED_SCORE"]) <= 0) {
                     unset($arFields["COMPLETED_SCORE"]);
                 }
                 if (is_set($arFields, "PREVIOUS_TEST_ID") && intval($arFields["PREVIOUS_TEST_ID"]) <= 0 || !CTest::GetByID($arFields["PREVIOUS_TEST_ID"])->Fetch()) {
                     unset($arFields["PREVIOUS_TEST_ID"], $arFields["PREVIOUS_TEST_SCORE"]);
                 }
             }
         }
     }
     if ($createUnilesson === false) {
         $ID = $cl->Add($arFields);
         unset($cl);
     } else {
         $bProhibitPublish = false;
         // properties (in context of parent) by default
         $arProperties = array('SORT' => 500);
         // Lesson's sort order in context of parent
         if (isset($arFields['EDGE_SORT'])) {
             $arFields['SORT'] = (int) $arFields['EDGE_SORT'];
             unset($arFields['EDGE_SORT']);
         }
         if (isset($arFields['SORT'])) {
             $arProperties['SORT'] = (int) $arFields['SORT'];
             // Lessons doesn't have more SORT field
             unset($arFields['SORT']);
         }
         if (isset($arFields['META_PUBLISH_PROHIBITED'])) {
             if ($arFields['META_PUBLISH_PROHIBITED'] === 'Y') {
                 $bProhibitPublish = true;
             }
             unset($arFields['META_PUBLISH_PROHIBITED']);
         }
         // unset fields, that are absent in unilesson
         $arUnilessonFields = $arFields;
         $arFieldsNames = array_keys($arUnilessonFields);
         foreach ($arFieldsNames as $fieldName) {
             if (!in_array(strtoupper($fieldName), $this->arLessonWritableFields)) {
                 unset($arUnilessonFields[$fieldName]);
             }
         }
         $ID = CLearnLesson::Add($arUnilessonFields, false, $linkToParentLessonId, $arProperties);
         if ($bProhibitPublish && $ID > 0) {
             CLearnLesson::PublishProhibitionSetTo($ID, $linkToParentLessonId, $bProhibitPublish);
         }
     }
     if ($ID > 0) {
         return $ID;
     } else {
         if ($e = $APPLICATION->GetException()) {
             $this->arWarnings[$TYPE][] = array("TITLE" => $TITLE, "TEXT" => $e->GetString());
         }
     }
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
} else {
    $arNavParams = array('nPageSize' => CAdminResult::GetNavSize($sTableID));
}
$rsData = CLQuestion::GetList(array($by => $order), $arFilter, true, $arNavParams);
$rsData = new CAdminResult($rsData, $sTableID);
// navigation string setup
$lAdmin->NavText($rsData->GetNavPrint(GetMessage("LEARNING_QUESTION")));
// list header
$lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "id", "default" => true), array("id" => "ACTIVE", "content" => GetMessage('LEARNING_COURSE_ADM_ACT'), "sort" => "active", "default" => true), array("id" => "TIMESTAMP_X", "content" => GetMessage('LEARNING_COURSE_ADM_DATECH'), "sort" => "timestamp_x", "default" => true), array("id" => "NAME", "content" => GetMessage('LEARNING_NAME'), "sort" => "name", "default" => true), array("id" => "SORT", "content" => GetMessage('LEARNING_COURSE_ADM_SORT'), "sort" => "sort", "default" => true), array("id" => "SELF", "content" => GetMessage('LEARNING_QUESTION_ADM_SELF'), "sort" => "self", "default" => true), array("id" => "CORRECT_REQUIRED", "content" => GetMessage('LEARNING_QUESTION_ADM_REQUIRED'), "sort" => "correct_required", "default" => true), array("id" => "QUESTION_TYPE", "content" => GetMessage('LEARNING_QUESTION_ADM_TYPE'), "sort" => "type", "default" => true), array("id" => "POINT", "content" => GetMessage('LEARNING_QUESTION_ADM_POINT'), "sort" => "point", "default" => true), array("id" => "ANSWERS_STATS", "content" => GetMessage('LEARNING_QUESTION_ADM_STATS'), "default" => true)));
$arQuestions = array();
$arQuestionsIds = array();
while ($arRes = $rsData->Fetch()) {
    $arQuestionsIds[] = (int) $arRes['ID'];
    $arQuestions[] = $arRes;
}
$arMultiStats = CLAnswer::getMultiStats($arQuestionsIds);
// building list
foreach ($arQuestions as $arRes) {
    extract($arRes, EXTR_PREFIX_ALL, 'f');
    $row =& $lAdmin->AddRow($f_ID, $arRes);
    $arStat = $arMultiStats[$f_ID];
    $row->AddCheckField("SELF");
    $row->AddCheckField("ACTIVE");
    $row->AddCheckField("CORRECT_REQUIRED");
    $row->AddInputField("NAME", array("size" => "35"));
    $row->AddInputField("SORT", array("size" => "3"));
    $row->AddInputField("POINT", array("size" => "3"));
    $row->AddViewField("QUESTION_TYPE", '<div title="' . GetMessage("LEARNING_QUESTION_TYPE_" . $f_QUESTION_TYPE) . '" class="learning-question-' . strtolower($f_QUESTION_TYPE) . '"></div>');
    $index = '-';
    if ($arStat["ALL_CNT"] > 0.1) {
        $index = 100 * ($arStat["CORRECT_CNT"] / $arStat["ALL_CNT"]);
Exemplo n.º 6
0
 function GetList($arOrder = array(), $arFilter = array())
 {
     global $DB, $USER;
     $arSqlSearch = CLAnswer::GetFilter($arFilter);
     $strSqlSearch = "";
     for ($i = 0; $i < count($arSqlSearch); $i++) {
         if (strlen($arSqlSearch[$i]) > 0) {
             $strSqlSearch .= " AND " . $arSqlSearch[$i] . " ";
         }
     }
     $strSql = "SELECT CA.*, CQ.ID AS QUESTION_ID, CQ.NAME AS QUESTION_NAME " . "FROM b_learn_answer CA " . "INNER JOIN b_learn_question CQ ON CA.QUESTION_ID = CQ.ID " . "WHERE 1=1 " . $strSqlSearch;
     if (!is_array($arOrder)) {
         $arOrder = array();
     }
     foreach ($arOrder as $by => $order) {
         $by = strtolower($by);
         $order = strtolower($order);
         if ($order != "asc") {
             $order = "desc";
         }
         if ($by == "id") {
             $arSqlOrder[] = " CA.ID " . $order . " ";
         } elseif ($by == "sort") {
             $arSqlOrder[] = " CA.SORT " . $order . " ";
         } elseif ($by == "correct") {
             $arSqlOrder[] = " CA.CORRECT " . $order . " ";
         } elseif ($by == "answer") {
             $arSqlOrder[] = " CA.ANSWER " . $order . " ";
         } elseif ($by == "rand") {
             $arSqlOrder[] = CTest::GetRandFunction();
         } else {
             $arSqlOrder[] = " CA.ID " . $order . " ";
             $by = "id";
         }
     }
     $strSqlOrder = "";
     DelDuplicateSort($arSqlOrder);
     for ($i = 0; $i < count($arSqlOrder); $i++) {
         if ($i == 0) {
             $strSqlOrder = " ORDER BY ";
         } else {
             $strSqlOrder .= ",";
         }
         $strSqlOrder .= $arSqlOrder[$i];
     }
     $strSql .= $strSqlOrder;
     //echo $strSql;
     return $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
 }
Exemplo n.º 7
0
 // For backward compatibility with template`
 $arLesson['ID'] = $arLesson['LESSON_ID'];
 // Resolve links "?COURSE_ID={SELF}". Don't relay on it, this behaviour
 // can be changed in future without any notifications.
 if (isset($arLesson['DETAIL_TEXT'])) {
     $arLesson['DETAIL_TEXT'] = CLearnHelper::PatchLessonContentLinks($arLesson['DETAIL_TEXT'], $arParams['COURSE_ID']);
 }
 if (isset($arLesson['PREVIEW_TEXT'])) {
     $arLesson['PREVIEW_TEXT'] = CLearnHelper::PatchLessonContentLinks($arLesson['PREVIEW_TEXT'], $arParams['COURSE_ID']);
 }
 //arResult
 $arResult = array("LESSON" => $arLesson, "QUESTIONS" => array(), "QUESTIONS_COUNT" => 0, "ERROR_MESSAGE" => "");
 //Questions
 $obquestion = CLQuestion::GetList($arOrder = array("SORT" => "ASC", "ID" => "ASC"), $arFilter = array("LESSON_ID" => $arParams["LESSON_ID"], "ACTIVE" => "Y", "SELF" => "Y", 'CHECK_PERMISSIONS' => 'N'));
 while ($arQuestion = $obquestion->GetNext()) {
     $obanswer = CLAnswer::GetList(array("SORT" => "ASC"), array("QUESTION_ID" => $arQuestion["ID"]));
     // Resolve links "?COURSE_ID={SELF}". Don't relay on it, this behaviour
     // can be changed in future without any notifications.
     if (isset($arQuestion['DESCRIPTION'])) {
         $arQuestion['DESCRIPTION'] = CLearnHelper::PatchLessonContentLinks($arQuestion['DESCRIPTION'], $arParams['COURSE_ID']);
     }
     $arQuestion["FILE"] = CFile::GetFileArray($arQuestion["FILE_ID"]);
     $arQuestion["ANSWERS"] = array();
     while ($arAnswer = $obanswer->GetNext()) {
         $arQuestion["ANSWERS"][] = $arAnswer;
     }
     if ($arQuestion["QUESTION_TYPE"] == "R") {
         $arQuestion["ANSWERS_ORIGINAL"] = $arQuestion["ANSWERS"];
         shuffle($arQuestion["ANSWERS"]);
     }
     $arResult["QUESTIONS"][] = $arQuestion;
Exemplo n.º 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;
	}
Exemplo n.º 9
0
                if ($arResult["NAV"]["END_PAGE"] - $arParams["PAGE_WINDOW"] + 1 >= 1) {
                    $arResult["NAV"]["START_PAGE"] = $arResult["NAV"]["END_PAGE"] - $arParams["PAGE_WINDOW"] + 1;
                }
            }
            $rsQuestion = CLQuestion::GetList(array(), array("ID" => $arResult["QBAR"][$arResult["NAV"]["PAGE_NUMBER"]]["QUESTION_ID"]));
            $arResult["QUESTION"] = $rsQuestion->GetNext();
            // Resolve links "?COURSE_ID={SELF}". Don't relay on it, this behaviour
            // can be changed in future without any notifications.
            if (isset($arResult["QUESTION"]['DESCRIPTION'])) {
                $arResult["QUESTION"]['DESCRIPTION'] = CLearnHelper::PatchLessonContentLinks($arResult["QUESTION"]['DESCRIPTION'], $arParams['COURSE_ID']);
            }
            $arResult["QUESTION"]["FILE"] = CFile::GetFileArray($arResult["QUESTION"]["FILE_ID"]);
            //Answers
            $arResult["QUESTION"]["ANSWERS"] = array();
            $arSort = $arTest["RANDOM_ANSWERS"] == "Y" || $arResult["QUESTION"]["QUESTION_TYPE"] == "R" ? array("RAND" => "RAND", "SORT" => "ASC") : array("SORT" => "ASC");
            $rsAnswer = CLAnswer::GetList($arSort, array("QUESTION_ID" => $arResult["QUESTION"]["ID"]));
            while ($arAnswer = $rsAnswer->GetNext()) {
                $arResult["QUESTION"]["ANSWERS"][] = $arAnswer;
            }
        }
    }
    $arResult["SAFE_REDIRECT_PAGE"] = htmlspecialcharsbx($arResult["REDIRECT_PAGE"]);
}
$linkedLessonId = CCourse::CourseGetLinkedLesson($arResult['TEST']['COURSE_ID']);
$bCanEdit = $linkedLessonId !== false && (CLearnAccessMacroses::CanUserEditLesson(array('lesson_id' => $linkedLessonId)) || $USER->IsAdmin());
if ($bCanEdit) {
    $deleteReturnUrl = "";
    if ($parent = $this->GetParent()) {
        $deleteReturnUrl = CComponentEngine::MakePathFromTemplate($parent->arResult["URL_TEMPLATES"]["test.list"], array("COURSE_ID" => $arResult["TEST"]["COURSE_ID"]));
    }
    $arAreaButtons = array(array("TEXT" => GetMessage("LEARNING_COURSES_TEST_EDIT"), "TITLE" => GetMessage("LEARNING_COURSES_TEST_EDIT"), "URL" => 'javascript:' . $APPLICATION->GetPopupLink(array("URL" => "/bitrix/admin/learn_test_edit.php?lang=" . LANGUAGE_ID . "&ID=" . $arResult["TEST"]["ID"] . "&COURSE_ID=" . $arResult["TEST"]["COURSE_ID"] . "&bxpublic=Y&from_module=learning", "PARAMS" => array("width" => 700, 'height' => 500, 'resize' => false))), "ICON" => "bx-context-toolbar-edit-icon", "ID" => "bx-context-toolbar-edit-test"), array("TEXT" => GetMessage("LEARNING_COURSES_TEST_DELETE"), "TITLE" => GetMessage("LEARNING_COURSES_TEST_DELETE"), "URL" => "javascript:if(confirm('" . GetMessage("LEARNING_COURSES_TEST_DELETE_CONF") . "'))jsUtils.Redirect([], '" . CUtil::JSEscape("/bitrix/admin/learn_test_admin.php?ID=" . $arParams["TEST_ID"] . "&action=delete&lang=" . LANGUAGE_ID . "&" . bitrix_sessid_get() . "&COURSE_ID=" . $arParams["COURSE_ID"]) . (strlen($deleteReturnUrl) ? "&return_url=" . urlencode($deleteReturnUrl) : "") . "')", "ICON" => "bx-context-toolbar-delete-icon", "ID" => "bx-context-toolbar-delete-test"), array("SEPARATOR" => "Y"));
Exemplo n.º 10
0
$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
while ($arRes = $rsData->NavNext(true, "f_")) {
    $arRes['RESPONSE_TEXT'] = '';
    $result = CLQuestion::GetByID($arRes['QUESTION_ID']);
    $arData = $result->Fetch();
    if ($arData['QUESTION_TYPE'] === 'T') {
        $arRes['RESPONSE_TEXT'] = $arRes['RESPONSE'];
    } elseif (!empty($arRes['RESPONSE'])) {
        $arResponseIDs = explode(',', $arRes['RESPONSE']);
        foreach ($arResponseIDs as $responseID) {
            $rsResponse = CLAnswer::GetByID((int) $responseID);
            $arResponseData = $rsResponse->GetNext();
            if (strlen($arRes['RESPONSE_TEXT']) > 0) {
                $arRes['RESPONSE_TEXT'] .= '<hr>';
            }
            $arRes['RESPONSE_TEXT'] .= $arResponseData['ANSWER'];
        }
    }
    $row =& $lAdmin->AddRow($f_ID, $arRes);
    /*
    	if (!$row->bEditMode && $f_ANSWERED=="Y" && $f_POINT == 0  )
    $row->AddViewField("POINT","<div class=\"learning-wrong-answer\">".$f_POINT."</div>");
    	else
    $row->AddInputField("POINT", Array("size"=>"3"));
    */
    $row->AddInputField("POINT", array("size" => "3"));
                break;
        }
    }
}
// fetch data
$rsData = CLQuestion::GetList(array($by => $order), $arFilter, true);
$rsData = new CAdminResult($rsData, $sTableID);
$rsData->NavStart();
// navigation string setup
$lAdmin->NavText($rsData->GetNavPrint(GetMessage("LEARNING_QUESTION")));
// list header
$lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "id", "default" => true), array("id" => "ACTIVE", "content" => GetMessage('LEARNING_COURSE_ADM_ACT'), "sort" => "active", "default" => true), array("id" => "TIMESTAMP_X", "content" => GetMessage('LEARNING_COURSE_ADM_DATECH'), "sort" => "timestamp_x", "default" => true), array("id" => "NAME", "content" => GetMessage('LEARNING_NAME'), "sort" => "name", "default" => true), array("id" => "SORT", "content" => GetMessage('LEARNING_COURSE_ADM_SORT'), "sort" => "sort", "default" => true), array("id" => "SELF", "content" => GetMessage('LEARNING_QUESTION_ADM_SELF'), "sort" => "self", "default" => true), array("id" => "CORRECT_REQUIRED", "content" => GetMessage('LEARNING_QUESTION_ADM_REQUIRED'), "sort" => "correct_required", "default" => true), array("id" => "QUESTION_TYPE", "content" => GetMessage('LEARNING_QUESTION_ADM_TYPE'), "sort" => "type", "default" => true), array("id" => "POINT", "content" => GetMessage('LEARNING_QUESTION_ADM_POINT'), "sort" => "point", "default" => true), array("id" => "ANSWERS_STATS", "content" => GetMessage('LEARNING_QUESTION_ADM_STATS'), "default" => true)));
// building list
while ($arRes = $rsData->NavNext(true, "f_")) {
    $row =& $lAdmin->AddRow($f_ID, $arRes);
    $arStat = CLAnswer::GetStats($f_ID);
    $row->AddCheckField("SELF");
    $row->AddCheckField("ACTIVE");
    $row->AddCheckField("CORRECT_REQUIRED");
    $row->AddInputField("NAME", array("size" => "35"));
    $row->AddInputField("SORT", array("size" => "3"));
    $row->AddInputField("POINT", array("size" => "3"));
    $row->AddViewField("QUESTION_TYPE", '<div title="' . GetMessage("LEARNING_QUESTION_TYPE_" . $f_QUESTION_TYPE) . '" class="learning-question-' . strtolower($f_QUESTION_TYPE) . '"></div>');
    $index = '-';
    if ($arStat["ALL_CNT"] > 0.1) {
        $index = 100 * ($arStat["CORRECT_CNT"] / $arStat["ALL_CNT"]);
        $index = round($index, 1);
        $index = sprintf("%03.1f", $index) . '%';
    }
    $row->AddViewField("ANSWERS_STATS", $index . ' (<a href="learn_test_result_admin.php?lang=' . LANG . '&set_filter=Y&filter_correct=Y&filter_answered=Y">' . $arStat["CORRECT_CNT"] . '</a> / <a href="learn_test_result_admin.php?lang=' . LANG . '">' . $arStat["ALL_CNT"] . '</a>)');
    $arActions = array();
$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
while ($arRes = $rsData->NavNext(true, "f_")) {
    $result = CLQuestion::GetByID($arRes['QUESTION_ID']);
    $arData = $result->Fetch();
    if ($arData['QUESTION_TYPE'] === 'T') {
        $arRes['RESPONSE_TEXT'] = $arRes['RESPONSE'];
    } else {
        $arResponseIDs = explode(',', $arRes['RESPONSE']);
        $arRes['RESPONSE_TEXT'] = '';
        foreach ($arResponseIDs as $responseID) {
            $rsResponse = CLAnswer::GetByID($responseID);
            $arResponseData = $rsResponse->Fetch();
            if (strlen($arRes['RESPONSE_TEXT']) > 0) {
                $arRes['RESPONSE_TEXT'] .= '<hr>';
            }
            $arRes['RESPONSE_TEXT'] .= $arResponseData['ANSWER'];
        }
    }
    $row =& $lAdmin->AddRow($f_ID, $arRes);
    /*
    	if (!$row->bEditMode && $f_ANSWERED=="Y" && $f_POINT == 0  )
    $row->AddViewField("POINT","<div class=\"learning-wrong-answer\">".$f_POINT."</div>");
    	else
    $row->AddInputField("POINT", Array("size"=>"3"));
    */
    $row->AddInputField("POINT", array("size" => "3"));