Example #1
0
 function CheckFields(&$arFields, $ID = false)
 {
     global $DB;
     $arMsg = array();
     if ((is_set($arFields, "ANSWER") || $ID === false) && strlen(trim($arFields["ANSWER"])) <= 0) {
         $arMsg[] = array("id" => "NAME", "text" => GetMessage("LEARNING_BAD_NAME"));
     }
     if ($ID === false && !is_set($arFields, "QUESTION_ID") || is_set($arFields, "QUESTION_ID") && intval($arFields["QUESTION_ID"]) < 1) {
         $arMsg[] = array("id" => "QUESTION_ID", "text" => GetMessage("LEARNING_BAD_QUESTION_ID"));
     } elseif (is_set($arFields, "QUESTION_ID")) {
         $res = CLQuestion::GetByID($arFields["QUESTION_ID"]);
         if (!($arRes = $res->Fetch())) {
             $arMsg[] = array("id" => "QUESTION_ID", "text" => GetMessage("LEARNING_BAD_QUESTION_ID"));
         }
     }
     if (!empty($arMsg)) {
         $e = new CAdminException($arMsg);
         $GLOBALS["APPLICATION"]->ThrowException($e);
         return false;
     }
     if (is_set($arFields, "CORRECT") && $arFields["CORRECT"] != "Y") {
         $arFields["CORRECT"] = "N";
     }
     return true;
 }
Example #2
0
 public static function CheckFields(&$arFields, $ID = false)
 {
     global $DB, $APPLICATION;
     if ($ID === false) {
         if (is_set($arFields, "ATTEMPT_ID")) {
             $r = CTestAttempt::GetByID($arFields["ATTEMPT_ID"]);
             if (!$r->Fetch()) {
                 $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_ATTEMPT_ID_EX"), "ERROR_NO_ATTEMPT_ID");
                 return false;
             }
         } else {
             $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_ATTEMPT_ID"), "EMPTY_ATTEMPT_ID");
             return false;
         }
         if (is_set($arFields, "QUESTION_ID")) {
             $r = CLQuestion::GetByID($arFields["QUESTION_ID"]);
             if (!$r->Fetch()) {
                 $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_QUESTION_ID"), "EMPTY_QUESTION_ID");
                 return false;
             }
         } else {
             $APPLICATION->ThrowException(GetMessage("LEARNING_BAD_QUESTION_ID"), "EMPTY_QUESTION_ID");
             return false;
         }
     }
     if (is_set($arFields, "RESPONSE") && is_array($arFields["RESPONSE"])) {
         $s = "";
         foreach ($arFields["RESPONSE"] as $val) {
             $s .= $val . ",";
         }
         $arFields["RESPONSE"] = substr($s, 0, -1);
     }
     /*
     if (is_set($arFields, "ANSWERED") && is_set($arFields, "RESPONSE"))
     {
     	if ($arFields["ANSWERED"]=="Y" && strlen($arFields["RESPONSE"]) <= 0)
     	{
     		$APPLICATION->ThrowException(GetMessage("LEARNING_BAD_NO_ANSWERS"), "EMPTY_ANSWERS");
     		return false;
     	}
     }
     */
     if (is_set($arFields, "CORRECT") && $arFields["CORRECT"] != "Y") {
         $arFields["CORRECT"] = "N";
     }
     return true;
 }
