function saveAssessment($id_assessment, $assessment_data)
 {
     if ($id_assessment == 0) {
         // create the course
         $course_info = array('code' => $assessment_data['code'], 'name' => $assessment_data['name'], 'description' => $assessment_data['description'], 'lang_code' => getLanguage(), 'course_type' => $this->courseType(), 'show_rules' => 2, 'status' => 2, 'direct_play' => 1);
         $id_course = $this->man_course->addCourse($course_info);
         if ($id_course == false) {
             return false;
         }
         $level_idst =& DoceboCourse::createCourseLevel($id_course);
         if ($level_idst == false) {
             return false;
         }
         $id_main = $this->man_course->addMainToCourse($id_course, Lang::t('_PREASSESSMENT_MENU', 'preassessment', 'framework'));
         if ($id_main == false) {
             return false;
         }
         $re = true;
         $perm = array();
         $perm['7'] = array('view');
         $perm['6'] = array('view');
         $perm['3'] = array('view');
         $re &= $this->man_course->addModuleToCourse($id_course, $level_idst, $id_main, false, 'organization', 'organization', $perm);
         $perm = array();
         $perm['7'] = array('view', 'home', 'lesson', 'public');
         $perm['6'] = array('view', 'home', 'lesson', 'public');
         $re &= $this->man_course->addModuleToCourse($id_course, $level_idst, $id_main, false, 'storage', 'display', $perm);
         $perm = array();
         $perm['7'] = array('view', 'mod');
         $perm['6'] = array('view', 'mod');
         $re &= $this->man_course->addModuleToCourse($id_course, $level_idst, $id_main, false, 'coursereport', 'coursereport', $perm);
         //after creating the assessment course, create directly the test LO
         if ($re) {
             $query = "INSERT INTO %lms_test ( author, title, description ) VALUES " . "( '" . Docebo::user()->getIdSt() . "', '" . $assessment_data['name'] . "', '' )";
             if (!sql_query($query)) {
                 //...
                 return false;
             }
             $id_test = sql_insert_id();
             if ($id_test) {
                 require_once _lms_ . '/modules/organization/orglib.php';
                 $odb = new OrgDirDb($id_course);
                 $odb->addItem(0, $assessment_data['name'], 'test', $id_test, '0', '0', getLogUserId(), '1.0', '_DIFFICULT_MEDIUM', '', '', '', '', date('Y-m-d H:i:s'));
             } else {
                 //...
                 return false;
             }
         }
         return $re;
     } else {
         // modify the course
         $course_info = array('code' => $assessment_data['code'], 'name' => $assessment_data['name'], 'description' => $assessment_data['description']);
         return $this->man_course->saveCourse($id_assessment, $course_info);
     }
 }
Exemple #2
0
function exportquest(&$url)
{
    require_once _lms_ . '/lib/lib.quest_bank.php';
    $lang =& DoceboLanguage::createInstance('test');
    $qb_man = new QuestBankMan();
    $file_format = Get::pReq('export_quest_select', DOTY_INT, 0);
    $quest_category = Get::pReq('quest_category', DOTY_INT);
    $quest_difficult = Get::pReq('quest_difficult', DOTY_INT);
    $quest_type = Get::pReq('quest_type', DOTY_ALPHANUM);
    $quest_selection = Get::req('selected_quest', DOTY_NUMLIST, '');
    $quest_selection = array_filter(preg_split('/,/', $quest_selection, -1, PREG_SPLIT_NO_EMPTY));
    if ($file_format == -1) {
        $new_test_step = Get::pReq('new_test_step', DOTY_INT);
        if (Get::req('button_undo', DOTY_MIXED, false) !== false) {
            questbank($url);
            return;
        }
        if ($new_test_step == 2) {
            $title = trim($_POST['title']);
            if ($title == '') {
                $title = $lang->def('_NOTITLE');
            }
            if (is_array($quest_selection) && !empty($quest_selection)) {
                //Insert the test
                $ins_query = "\r\n\t\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_test\r\n\t\t\t\t( author, title, description )\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t( '" . (int) getLogUserId() . "', '" . $title . "', '" . $_POST['textof'] . "' )";
                //TODO:
                if (!mysql_query($ins_query)) {
                    $_SESSION['last_error'] = $lang->def('_OPERATION_FAILURE');
                }
                list($id_test) = sql_fetch_row(sql_query("SELECT LAST_INSERT_ID()"));
                if ($id_test) {
                    //Insert the question for the test
                    $reQuest = sql_query("\r\n\t\t\t\t\tSELECT q.idQuest, q.type_quest, t.type_file, t.type_class\r\n\t\t\t\t\tFROM " . $GLOBALS['prefix_lms'] . "_testquest AS q JOIN " . $GLOBALS['prefix_lms'] . "_quest_type AS t\r\n\t\t\t\t\tWHERE q.idQuest IN (" . implode(',', $quest_selection) . ") AND q.type_quest = t.type_quest");
                    while (list($idQuest, $type_quest, $type_file, $type_class) = sql_fetch_row($reQuest)) {
                        require_once _lms_ . '/modules/question/' . $type_file;
                        $quest_obj = new $type_class($idQuest);
                        $new_id = $quest_obj->copy($id_test);
                    }
                    //Adding the item to the tree
                    require_once _lms_ . '/modules/organization/orglib.php';
                    $odb = new OrgDirDb($_SESSION['idCourse']);
                    $odb->addItem(0, $title, 'test', $id_test, '0', '0', getLogUserId(), '1.0', '_DIFFICULT_MEDIUM', '', '', '', '', date('Y-m-d H:i:s'));
                }
            }
            questbank($url);
        } else {
            if (is_array($quest_selection) && !empty($quest_selection)) {
                require_once _lib_ . '/lib.form.php';
                cout(getTitleArea($lang->def('_QUEST_BANK', 'menu_course')) . '<div class="std_block yui-skin-docebo yui-skin-sam">', 'content');
                $form = new Form();
                cout($form->openForm('search_form', $url->getUrl(), false, 'POST') . $form->getHidden('new_test_step', 'new_test_step', '2') . $form->getHidden('export_quest', 'export_quest', $lang->def('_EXPORT')) . $form->getHidden('export_quest_select', 'export_quest_select', $file_format) . $form->getHidden('quest_category', 'quest_category', $quest_category) . $form->getHidden('quest_difficult', 'quest_difficult', $quest_difficult) . $form->getHidden('quest_type', 'quest_type', $quest_type) . $form->getHidden('selected_quest', 'selected_quest', $_POST['selected_quest']) . $form->openElementSpace() . $form->getTextfield($lang->def('_TITLE'), 'title', 'title', '255') . $form->getTextarea($lang->def('_DESCRIPTION'), 'textof', 'textof') . $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('button_ins', 'button_ins', $lang->def('_TEST_INSERT')) . $form->getButton('button_undo', 'button_undo', $lang->def('_UNDO')) . $form->closeButtonSpace() . $form->closeForm(), 'content');
            } else {
                $_SESSION['last_error'] = $lang->def('_EMPTY_SELECTION');
                questbank($url);
            }
        }
    } else {
        $quests = $qb_man->getQuestFromId($quest_selection);
        $quest_export = $qb_man->export_quest($quests, $file_format);
        require_once _lib_ . '/lib.download.php';
        sendStrAsFile($quest_export, 'export_' . date("Y-m-d") . '.txt');
    }
}