public function addQuestion()
 {
     global $lng, $ilCtrl, $tpl;
     include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
     $ilCtrl->setParameter($this, 'qtype', $_REQUEST['qtype']);
     $form = new ilPropertyFormGUI();
     $ilCtrl->setParameter($this, 'test_express_mode', 1);
     $form->setFormAction($ilCtrl->getFormAction($this, "handleToolbarCommand"));
     $form->setTitle($lng->txt("ass_create_question"));
     include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
     $pool = new ilObjQuestionPool();
     $questionTypes = $pool->getQuestionTypes(false, true);
     $options = array();
     // question type
     foreach ($questionTypes as $label => $data) {
         $options[$data['question_type_id']] = $label;
     }
     include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
     $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
     $si->setOptions($options);
     $form->addItem($si, true);
     // position
     $questions = $this->test_object->getQuestionTitlesAndIndexes();
     if ($questions) {
         $si = new ilSelectInputGUI($lng->txt("position"), "position");
         $options = array('0' => $lng->txt('first'));
         foreach ($questions as $key => $title) {
             $options[$key] = $lng->txt('behind') . ' ' . $title . ' [' . $this->lng->txt('question_id_short') . ': ' . $key . ']';
         }
         $si->setOptions($options);
         $si->setValue($_REQUEST['q_id']);
         $form->addItem($si, true);
     }
     // content editing mode
     if (ilObjAssessmentFolder::isAdditionalQuestionContentEditingModePageObjectEnabled()) {
         $ri = new ilRadioGroupInputGUI($lng->txt("tst_add_quest_cont_edit_mode"), "add_quest_cont_edit_mode");
         $ri->addOption(new ilRadioOption($lng->txt('tst_add_quest_cont_edit_mode_default'), assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT));
         $ri->addOption(new ilRadioOption($lng->txt('tst_add_quest_cont_edit_mode_page_object'), assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_PAGE_OBJECT));
         $ri->setValue(assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT);
         $form->addItem($ri, true);
     } else {
         $hi = new ilHiddenInputGUI("question_content_editing_type");
         $hi->setValue(assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT);
         $form->addItem($hi, true);
     }
     if ($this->test_object->getPoolUsage()) {
         // use pool
         $usage = new ilRadioGroupInputGUI($this->lng->txt("assessment_pool_selection"), "usage");
         $usage->setRequired(true);
         $no_pool = new ilRadioOption($this->lng->txt("assessment_no_pool"), 1);
         $usage->addOption($no_pool);
         $existing_pool = new ilRadioOption($this->lng->txt("assessment_existing_pool"), 3);
         $usage->addOption($existing_pool);
         $new_pool = new ilRadioOption($this->lng->txt("assessment_new_pool"), 2);
         $usage->addOption($new_pool);
         $form->addItem($usage);
         $usage->setValue(1);
         $questionpools = ilObjQuestionPool::_getAvailableQuestionpools(FALSE, FALSE, TRUE, FALSE, FALSE, "write");
         $pools_data = array();
         foreach ($questionpools as $key => $p) {
             $pools_data[$key] = $p['title'];
         }
         $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_qpl");
         $pools->setOptions($pools_data);
         $existing_pool->addSubItem($pools);
         $name = new ilTextInputGUI($this->lng->txt("name"), "txt_qpl");
         $name->setSize(50);
         $name->setMaxLength(50);
         $new_pool->addSubItem($name);
     }
     $form->addCommandButton("handleToolbarCommand", $lng->txt("submit"));
     $form->addCommandButton("questions", $lng->txt("cancel"));
     return $tpl->setContent($form->getHTML());
 }
