function check_question_type($parameter) { $question_list = Question::get_question_type_list(); foreach ($question_list as $key => $value) { $valid_question_types[] = $key; } if (in_array($parameter, $valid_question_types)) { return true; } else { return false; } }
/** * @param string $courseCode * @param array $rules * @param array $columns * @param array $column_model * @return array */ public static function getRules($courseCode, &$rules, &$columns, &$column_model, $questionFields, $checkFields = false) { // sessions // course // categories // exercises // difficult // type if (empty($courseCode)) { // Session. $sessionList = SessionManager::get_sessions_by_general_coach(api_get_user_id()); $fields = array(); if (!empty($sessionList)) { $new_options = array(); $new_options[] = "-1:" . get_lang('All'); foreach ($sessionList as $session) { $new_options[] = "{$session['id']}:{$session['name']}"; } $string = implode(';', $new_options); $fields[] = array('field_display_text' => get_lang('Session'), 'field_variable' => 'session_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string); } } else { // $courseList = array(api_get_course_info()); //$courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id()); } // Courses. $courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id()); if (!empty($courseList)) { $new_options = array(); $new_options[] = "-1:" . get_lang('All'); foreach ($courseList as $course) { $new_options[] = "{$course['id']}:{$course['title']}"; } $string = implode(';', $new_options); $fields[] = array('field_display_text' => get_lang('Course'), 'field_variable' => 'c_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string); } // Categories. $string = null; if (!empty($courseList)) { $new_options = array(); $new_options[] = "-1:" . get_lang('All'); // Global categories // @todo use tree view $categories = Testcategory::getCategoriesIdAndName(0); if (!empty($categories)) { foreach ($categories as $id => $category) { if (!empty($id)) { $new_options[] = "{$id}:[Global] - " . $category; } } } foreach ($courseList as $course) { $categories = Testcategory::getCategoriesIdAndName($course['real_id']); if (!empty($categories)) { foreach ($categories as $id => $category) { if (!empty($id)) { $new_options[] = "{$id}:" . $course['title'] . " - " . $category; } } } } $string = implode(';', $new_options); $fields[] = array('field_display_text' => get_lang('Category'), 'field_variable' => 'category_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string); } $course = api_get_course_int_id(); $sessionId = api_get_session_id(); // Exercises. $exerciseList = ExerciseLib::get_all_exercises_for_course_id($sessionId, $course); if (!empty($exerciseList)) { $new_options = array(); $new_options[] = "-1:" . get_lang('All'); $new_options[] = "0:" . get_lang('Orphan'); foreach ($exerciseList as $exercise) { $new_options[] = "{$exercise['iid']}:{$exercise['title']}"; } $string = implode(';', $new_options); $fields[] = array('field_display_text' => get_lang('Exercise'), 'field_variable' => 'exercise_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string); } // Question type. $questionList = Question::get_question_type_list(); if (!empty($questionList)) { $new_options = array(); $new_options[] = "-1:" . get_lang('All'); foreach ($questionList as $key => $question) { $new_options[] = "{$key}:" . get_lang($question['1']); } $string = implode(';', $new_options); $fields[] = array('field_display_text' => get_lang('AnswerType'), 'field_variable' => 'question_type', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string); } // Difficult. $levels = Question::get_default_levels(); if (!empty($levels)) { $new_options = array(); $new_options[] = "-1:" . get_lang('All'); foreach ($levels as $key => $level) { $new_options[] = "{$key}:{$level}"; } $string = implode(';', $new_options); $fields[] = array('field_display_text' => get_lang('Difficulty'), 'field_variable' => 'difficulty', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string); } $questionFieldsKeys = array(); if (!empty($questionFields)) { foreach ($questionFields as $question) { $questionFieldsKeys[] = $question['field']; } } if (!empty($fields)) { foreach ($fields as $field) { $search_options = array(); $type = 'text'; if (in_array($field['field_type'], array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) { $type = 'select'; $search_options['sopt'] = array('eq', 'ne'); //equal not equal //$search_options['sopt'] = array('cn', 'nc'); //contains not contains } else { $search_options['sopt'] = array('cn', 'nc'); //contains not contains } $search_options['searchhidden'] = 'true'; $search_options['defaultValue'] = isset($search_options['field_default_value']) ? $search_options['field_default_value'] : null; $search_options['value'] = $field['field_options']; $column_model[] = array('name' => 'question_' . $field['field_variable'], 'index' => 'question_' . $field['field_variable'], 'width' => '100', 'hidden' => 'true', 'search' => 'true', 'stype' => $type, 'searchoptions' => $search_options); $columns[] = $field['field_display_text']; $rules[] = array('field' => 'question_' . $field['field_variable'], 'op' => 'eq'); } } return $rules; }
$my_exercise_list[$row['id']] = "> "; } $my_exercise_list[$row['id']] .= $row['title']; } } if ($exercice_id_changed == 1) { reset_menu_lvl_type(); } $select_exercise_html = Display::select('exerciseId', $my_exercise_list, $exerciseId, array('class' => 'chzn-select', 'onchange' => 'mark_exercice_id_changed(); submit_form(this);'), false); echo Display::form_row(get_lang('Exercise'), $select_exercise_html); // Difficulty list (only from 0 to 5) $levels = array(-1 => get_lang('All'), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5); $select_difficulty_html = Display::select('exerciseLevel', $levels, $exerciseLevel, array('class' => 'chzn-select', 'onchange' => 'submit_form(this);'), false); echo Display::form_row(get_lang('Difficulty'), $select_difficulty_html); // Answer type $question_list = Question::get_question_type_list(); $new_question_list = array(); $new_question_list['-1'] = get_lang('All'); if (!empty($_course)) { $objExercise = new Exercise(); $objExercise->read($fromExercise); foreach ($question_list as $key => $item) { if ($objExercise->feedback_type == EXERCISE_FEEDBACK_TYPE_DIRECT) { if (!in_array($key, array(HOT_SPOT_DELINEATION, UNIQUE_ANSWER))) { continue; } $new_question_list[$key] = get_lang($item[1]); } else { if ($key == HOT_SPOT_DELINEATION) { continue; }
/** * @return array the image filename of the question type */ public function get_type_icon_html() { $type = $this->selectType(); $tabQuestionList = Question::get_question_type_list(); // [0]=file to include [1]=type name require_once $tabQuestionList[$type][0]; $img = $explanation = null; eval('$img = ' . $tabQuestionList[$type][1] . '::$typePicture;'); eval('$explanation = get_lang(' . $tabQuestionList[$type][1] . '::$explanationLangVar);'); return array($img, $explanation); }
$objQuestion = Question::getInstance($_REQUEST['answerType']); $action = api_get_self() . "?" . api_get_cidreq() . "&modifyQuestion=" . $modifyQuestion . "&newQuestion=" . $newQuestion; } if (is_object($objQuestion)) { // FORM CREATION $form = new FormValidator('question_admin_form', 'post', $action); if (isset($_GET['editQuestion'])) { $class = "btn btn-default"; $text = get_lang('ModifyQuestion'); $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null; } else { $class = "btn btn-default"; $text = get_lang('AddQuestionToExercise'); $type = $_REQUEST['answerType']; } $typesInformation = Question::get_question_type_list(); $form_title_extra = isset($typesInformation[$type][1]) ? get_lang($typesInformation[$type][1]) : null; // form title $form->addElement('header', $text . ': ' . $form_title_extra); // question form elements $objQuestion->createForm($form); // answer form elements $objQuestion->createAnswersForm($form); // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications if ($objExercise->edit_exercise_in_lp == false) { $form->freeze(); } // FORM VALIDATION if (isset($_POST['submitQuestion']) && $form->validate()) { // question $objQuestion->processCreation($form, $objExercise);