Example #3
0
 }
 //Images
 $arChapter["PREVIEW_PICTURE_ARRAY"] = CFile::GetFileArray($arChapter["PREVIEW_PICTURE"]);
 $arChapter["DETAIL_PICTURE_ARRAY"] = CFile::GetFileArray($arChapter["DETAIL_PICTURE"]);
 // Resolve links "?COURSE_ID={SELF}". Don't relay on it, this behaviour
 // can be changed in future without any notifications.
 if (isset($arChapter['DETAIL_TEXT'])) {
     $arChapter['DETAIL_TEXT'] = CLearnHelper::PatchLessonContentLinks($arChapter['DETAIL_TEXT'], $arParams['COURSE_ID']);
 }
 if (isset($arChapter['PREVIEW_TEXT'])) {
     $arChapter['PREVIEW_TEXT'] = CLearnHelper::PatchLessonContentLinks($arChapter['PREVIEW_TEXT'], $arParams['COURSE_ID']);
 }
 // Self test page URL
 $arChapter["SELF_TEST_URL"] = CComponentEngine::MakePathFromTemplate($arParams["SELF_TEST_TEMPLATE"], array("LESSON_ID" => $arParams["CHAPTER_ID"], "SELF_TEST_ID" => $arParams["CHAPTER_ID"], "COURSE_ID" => $arParams["COURSE_ID"]));
 //Self test exists?
 $rsQuestion = CLQuestion::GetList(array(), array("LESSON_ID" => $arParams["CHAPTER_ID"], "ACTIVE" => "Y", "SELF" => "Y"));
 $arChapter["SELF_TEST_EXISTS"] = (bool) $rsQuestion->Fetch();
 $arResult = array("COURSE" => $arCourse, "CHAPTER" => $arChapter, "CONTENTS" => array());
 //Included chapters and lessons
 $rsContent = CCourse::GetCourseContent($arParams["COURSE_ID"], array());
 $foundChapter = false;
 while ($arContent = $rsContent->GetNext()) {
     if ($foundChapter) {
         if ($arContent["DEPTH_LEVEL"] <= $baseDepthLevel) {
             break;
         }
         $arContent["DEPTH_LEVEL"] -= $baseDepthLevel;
         if ($arContent["TYPE"] == "CH") {
             $arContent["URL"] = CComponentEngine::MakePathFromTemplate($arParams["CHAPTER_DETAIL_TEMPLATE"], array("CHAPTER_ID" => '0' . $arContent["ID"], "COURSE_ID" => $arParams["COURSE_ID"]));
         } else {
             $arContent["URL"] = CComponentEngine::MakePathFromTemplate($arParams["LESSON_DETAIL_TEMPLATE"], array("LESSON_ID" => $arContent["ID"], "COURSE_ID" => $arParams["COURSE_ID"]));
    } else {
        $bBadCourse = true;
    }
}
$aTabs = array(array("DIV" => "edit1", "TAB" => GetMessage("LEARNING_ADMIN_TAB1"), "ICON" => "main_user_edit", "TITLE" => GetMessage("LEARNING_ADMIN_TAB1_EX")), array("DIV" => "edit2", "TAB" => GetMessage("LEARNING_ADMIN_TAB2"), "ICON" => "main_user_edit", "TITLE" => GetMessage("LEARNING_ADMIN_TAB2_EX")), array("DIV" => "edit3", "TAB" => GetMessage("LEARNING_ADMIN_TAB3"), "ICON" => "main_user_edit", "TITLE" => GetMessage("LEARNING_ADMIN_TAB3_EX")));
$aTabs[] = $USER_FIELD_MANAGER->EditFormTab('LEARNING_QUESTIONS');
$tabControl = new CAdminForm("questionTabControl", $aTabs);
if (!$bBadCourse && $_SERVER["REQUEST_METHOD"] == "POST" && strlen($Update) > 0 && check_bitrix_sessid()) {
    $arFILE_ID = $_FILES["FILE_ID"];
    $arFILE_ID["del"] = ${"FILE_ID_del"};
    $arFILE_ID["MODULE_ID"] = "learning";
    $arFILE_ID["description"] = ${"FILE_ID_descr"};
    if ($NEW_LESSON_ID !== false) {
        $LESSON_ID = $NEW_LESSON_ID;
    }
    $cq = new CLQuestion();
    $arFields = array("LESSON_ID" => $LESSON_ID, "NAME" => $NAME, "QUESTION_TYPE" => $QUESTION_TYPE, "SORT" => $SORT, "SELF" => $SELF, "ACTIVE" => $ACTIVE, "CORRECT_REQUIRED" => $CORRECT_REQUIRED, "POINT" => $POINT, "FILE_ID" => $arFILE_ID, "DESCRIPTION" => $DESCRIPTION, "DESCRIPTION_TYPE" => $DESCRIPTION_TYPE, "INCORRECT_MESSAGE" => $INCORRECT_MESSAGE, "COMMENT_TEXT" => $COMMENT_TEXT, "EMAIL_ANSWER" => $EMAIL_ANSWER, "~TIMESTAMP_X" => $DB->CurrentTimeFunction());
    $USER_FIELD_MANAGER->EditFormAddFields('LEARNING_QUESTIONS', $arFields);
    if ($ID > 0) {
        $res = $cq->Update($ID, $arFields);
    } else {
        // check, that default answer selected
        if ($QUESTION_TYPE === 'S' && !isset($_POST['ANSWER_CORRECT'])) {
            $res = false;
            $message = new CAdminMessage(array('MESSAGE' => GetMessage("LEARNING_ERROR"), 'TYPE' => 'ERROR', 'DETAILS' => GetMessage('LEARNING_ADD_RIGHT_ANSWER_NOT_SELECTED'), 'HTML' => false));
        } else {
            $ID = $cq->Add($arFields);
            $res = $ID > 0;
        }
    }
    if (!$res) {
Example #5
0
 public static final function Delete($lesson_id)
 {
     global $USER_FIELD_MANAGER;
     list($lesson_id, $simulate, $check_permissions, $user_id) = self::_funcDelete_ParseOptions($lesson_id);
     if ($check_permissions) {
         $oAccess = CLearnAccess::GetInstance($user_id);
         if (!$oAccess->IsLessonAccessible($lesson_id, CLearnAccess::OP_LESSON_REMOVE)) {
             throw new LearnException('EA_ACCESS_DENIED', LearnException::EXC_ERR_ALL_ACCESS_DENIED);
         }
     }
     // Parents and childs of the lesson
     $arNeighboursEdges = self::ListImmediateNeighbours($lesson_id);
     // precache rights for lesson
     if ($check_permissions) {
         $IsLessonAccessibleFor_OP_LESSON_UNLINK_DESCENDANTS = $oAccess->IsLessonAccessible($lesson_id, CLearnAccess::OP_LESSON_UNLINK_DESCENDANTS);
         $IsLessonAccessibleFor_OP_LESSON_UNLINK_FROM_PARENTS = $oAccess->IsLessonAccessible($lesson_id, CLearnAccess::OP_LESSON_UNLINK_FROM_PARENTS);
     }
     foreach (GetModuleEvents('learning', 'OnBeforeLessonDelete', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($lesson_id));
     }
     foreach ($arNeighboursEdges as $arEdge) {
         $child_lesson_id = (int) $arEdge['CHILD_LESSON'];
         $parent_lesson_id = (int) $arEdge['PARENT_LESSON'];
         if ($check_permissions) {
             $IsLessonAccessible = false;
             if ($child_lesson_id === $lesson_id) {
                 // if we will be remove edge to parent - use precached rights for OP_LESSON_UNLINK_FROM_PARENTS
                 $IsLessonAccessible = $IsLessonAccessibleFor_OP_LESSON_UNLINK_FROM_PARENTS && $oAccess->IsLessonAccessible($parent_lesson_id, CLearnAccess::OP_LESSON_UNLINK_DESCENDANTS);
             } elseif ($parent_lesson_id === $lesson_id) {
                 // if we will be remove edge to child - use precached rights for OP_LESSON_UNLINK_DESCENDANTS
                 $IsLessonAccessible = $IsLessonAccessibleFor_OP_LESSON_UNLINK_DESCENDANTS && $oAccess->IsLessonAccessible($child_lesson_id, CLearnAccess::OP_LESSON_UNLINK_FROM_PARENTS);
             } else {
                 throw new LearnException('EA_FATAL: $lesson_id (' . $lesson_id . ') not equal to one of: $child_lesson_id (' . $child_lesson_id . '), $parent_lesson_id (' . $parent_lesson_id . ')', LearnException::EXC_ERR_ALL_LOGIC | LearnException::EXC_ERR_ALL_GIVEUP);
             }
             if (!$IsLessonAccessible) {
                 throw new LearnException('EA_ACCESS_DENIED', LearnException::EXC_ERR_ALL_ACCESS_DENIED);
             }
             if ($simulate === false) {
                 self::RelationRemove($parent_lesson_id, $child_lesson_id);
             }
         }
     }
     $linkedCourseId = self::GetLinkedCourse($lesson_id);
     // If lesson is course, remove course
     if ($linkedCourseId !== false) {
         global $DB;
         if ($simulate === false) {
             if (!$DB->Query("DELETE FROM b_learn_course_site WHERE COURSE_ID = " . (int) $linkedCourseId, true)) {
                 throw new LearnException('EA_SQLERROR', LearnException::EXC_ERR_ALL_GIVEUP);
             }
             $rc = self::CourseBecomeLesson($linkedCourseId);
             // if course cannot be converted to lesson - don't remove lesson
             if ($rc === false) {
                 throw new LearnException('EA_OTHER: lesson is unremovable because linked course is in use.', LearnException::EXC_ERR_LL_UNREMOVABLE_CL);
             }
             // reload cache of LINKED_LESSON_ID -> COURSE_ID
             self::GetCourseToLessonMap_ReloadCache();
             if (CModule::IncludeModule("search")) {
                 CSearch::DeleteIndex("learning", false, "C" . $linkedCourseId);
                 CSearch::DeleteIndex("learning", "C" . $linkedCourseId);
             }
         }
     }
     // And remove lesson
     if ($simulate === false) {
         global $DB;
         $r = $DB->Query("SELECT PREVIEW_PICTURE, DETAIL_PICTURE \n\t\t\t\tFROM b_learn_lesson \n\t\t\t\tWHERE ID = " . (int) $lesson_id, true);
         if ($r === false) {
             throw new LearnException('EA_SQLERROR', LearnException::EXC_ERR_ALL_GIVEUP);
         }
         $arRes = $r->Fetch();
         if (!$arRes) {
             throw new LearnException('EA_SQLERROR', LearnException::EXC_ERR_ALL_GIVEUP);
         }
         CFile::Delete($arRes['PREVIEW_PICTURE']);
         CFile::Delete($arRes['DETAIL_PICTURE']);
         // Remove questions
         $q = CLQuestion::GetList(array(), array('LESSON_ID' => $lesson_id));
         while ($arQ = $q->Fetch()) {
             if (!CLQuestion::Delete($arQ['ID'])) {
                 throw new LearnException('EA_QUESTION_NOT_REMOVED', LearnException::EXC_ERR_ALL_GIVEUP);
             }
         }
         CLearnGraphNode::Remove($lesson_id);
         $USER_FIELD_MANAGER->delete('LEARNING_LESSONS', $lesson_id);
         CLearnCacheOfLessonTreeComponent::MarkAsDirty();
         CEventLog::add(array('AUDIT_TYPE_ID' => 'LEARNING_REMOVE_ITEM', 'MODULE_ID' => 'learning', 'ITEM_ID' => 'L #' . $lesson_id, 'DESCRIPTION' => 'lesson removed'));
         if (CModule::IncludeModule('search')) {
             CSearch::DeleteIndex('learning', false, 'L' . $lesson_id);
             CSearch::DeleteIndex('learning', 'L' . $lesson_id);
         }
     }
     if ($simulate === false) {
         foreach (GetModuleEvents('learning', 'OnAfterLessonDelete', true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array($lesson_id));
         }
     }
 }
Example #6
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());
         }
     }
 }
                    }
                }
                break;
            case "activate":
            case "deactivate":
                $cl = new CLQuestion();
                $arFields = array("ACTIVE" => $_REQUEST['action'] == "activate" ? "Y" : "N");
                if (!$cl->Update($ID, $arFields)) {
                    if ($e = $APPLICATION->GetException()) {
                        $lAdmin->AddGroupError(GetMessage("SAVE_ERROR") . $ID . ": " . $e->GetString(), $ID);
                    }
                }
                break;
            case "required":
            case "derequired":
                $cl = new CLQuestion();
                $arFields = array("CORRECT_REQUIRED" => $_REQUEST['action'] == "required" ? "Y" : "N");
                if (!$cl->Update($ID, $arFields)) {
                    if ($e = $APPLICATION->GetException()) {
                        $lAdmin->AddGroupError(GetMessage("SAVE_ERROR") . $ID . ": " . $e->GetString(), $ID);
                    }
                }
                break;
        }
    }
}
// fetch data
if (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "excel") {
    $arNavParams = array();
} else {
    $arNavParams = array('nPageSize' => CAdminResult::GetNavSize($sTableID));
Example #8
0
 /**
  * <p>Метод возвращает количество вопросов по заданному фильтру.</p>
  *
  *
  * @param array $arrayarFilter = Array() Массив вида <i> array("фильтруемое поле"=&gt;"значение фильтра" [, ...])</i>.
  * Описание фильтра см. в <a
  * href="http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/getlist.php">CLQuestion::GetList</a>.<br> По
  * умолчанию вопросы не фильтруются.
  *
  * @return int <p>Число - количество вопросов.</p>
  *
  * <h4>Example</h4> 
  * <pre>
  * &lt;?
  * if (CModule::IncludeModule("learning"))
  * {
  *     $COURSE_ID = 97;
  *     
  *     $cnt = CLQuestion::GetCount(Array("ACTIVE" =&gt; "Y", "COURSE_ID" =&gt; $COURSE_ID));
  * 
  *     echo "Number of questions: ".$cnt;
  * }
  * 
  * ?&gt;
  * 
  * &lt;?
  * if (CModule::IncludeModule("learning"))
  * {
  *     $LESSON_ID = 426;
  *     
  *     $cnt = CLQuestion::GetCount(Array("LESSON_ID" =&gt; $LESSON_ID));
  * 
  *     echo "Number of questions: ".$cnt;
  * }
  * 
  * ?&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/getlist.php">GetList</a> </li> </ul><a
  * name="examples"></a>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/getcount.php
  * @author Bitrix
  */
 public static function GetCount($arFilter = array())
 {
     global $DB;
     $arSqlSearch = CLQuestion::GetFilter($arFilter);
     $strSqlSearch = "";
     $cnt = count($arSqlSearch);
     for ($i = 0; $i < $cnt; $i++) {
         if (strlen($arSqlSearch[$i]) > 0) {
             $strSqlSearch .= " AND " . $arSqlSearch[$i] . " ";
         }
     }
     $strSql = "SELECT COUNT(DISTINCT CQ.ID) as C " . "FROM b_learn_question CQ " . "INNER JOIN b_learn_lesson CL ON CQ.LESSON_ID = CL.ID " . "WHERE 1=1 " . $strSqlSearch;
     $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $res_cnt = $res->Fetch();
     return intval($res_cnt["C"]);
 }
Example #9
0
 $arLesson["PREVIEW_PICTURE_ARRAY"] = CFile::GetFileArray($arLesson["PREVIEW_PICTURE"]);
 $arLesson["DETAIL_PICTURE_ARRAY"] = CFile::GetFileArray($arLesson["DETAIL_PICTURE"]);
 // 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"]);
    public function BuildList()
    {
        global $USER;
        $filterParams = GetFilterParams('filter_');
        // list's footer
        $this->oList->AddFooter(array(array('title' => GetMessage('MAIN_ADMIN_LIST_SELECTED'), 'value' => $this->rsData->SelectedRowsCount()), array('counter' => true, 'title' => GetMessage('MAIN_ADMIN_LIST_CHECKED'), 'value' => '0')));
        $oParentPath = new CLearnPath();
        if (isset($_GET['LESSON_PATH'])) {
            $oParentPath->ImportUrlencoded($_GET['LESSON_PATH']);
        }
        $arParentPath = $oParentPath->GetPathAsArray();
        // building list
        while ($arRes = $this->rsData->NavNext(false)) {
            $oCurPath = new CLearnPath();
            $oCurPath->SetPathFromArray(array_merge($arParentPath, array($arRes['LESSON_ID'])));
            $urlCurPath = $oCurPath->ExportUrlencoded();
            unset($oCurPath);
            // PUBLISH_PROHIBITED available in context of most parent course only
            if ($this->contextCourseLessonId !== false) {
                $arRes['PUBLISH_PROHIBITED'] = 'N';
                if (CLearnLesson::IsPublishProhibited($arRes['LESSON_ID'], $this->contextCourseLessonId)) {
                    $arRes['PUBLISH_PROHIBITED'] = 'Y';
                }
            }
            $arRes['SITE_ID'] = '';
            $courseId = CLearnLesson::GetLinkedCourse($arRes['LESSON_ID']);
            if ($courseId !== false) {
                $hrefPrefix = 'learn_course_edit.php?COURSE_ID=' . $courseId;
                $resCourseSites = CCourse::GetSite($courseId);
                while ($arCourseSites = $resCourseSites->Fetch()) {
                    if ($arRes['SITE_ID'] != '') {
                        $arRes['SITE_ID'] .= ' / ';
                    }
                    $arRes['SITE_ID'] .= htmlspecialcharsbx($arCourseSites['LID']);
                }
            } else {
                $hrefPrefix = 'learn_unilesson_edit.php?LESSON_ID=' . $arRes['LESSON_ID'] . '&LESSON_PATH=' . urlencode($urlCurPath);
            }
            $actionEditLesson = $hrefPrefix . '&lang=' . LANG . $filterParams;
            $rowAction = false;
            $rowTitle = '';
            if (!$this->IsSearchMode()) {
                $rowAction = 'learn_unilesson_admin.php?lang=' . LANG . '&set_filter=Y' . '&PARENT_LESSON_ID=' . ($arRes['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurPath . '&' . $this->hrefSearchRetPoint;
                $rowTitle = GetMessage('LEARNING_TRAVERSE');
                // "Traverse list of immediate childs"
                if (!$arRes['IS_CHILDS']) {
                    $rowAction = $actionEditLesson;
                    $rowTitle = GetMessage('LEARNING_EDIT_TITLE');
                }
            }
            $row =& $this->oList->AddRow($arRes['LESSON_ID'], $arRes, $rowAction, $rowTitle);
            $arParents = $arChilds = array();
            $htmlParents = $htmlChilds = '';
            $rsParents = CLearnLesson::GetListOfImmediateParents($arRes['LESSON_ID'], array(), array('CHECK_PERMISSIONS' => 'N'));
            while ($arParent = $rsParents->Fetch()) {
                $arParents[] = $arParent['NAME'];
            }
            $arParents = array_map('htmlspecialcharsbx', $arParents);
            if (count($arParents) > 0) {
                $htmlParents = implode('<hr width="100%" size="1">', $arParents);
            } else {
                $htmlParents = '&nbsp;';
            }
            $rsChilds = CLearnLesson::GetListOfImmediateChilds($arRes['LESSON_ID'], array(), array('CHECK_PERMISSIONS' => 'N'));
            while ($arChild = $rsChilds->Fetch()) {
                $arChilds[] = $arChild['NAME'];
            }
            $arChilds = array_map('htmlspecialcharsbx', $arChilds);
            if (count($arChilds) > 0) {
                $htmlChilds = implode('<hr width="100%" size="1">', $arChilds);
            } else {
                $htmlChilds = '&nbsp;';
            }
            if (isset($arRes['LINKED_LESSON_ID']) && $arRes['LINKED_LESSON_ID'] > 0) {
                $icon = 'learning_icon_courses';
            } elseif (count($arChilds) > 0) {
                $icon = 'learning_icon_chapters';
            } else {
                $icon = 'learning_icon_lessons';
            }
            if (!$this->IsSearchMode()) {
                $row->AddViewField('NAME', '<span class="adm-list-table-icon-link"><span class="adm-submenu-item-link-icon adm-list-table-icon ' . $icon . '"></span>' . ($rowAction === false ? '<span class="adm-list-table-link">' . htmlspecialcharsbx($arRes['NAME']) . '</span>' : '<a href="' . $rowAction . '" class="adm-list-table-link">' . htmlspecialcharsbx($arRes['NAME']) . '</a>') . '</span>');
            } else {
                $actionUseLesson = "(function()\n\t\t\t\t\t{\n\t\t\t\t\t\tvar fnName = '" . str_replace(array("'", ';', ',', "\n", "\r"), '', htmlspecialcharsbx($this->search_retpoint)) . "';\n\t\t\t\t\t\tif ( ! (window.opener && window.opener[fnName]) )\n\t\t\t\t\t\t\treturn;\n\n\t\t\t\t\t\twindow.opener[fnName]('" . (int) $arRes['LESSON_ID'] . "', '" . CUtil::JSEscape(htmlspecialcharsbx($arRes['NAME'])) . "');\n\t\t\t\t\t\twindow.close();\n\t\t\t\t\t})();\n\t\t\t\t\t";
                $row->AddViewField('NAME', '<a href="javascript:void(0);" class="adm-list-table-icon-link" onclick="' . $actionUseLesson . '"><span class="adm-submenu-item-link-icon adm-list-table-icon ' . $icon . '"></span><span class="adm-list-table-link">' . htmlspecialcharsbx($arRes['NAME']) . '</span></a>');
            }
            $row->AddViewField('PARENTS', $htmlParents);
            $row->AddEditField('PARENTS', '&nbsp;');
            $row->AddViewField('CHILDS', $htmlChilds);
            $row->AddEditField('CHILDS', '&nbsp;');
            // this is very heavy statistic, so will be a good idea to add settings to the module, which turn off this statistics
            $oLearnTree = CLearnLesson::GetTree($arRes['LESSON_ID']);
            $arTree = $oLearnTree->GetTreeAsList();
            $depth = -1;
            $chapterCount = 0;
            $lessonsCount = 0;
            $questionsCount = CLQuestion::GetCount(array('LESSON_ID' => (int) $arRes['LESSON_ID']));
            foreach ($arTree as $arLessonData) {
                if ($arLessonData['IS_CHILDS']) {
                    ++$chapterCount;
                } else {
                    ++$lessonsCount;
                }
                if ((int) $arLessonData['#DEPTH_IN_TREE'] > $depth) {
                    $depth = (int) $arLessonData['#DEPTH_IN_TREE'];
                }
                $questionsCount += CLQuestion::GetCount(array('LESSON_ID' => (int) $arLessonData['LESSON_ID']));
            }
            // PUBLISH_PROHIBITED available in context of most parent course only
            if ($this->contextCourseLessonId !== false) {
                if ($this->IsLessonUpdateAccess($arRes['LESSON_ID']) === true) {
                    $row->AddInputField('PUBLISH_PROHIBITED', array('size' => '35'));
                    $row->AddCheckField('PUBLISH_PROHIBITED');
                } else {
                    $row->AddCheckField('PUBLISH_PROHIBITED', true);
                }
            }
            // Render CARDINALITY fields
            $htmlDepth = (int) ($depth + 1);
            $htmlChapters = (string) (int) $chapterCount . '&nbsp;[<a href="learn_unilesson_edit.php?lang=' . LANG . '&PROPOSE_RETURN_LESSON_PATH=' . $urlCurPath . '" title="' . GetMessage('LEARNING_UNILESSON_ADD') . '"' . '>+</a>]';
            $htmlLessons = (string) (int) $lessonsCount . '&nbsp;[<a href="learn_unilesson_edit.php?lang=' . LANG . '&PROPOSE_RETURN_LESSON_PATH=' . $urlCurPath . '" title="' . GetMessage('LEARNING_UNILESSON_ADD') . '"' . '>+</a>]';
            $htmlQuestions = '<a href="learn_question_admin.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&PARENT_LESSON_ID=' . ($arRes['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurPath . '" title="' . GetMessage('LEARNING_QUESTION_ALT') . '">' . (int) $questionsCount . '</a>' . '&nbsp;[' . '<a href="learn_question_edit.php?lang=' . LANG . '&LESSON_PATH=' . $urlCurPath . '&QUESTION_TYPE=S' . '&filter=Y&set_filter=Y' . '&from=learn_menu"' . ' title="' . GetMessage('LEARNING_QUESTION_ADD') . '">+</a>' . ']';
            $row->AddViewField('CARDINALITY_DEPTH', $htmlDepth);
            $row->AddViewField('CARDINALITY_CHAPTERS', $htmlChapters);
            $row->AddViewField('CARDINALITY_LESSONS', $htmlLessons);
            $row->AddViewField('CARDINALITY_QUESTIONS', $htmlQuestions);
            if ($courseId !== false) {
                $testsCount = (int) CTest::GetCount(array('COURSE_ID' => $courseId));
                $htmlTests = '<a href="learn_test_admin.php?lang=' . LANG . '&COURSE_ID=' . $courseId . '&PARENT_LESSON_ID=' . (int) $arRes['LESSON_ID'] . '&LESSON_PATH=' . $urlCurPath . '&filter=Y&set_filter=Y"' . '>' . $testsCount . '</a>' . '&nbsp;[<a href="learn_test_edit.php?lang=' . LANG . '&COURSE_ID=' . $courseId . '&PARENT_LESSON_ID=' . (int) $arRes['LESSON_ID'] . '&LESSON_PATH=' . $urlCurPath . '&filter=Y&set_filter=Y"
					title="' . GetMessage('LEARNING_QUESTION_ADD') . '"' . '>+</a>]';
                $row->AddViewField('CARDINALITY_TESTS', $htmlTests);
            }
            if (!$this->IsSearchMode() && $this->IsLessonUpdateAccess($arRes['LESSON_ID']) === true) {
                $row->AddInputField('NAME', array('size' => '35'));
                // SORT field editing possibly only for courses and for lessons in relation to parent lesson
                if ($this->IsListChildLessonsMode() || $this->IsListAnyCoursesMode()) {
                    $row->AddInputField('SORT', array('size' => '3'));
                }
                $row->AddCheckField('ACTIVE');
                $row->AddInputField('CODE');
            } else {
                $row->AddCheckField('ACTIVE', false);
            }
            $row->AddViewField('CREATED_USER_NAME', $arRes['CREATED_USER_NAME']);
            $arActions = array();
            if (!$this->IsSearchMode()) {
                if ($this->IsLessonUpdateAccess($arRes['LESSON_ID']) === true) {
                    $editTxt = GetMessage('MAIN_ADMIN_MENU_EDIT');
                } else {
                    $editTxt = GetMessage('MAIN_ADMIN_MENU_OPEN');
                }
                // Actions
                $arActions[] = array('ICON' => 'edit', 'TEXT' => $editTxt, 'ACTION' => $this->oList->ActionRedirect($actionEditLesson));
                $arActions[] = array("SEPARATOR" => true);
                $arActions[] = array('ICON' => 'list', 'TEXT' => GetMessage('LEARNING_QUESTION_ALT') . ' (' . ($questionsCount + 0) . ')', 'ACTION' => $this->oList->ActionRedirect('learn_question_admin.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&PARENT_LESSON_ID=' . ($arRes['LESSON_ID'] + 0) . '&LESSON_PATH=' . urlencode($urlCurPath)));
                /*
                $arActions[] = array(
                	"ICON"=>"copy",
                	"TEXT"=>GetMessage("MAIN_ADMIN_ADD_COPY"),
                	"ACTION"=>$this->oList->ActionRedirect("learn_course_edit.php?COPY_ID=".$f_ID));
                */
                $isDeleteCmdDisabled = true;
                $isDisbandCmdDisabled = true;
                $deleteMSG = '';
                $disbandMSG = '';
                $actionDisband = '';
                $action = '';
                if ($arRes['CHILDS_CNT'] > 0) {
                    $deleteMSG = GetMessage('LEARNING_ADMIN_MENU_DELETE_RECURSIVE') . ' (' . (string) (int) $arRes['CHILDS_CNT'] . ')';
                } else {
                    $deleteMSG = GetMessage("MAIN_ADMIN_MENU_DELETE");
                }
                $disbandMSG = GetMessage('LEARNING_ADMIN_MENU_DISBAND');
                $isEnoughRightsForDisbandLesson = false;
                try {
                    $this->EnsureLessonDisbandAccess($arRes['LESSON_ID']);
                    $isEnoughRightsForDisbandLesson = true;
                } catch (CLearnRenderAdminUnilessonListException $e) {
                    if ($e->GetCode() & CLearnRenderAdminUnilessonListException::C_ACCESS_DENIED) {
                    } else {
                        // bubble exception
                        throw new CLearnRenderAdminUnilessonListException($e->GetMessage(), $e->GetCode());
                    }
                }
                // If we can unlink all neighbours and remove lesson
                if ($isEnoughRightsForDisbandLesson) {
                    $arOPathes = CLearnLesson::GetListOfParentPathes($arRes['LESSON_ID']);
                    $parentPathesCnt = count($arOPathes);
                    // prepare "Disband" command
                    $isDisbandCmdDisabled = false;
                    $actionDisband = $this->oList->ActionDoGroup($arRes['LESSON_ID'], 'disband', 'PARENT_LESSON_ID=' . ($this->requestedParentLessonId + 0));
                    if ($parentPathesCnt >= 1) {
                        $actionDisband = "if(confirm('" . str_replace('#CNT#', $parentPathesCnt, GetMessageJS('LEARNING_CONFIRM_DISBAND_LESSON_WITH_PARENT_PATHES')) . "')) " . '{ ' . $actionDisband . ' }';
                    }
                    $actionDisband = "if(confirm('" . GetMessageJS('LEARNING_ADMIN_MENU_DISBAND_QUESTION') . "')) " . '{ ' . $actionDisband . ' }';
                    // prepare "Remove" command
                    $isDeleteCmdDisabled = false;
                    if ($arRes['CHILDS_CNT'] > 0) {
                        $action = $this->oList->ActionDoGroup($arRes['LESSON_ID'], 'recursive_delete', 'PARENT_LESSON_ID=' . ($this->requestedParentLessonId + 0));
                    } else {
                        // If no childs => "delete" is equal to "disband"
                        $action = $this->oList->ActionDoGroup($arRes['LESSON_ID'], 'disband', 'PARENT_LESSON_ID=' . ($this->requestedParentLessonId + 0));
                    }
                    if ($parentPathesCnt >= 1) {
                        $deleteMSG .= ' [' . $parentPathesCnt . ']';
                        $action = "if(confirm('" . str_replace('#CNT#', $parentPathesCnt, GetMessageJS("LEARNING_CONFIRM_DEL_LESSON_WITH_PARENT_PATHES")) . "')) " . $action;
                    } else {
                        $action = "if(confirm('" . GetMessageJS('LEARNING_CONFIRM_DEL_MESSAGE') . "')) " . $action;
                    }
                }
                // We can "disband" only lessons, that contains childs
                $arActions[] = array("SEPARATOR" => true);
                if ($arRes['CHILDS_CNT'] > 0) {
                    $arActions[] = array('ICON' => 'delete', 'TEXT' => $disbandMSG, 'ACTION' => $actionDisband, 'DISABLED' => $isDisbandCmdDisabled, 'TITLE' => GetMessage('LEARNING_ADMIN_MENU_DISBAND_TITLE'));
                }
                $arActions[] = array('ICON' => 'delete', 'TEXT' => $deleteMSG, 'ACTION' => $action, 'DISABLED' => $isDeleteCmdDisabled);
            } else {
                $arActions[] = array('ICON' => 'list', 'TEXT' => GetMessage('LEARNING_SELECT'), 'ACTION' => $actionUseLesson);
            }
            $row->AddActions($arActions);
        }
        return $this;
    }
Example #11
0
         }
     }
     if ($arResult["NAV"]["PAGE_NUMBER"] > floor($arParams["PAGE_WINDOW"] / 2) + 1 && $arResult["NAV"]["PAGE_COUNT"] > $arParams["PAGE_WINDOW"]) {
         $arResult["NAV"]["START_PAGE"] = $arResult["NAV"]["PAGE_NUMBER"] - floor($arParams["PAGE_WINDOW"] / 2);
     } else {
         $arResult["NAV"]["START_PAGE"] = 1;
     }
     if ($arResult["NAV"]["PAGE_NUMBER"] <= $arResult["NAV"]["PAGE_COUNT"] - floor($arParams["PAGE_WINDOW"] / 2) && $arResult["NAV"]["START_PAGE"] + $arParams["PAGE_WINDOW"] - 1 <= $arResult["NAV"]["PAGE_COUNT"]) {
         $arResult["NAV"]["END_PAGE"] = $arResult["NAV"]["START_PAGE"] + $arParams["PAGE_WINDOW"] - 1;
     } else {
         $arResult["NAV"]["END_PAGE"] = $arResult["NAV"]["PAGE_COUNT"];
         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;
     }
 }
                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
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);
Example #13
0
function __learning_admin_get_menu($THIS, $arPath = array(), $deep = 0, &$immediateChildsIds, $loadOnlySpecialEntities = false)
{
    $immediateChildsIds = array();
    // puts here ids of all immediate childs
    $deep = (int) $deep;
    // Index in path for current parentLessonId
    $indexInPath = $deep - 1;
    // Path doesn't include top root element ('all courses' or 'all unilessons')
    $arMenu = array();
    //$urlPath = $oPath->ExportUrlencoded();
    // current lesson id (not exists only for top root)
    if (isset($arPath[$deep])) {
        $currentLessonIdInPath = (int) $arPath[$deep];
    } else {
        $currentLessonIdInPath = false;
    }
    // Path to current element
    $arCurrentDeepPath = array();
    foreach ($arPath as $key => $value) {
        if ($key === $deep) {
            break;
        }
        $arCurrentDeepPath[] = $value;
    }
    if ($deep === 0) {
        // We are at the top level, so we must get list of all courses
        $CDBResult = CCourse::GetList(array('COURSE_SORT' => 'ASC'));
    } else {
        // If not parent with such indexInPath => we are deep too much.
        if (!isset($arPath[$indexInPath])) {
            return $arMenu;
        }
        // no items
        $parentLessonId = $arPath[$indexInPath];
        $oCurrentDeepPath = new CLearnPath();
        $oCurrentDeepPath->SetPathFromArray(array_merge($arCurrentDeepPath));
        $urlPath = $oCurrentDeepPath->ExportUrlencoded();
        $arMenu[] = array("text" => GetMessage("LEARNING_QUESTION"), "url" => "learn_question_admin.php?lang=" . LANG . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath . "&from=learn_menu", "icon" => "learning_icon_question", "more_url" => array("learn_question_admin.php?lang=" . LANG . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath . "&from=learn_menu", "learn_question_edit.php?lang=" . LANG . '&LESSON_PATH=' . $urlPath . "&from=learn_menu", "learn_question_admin.php?lang=" . LANG . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath, "learn_question_edit.php?lang=" . LANG . '&LESSON_PATH=' . $urlPath, "learn_question_admin.php?lang=" . LANG . '&LESSON_PATH=' . $urlPath), "title" => GetMessage("LEARNING_QUESTION_LIST"));
        $CDBResult = CLearnLesson::GetListOfImmediateChilds($parentLessonId, array('EDGE_SORT' => 'ASC'));
        // determine, is parent a course (only for courses in subroot level)?
        if ($deep === 1) {
            $immediateParentCourse = CLearnLesson::GetLinkedCourse($parentLessonId);
            if ($immediateParentCourse !== false) {
                // immediate parent is a course, so we must add entity 'Tests'
                $arMenu[] = array('text' => GetMessage('LEARNING_TESTS'), 'url' => 'learn_test_admin.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&COURSE_ID=' . ($immediateParentCourse + 0) . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath, 'icon' => 'learning_icon_tests', 'more_url' => array('learn_test_admin.php?lang=' . LANG . '&set_filter=Y' . '&COURSE_ID=' . ($immediateParentCourse + 0) . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath, 'learn_test_edit.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&COURSE_ID=' . ($immediateParentCourse + 0) . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath), 'title' => GetMessage('LEARNING_TESTS_LIST'));
                unset($urlPath);
                unset($oCurrentDeepPath);
            }
        }
    }
    if ($loadOnlySpecialEntities) {
        return $arMenu;
    }
    // When listing courses, limit it's count
    if ($deep === 0) {
        $items = 0;
        $learning_menu_max_courses = (int) COption::GetOptionString("learning", "menu_max_courses", "10");
    }
    while ($arData = $CDBResult->GetNext()) {
        // When listing courses, limit it's count
        if ($deep === 0) {
            if ($items >= $learning_menu_max_courses) {
                // add element 'other courses'
                $arMenu[] = array('text' => GetMessage('LEARNING_MENU_COURSES_OTHER'), 'url' => 'learn_unilesson_admin.php?lang=' . LANG . '&PARENT_LESSON_ID=-1', 'title' => GetMessage('LEARNING_MENU_COURSES_ALT'), 'more_url' => array('learn_test_admin.php', 'learn_test_edit.php', 'learn_unilesson_admin.php', 'learn_unilesson_edit.php', 'learn_question_admin.php', 'learn_question_edit.php'));
                // stop adding courses to menu
                break;
            }
            $items++;
        }
        $arSubImmediateChildsIds = false;
        $arCurItemPath = $arCurrentDeepPath;
        $arCurItemPath[] = $arData['LESSON_ID'] + 0;
        // Remember all immediate childs
        $immediateChildsIds[] = $arData['LESSON_ID'] + 0;
        $oCurItemPath = new CLearnPath();
        $oCurItemPath->SetPathFromArray($arCurItemPath);
        $urlCurItemPath = $oCurItemPath->ExportUrlencoded();
        $arItem = array('text' => $arData['NAME'], 'url' => 'learn_unilesson_admin.php?lang=' . LANG . '&PARENT_LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $oCurItemPath->ExportUrlencoded(), 'title' => $arData['NAME'], 'items_id' => 'menu_learning_courses_new_' . implode('_', $arCurItemPath), "icon" => "learning_icon_courses", 'module_id' => 'learning', 'more_url' => array('learn_unilesson_admin.php?lang=' . LANG . '&set_filter=Y' . '&PARENT_LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurItemPath, 'learn_unilesson_admin.php?lang=' . LANG . '&PARENT_LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurItemPath, 'learn_unilesson_admin.php?lang=' . LANG . '&set_filter=Y' . '&LESSON_PATH=' . $urlCurItemPath, 'learn_question_admin.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&LESSON_PATH=' . $urlCurItemPath, 'learn_question_edit.php?lang=' . LANG . '&set_filter=Y' . '&LESSON_PATH=' . $urlCurItemPath, 'learn_unilesson_edit.php?lang=' . LANG . '&LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurItemPath, 'learn_unilesson_edit.php?lang=' . LANG . '&PARENT_LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurItemPath));
        $arItem['items'] = array();
        if ($deep === 0 && isset($arData['LINKED_LESSON_ID']) && $arData['LINKED_LESSON_ID'] > 0) {
            $arItem['page_icon'] = $arItem['icon'] = 'learning_icon_courses';
            $arItem['dynamic'] = true;
            $loadOnlySpecialEntities = false;
            // Load child items only for lesson in current path
            if ($arData['LESSON_ID'] == $currentLessonIdInPath) {
                $arItem['items'] = __learning_admin_get_menu($THIS, $arPath, $deep + 1, $arSubImmediateChildsIds);
            }
        } else {
            $loadOnlySpecialEntities = false;
            $childsCnt = CLearnLesson::CountImmediateChilds($arData['LESSON_ID']);
            $questionsCnt = CLQuestion::GetCount(array('LESSON_ID' => (int) $arData['LESSON_ID']));
            if ($childsCnt > 0) {
                $arItem['page_icon'] = $arItem['icon'] = 'learning_icon_chapters';
            } else {
                $arItem['page_icon'] = $arItem['icon'] = 'learning_icon_lessons';
            }
            $arItem['dynamic'] = true;
            // Load child items only for lesson in current path
            if ($arData['LESSON_ID'] == $currentLessonIdInPath) {
                $arItem['items'] = __learning_admin_get_menu($THIS, $arPath, $deep + 1, $arSubImmediateChildsIds);
            }
        }
        // now, adds items into more_url (it needs when edit form for childs opened)
        if (is_array($arSubImmediateChildsIds)) {
            $oSubItemPath = new CLearnPath();
            foreach ($arSubImmediateChildsIds as $k => $v) {
                // determine path for every child
                $arSubItemPath = $arCurItemPath;
                $arSubItemPath[] = $v;
                // child id added to current path
                $oSubItemPath->SetPathFromArray($arSubItemPath);
                $arItem['more_url'][] = 'learn_unilesson_edit.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&LESSON_ID=' . ($v + 0) . '&LESSON_PATH=' . $oSubItemPath->ExportUrlencoded();
            }
            unset($oSubItemPath);
            $arSubImmediateChildsIds = false;
        }
        $arMenu[] = $arItem;
        unset($oCurItemPath, $arCurItemPath, $urlCurItemPath, $arItem);
    }
    return $arMenu;
}