Ejemplo n.º 2
0
 /**
 * Calculates the available questions for a test
 *
 * @access public
 */
 function getAvailableQuestions($arrFilter, $completeonly = 0)
 {
     global $ilUser;
     global $ilDB;
     include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
     $available_pools = array_keys(ilObjQuestionPool::_getAvailableQuestionpools($use_object_id = TRUE, $equal_points = FALSE, $could_be_offline = FALSE, $showPath = FALSE, $with_questioncount = FALSE));
     $available = "";
     if (count($available_pools)) {
         $available = " AND " . $ilDB->in('qpl_questions.obj_fi', $available_pools, false, 'integer');
     } else {
         return array();
     }
     if ($completeonly) {
         $available .= " AND qpl_questions.complete = " . $ilDB->quote("1", 'text');
     }
     $where = "";
     if (is_array($arrFilter)) {
         if (array_key_exists('title', $arrFilter) && strlen($arrFilter['title'])) {
             $where .= " AND " . $ilDB->like('qpl_questions.title', 'text', "%%" . $arrFilter['title'] . "%%");
         }
         if (array_key_exists('description', $arrFilter) && strlen($arrFilter['description'])) {
             $where .= " AND " . $ilDB->like('qpl_questions.description', 'text', "%%" . $arrFilter['description'] . "%%");
         }
         if (array_key_exists('author', $arrFilter) && strlen($arrFilter['author'])) {
             $where .= " AND " . $ilDB->like('qpl_questions.author', 'text', "%%" . $arrFilter['author'] . "%%");
         }
         if (array_key_exists('type', $arrFilter) && strlen($arrFilter['type'])) {
             $where .= " AND qpl_qst_type.type_tag = " . $ilDB->quote($arrFilter['type'], 'text');
         }
         if (array_key_exists('qpl', $arrFilter) && strlen($arrFilter['qpl'])) {
             $where .= " AND " . $ilDB->like('object_data.title', 'text', "%%" . $arrFilter['qpl'] . "%%");
         }
     }
     $original_ids =& $this->getExistingQuestions();
     $original_clause = " AND qpl_questions.original_id IS NULL";
     if (count($original_ids)) {
         $original_clause = " AND qpl_questions.original_id IS NULL AND " . $ilDB->in('qpl_questions.question_id', $original_ids, true, 'integer');
     }
     $query_result = $ilDB->query("\n\t\t\tSELECT\t\tqpl_questions.*,\n\t\t\t\t\t\tqpl_questions.tstamp,\n\t\t\t\t\t\tqpl_qst_type.type_tag,\n\t\t\t\t\t\tqpl_qst_type.plugin,\n\t\t\t\t\t\tobject_data.title qpl\n\t\t\t\t\t\t\n\t\t\tFROM\t\tqpl_questions\n\t\t\t\n\t\t\tINNER JOIN\tqpl_qst_type\n\t\t\tON \t\t\tqpl_qst_type.question_type_id = qpl_questions.question_type_fi\n\t\t\t\n\t\t\tINNER JOIN\tobject_data\n\t\t\tON\t\t\tobject_data.obj_id = qpl_questions.obj_fi\n\t\t\t\t\t\t\n\t\t\tWHERE\t\tqpl_questions.tstamp > 0\n\t\t\t\n\t\t\t{$original_clause}\n\t\t\t{$available}\n\t\t\t{$where}\n\t\t");
     $rows = array();
     $types = $this->getQuestionTypeTranslations();
     if ($query_result->numRows()) {
         while ($row = $ilDB->fetchAssoc($query_result)) {
             $row['ttype'] = $types[$row['type_tag']];
             if ($row["plugin"]) {
                 if ($this->isPluginActive($row["type_tag"])) {
                     array_push($rows, $row);
                 }
             } else {
                 array_push($rows, $row);
             }
         }
     }
     return $rows;
 }
 /**
  * Called when a new question should be created from a test
  *
  * Called when a new question should be created from a test
  *
  * @access	public
  */
 function createQuestionObject()
 {
     global $ilUser;
     $this->getQuestionsSubTabs();
     //$this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_qpl_select.html", "Modules/Test");
     $questionpools =& $this->object->getAvailableQuestionpools(FALSE, FALSE, FALSE, TRUE, FALSE, "write");
     if ($this->object->getPoolUsage()) {
         global $lng, $ilCtrl, $tpl;
         include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
         $form = new ilPropertyFormGUI();
         $form->setFormAction($ilCtrl->getFormAction($this, "executeCreateQuestion"));
         $form->setTitle($lng->txt("test_create_question"));
         include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
         $hidden = new ilHiddenInputGUI('sel_question_types');
         $hidden->setValue($_REQUEST["sel_question_types"]);
         $form->addItem($hidden);
         // use pool
         $usage = new ilRadioGroupInputGUI($this->lng->txt("assessment_pool_selection"), "usage");
         $usage->setRequired(true);
         $no_pool = new ilRadioOption($this->lng->txt("assessment_no_pool"), 1);
         $usage->addOption($no_pool);
         $existing_pool = new ilRadioOption($this->lng->txt("assessment_existing_pool"), 3);
         $usage->addOption($existing_pool);
         $new_pool = new ilRadioOption($this->lng->txt("assessment_new_pool"), 2);
         $usage->addOption($new_pool);
         $form->addItem($usage);
         $usage->setValue(1);
         $questionpools = ilObjQuestionPool::_getAvailableQuestionpools(FALSE, FALSE, TRUE, FALSE, FALSE, "write");
         $pools_data = array();
         foreach ($questionpools as $key => $p) {
             $pools_data[$key] = $p['title'];
         }
         $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_qpl");
         $pools->setOptions($pools_data);
         $existing_pool->addSubItem($pools);
         $name = new ilTextInputGUI($this->lng->txt("cat_create_qpl"), "txt_qpl");
         $name->setSize(50);
         $name->setMaxLength(50);
         $new_pool->addSubItem($name);
         $form->addCommandButton("executeCreateQuestion", $lng->txt("submit"));
         $form->addCommandButton("cancelCreateQuestion", $lng->txt("cancel"));
         return $this->tpl->setVariable('ADM_CONTENT', $form->getHTML());
     } else {
         global $ilCtrl;
         $ilCtrl->setParameterByClass('iltestexpresspageobjectgui', 'sel_question_types', $_REQUEST["sel_question_types"]);
         $link = $ilCtrl->getLinkTargetByClass('iltestexpresspageobjectgui', 'handleToolbarCommand', '', false, false);
         ilUtil::redirect($link);
     }
 }