当前位置: 首页>>代码示例>>PHP>>正文


PHP Question::readQuestionOption方法代码示例

本文整理汇总了PHP中Question::readQuestionOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::readQuestionOption方法的具体用法?PHP Question::readQuestionOption怎么用?PHP Question::readQuestionOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Question的用法示例。


在下文中一共展示了Question::readQuestionOption方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: manage_answer


//.........这里部分代码省略.........
     if ($debug) {
         error_log('Count of answers: ' . $nbrAnswers);
         error_log('$answerType: ' . $answerType);
     }
     if ($answerType == FREE_ANSWER || $answerType == ORAL_EXPRESSION || $answerType == CALCULATED_ANSWER) {
         $nbrAnswers = 1;
     }
     $nano = null;
     if ($answerType == ORAL_EXPRESSION) {
         $exe_info = Event::get_exercise_results_by_attempt($exeId);
         $exe_info = isset($exe_info[$exeId]) ? $exe_info[$exeId] : null;
         $params = array();
         $params['course_id'] = $course_id;
         $params['session_id'] = api_get_session_id();
         $params['user_id'] = isset($exe_info['exe_user_id']) ? $exe_info['exe_user_id'] : api_get_user_id();
         $params['exercise_id'] = isset($exe_info['exe_exo_id']) ? $exe_info['exe_exo_id'] : $this->id;
         $params['question_id'] = $questionId;
         $params['exe_id'] = isset($exe_info['exe_id']) ? $exe_info['exe_id'] : $exeId;
         $nano = new Nanogong($params);
         //probably this attempt came in an exercise all question by page
         if ($feedback_type == 0) {
             $nano->replace_with_real_exe($exeId);
         }
     }
     $user_answer = '';
     // Get answer list for matching
     $sql = "SELECT id_auto, id, answer\n                FROM {$table_ans}\n                WHERE c_id = {$course_id} AND question_id = {$questionId}";
     $res_answer = Database::query($sql);
     $answerMatching = array();
     while ($real_answer = Database::fetch_array($res_answer)) {
         $answerMatching[$real_answer['id_auto']] = $real_answer['answer'];
     }
     $real_answers = array();
     $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
     $organs_at_risk_hit = 0;
     $questionScore = 0;
     if ($debug) {
         error_log('Start answer loop ');
     }
     $answer_correct_array = array();
     for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
         $answer = $objAnswerTmp->selectAnswer($answerId);
         $answerComment = $objAnswerTmp->selectComment($answerId);
         $answerCorrect = $objAnswerTmp->isCorrect($answerId);
         $answerWeighting = (double) $objAnswerTmp->selectWeighting($answerId);
         $answerAutoId = $objAnswerTmp->selectAutoId($answerId);
         $answer_correct_array[$answerId] = (bool) $answerCorrect;
         if ($debug) {
             error_log("answer auto id: {$answerAutoId} ");
             error_log("answer correct: {$answerCorrect} ");
         }
         // Delineation
         $delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1);
         $answer_delineation_destination = $objAnswerTmp->selectDestination(1);
         switch ($answerType) {
             // for unique answer
             case UNIQUE_ANSWER:
             case UNIQUE_ANSWER_IMAGE:
             case UNIQUE_ANSWER_NO_OPTION:
                 if ($from_database) {
                     $sql = "SELECT answer FROM {$TBL_TRACK_ATTEMPT}\n                                WHERE\n                                    exe_id = '" . $exeId . "' AND\n                                    question_id= '" . $questionId . "'";
                     $result = Database::query($sql);
                     $choice = Database::result($result, 0, "answer");
                     $studentChoice = $choice == $answerAutoId ? 1 : 0;
                     if ($studentChoice) {
                         $questionScore += $answerWeighting;
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:67,代码来源:exercise.class.php

示例2: restore_quiz_question

 /**
  * Restore quiz-questions
  * @params int question id
  */
 function restore_quiz_question($id)
 {
     $resources = $this->course->resources;
     $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null;
     $new_id = 0;
     if (is_object($question)) {
         if ($question->is_restored()) {
             return $question->destination_id;
         }
         $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
         $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
         $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
         // check resources inside html from ckeditor tool and copy correct urls into recipient course
         $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($question->description, $this->course->code, $this->course->destination_path);
         $parent_id = 0;
         if (isset($question->parent_info) && !empty($question->parent_info)) {
             $question_obj = Question::readByTitle($question->parent_info['question'], $this->destination_course_id);
             if ($question_obj) {
                 // Reuse media.
                 $parent_id = $question_obj->selectId();
             } else {
                 // Create media.
                 $question_obj = new MediaQuestion();
                 $question_obj->updateCourse($this->destination_course_id);
                 $parent_id = $question_obj->saveMedia(array('questionName' => $question->parent_info['question'], 'questionDescription' => $question->parent_info['description']));
             }
         }
         $sql = "INSERT INTO " . $table_que . " SET\n                    c_id = " . $this->destination_course_id . " ,\n                    question = '" . self::DBUTF8escapestring($question->question) . "',\n                    description = '" . self::DBUTF8escapestring($question->description) . "',\n                    ponderation = '" . self::DBUTF8escapestring($question->ponderation) . "',\n                    position = '" . self::DBUTF8escapestring($question->position) . "',\n                    type='" . self::DBUTF8escapestring($question->quiz_type) . "',\n                    picture='" . self::DBUTF8escapestring($question->picture) . "',\n                    level='" . self::DBUTF8escapestring($question->level) . "',\n                    parent_id = '" . $parent_id . "',\n                    extra='" . self::DBUTF8escapestring($question->extra) . "'";
         Database::query($sql);
         $new_id = Database::insert_id();
         if ($new_id) {
             if (!empty($question->picture)) {
                 $question_temp = Question::read($new_id, $this->destination_course_info['real_id']);
                 $documentPath = api_get_path(SYS_COURSE_PATH) . $this->destination_course_info['path'] . '/document';
                 // picture path
                 $picturePath = $documentPath . '/images';
                 $old_picture = api_get_path(SYS_COURSE_PATH) . $this->course->info['path'] . '/document/images/' . $question->picture;
                 if (file_exists($old_picture)) {
                     $picture_name = 'quiz-' . $new_id . '.jpg';
                     $result = $question_temp->uploadPicture($old_picture, $picture_name, $picturePath);
                     if ($result) {
                         $sql = "UPDATE {$table_que} SET picture = '{$picture_name}' WHERE c_id = " . $this->destination_course_id . " AND id = {$new_id} ";
                         Database::query($sql);
                     }
                 }
             }
         }
         if ($question->type == MATCHING) {
             $temp = array();
             $matching_list = array();
             $matching_to_update = array();
             foreach ($question->answers as $index => $answer) {
                 $temp[$answer['position']] = $answer;
                 if (!empty($answer['correct'])) {
                     $matching_to_update[$answer['iid']] = $answer['correct'];
                 }
             }
             foreach ($temp as $index => $answer) {
                 $sql = "INSERT INTO " . $table_ans . " SET\n                            c_id = " . $this->destination_course_id . " ,\n                            question_id = '" . $new_id . "',\n                            answer = '" . self::DBUTF8escapestring($answer['answer']) . "',\n                            correct = '" . $answer['correct'] . "',\n                            comment = '" . self::DBUTF8escapestring($answer['comment']) . "',\n                            ponderation = '" . $answer['ponderation'] . "',\n                            position = '" . $answer['position'] . "',\n                            hotspot_coordinates = '" . $answer['hotspot_coordinates'] . "',\n                            hotspot_type = '" . $answer['hotspot_type'] . "'";
                 Database::query($sql);
                 $new_answer_id = Database::insert_id();
                 $matching_list[$answer['iid']] = $new_answer_id;
             }
             foreach ($matching_to_update as $old_answer_id => $old_correct_id) {
                 $new_correct = $matching_list[$old_correct_id];
                 $new_fixed_id = $matching_list[$old_answer_id];
                 $sql = "UPDATE {$table_ans} SET correct = '{$new_correct}' WHERE iid = {$new_fixed_id} ";
                 Database::query($sql);
             }
         } else {
             $correct_answers = array();
             foreach ($question->answers as $index => $answer) {
                 // check resources inside html from fckeditor tool and copy correct urls into recipient course
                 $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['answer'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                 $answer['comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['comment'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                 $sql = "INSERT INTO " . $table_ans . " SET\n                                c_id = " . $this->destination_course_id . " ,\n                                id = '" . ($index + 1) . "',\n                                question_id = '" . $new_id . "',\n                                answer = '" . self::DBUTF8escapestring($answer['answer']) . "',\n                                correct = '" . $answer['correct'] . "',\n                                comment = '" . self::DBUTF8escapestring($answer['comment']) . "',\n                                ponderation = '" . $answer['ponderation'] . "',\n                                position = '" . $answer['position'] . "',\n                                hotspot_coordinates = '" . $answer['hotspot_coordinates'] . "',\n                                hotspot_type = '" . $answer['hotspot_type'] . "'";
                 Database::query($sql);
                 $new_answer_id = Database::insert_id();
                 $correct_answers[$new_answer_id] = $answer['correct'];
             }
         }
         //Current course id
         $course_id = api_get_course_int_id();
         //Moving quiz_question_options
         if ($question->type == MULTIPLE_ANSWER_TRUE_FALSE) {
             $question_option_list = Question::readQuestionOption($id, $course_id);
             //Question copied from the current platform
             if ($question_option_list) {
                 $old_option_ids = array();
                 foreach ($question_option_list as $item) {
                     $old_id = $item['iid'];
                     unset($item['iid']);
                     $item['question_id'] = $new_id;
                     $item['c_id'] = $this->destination_course_id;
                     $question_option_id = Database::insert($table_options, $item);
                     $old_option_ids[$old_id] = $question_option_id;
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:CourseRestorer.class.php

示例3: showQuestion

    /**
     * Shows a question
     *
     * @param int    $questionId question id
     * @param bool   $only_questions if true only show the questions, no exercise title
     * @param bool   $origin  i.e = learnpath
     * @param string $current_item current item from the list of questions
     * @param bool   $show_title
     * @param bool   $freeze
     * @param array  $user_choice
     * @param bool   $show_comment
     * @param bool   $exercise_feedback
     * @param bool   $show_answers
     * */
    public static function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false)
    {
        $course_id = api_get_course_int_id();
        // Change false to true in the following line to enable answer hinting
        $debug_mark_answer = $show_answers;
        // Reads question information
        if (!($objQuestionTmp = Question::read($questionId))) {
            // Question not found
            return false;
        }
        if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
            $show_comment = false;
        }
        $answerType = $objQuestionTmp->selectType();
        $pictureName = $objQuestionTmp->selectPicture();
        $s = '';
        if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
            // Question is not a hotspot
            if (!$only_questions) {
                $questionDescription = $objQuestionTmp->selectDescription();
                if ($show_title) {
                    TestCategory::displayCategoryAndTitle($objQuestionTmp->id);
                    echo Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
                }
                if (!empty($questionDescription)) {
                    echo Display::div($questionDescription, array('class' => 'question_description'));
                }
            }
            if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
                return '';
            }
            echo '<div class="question_options row">';
            // construction of the Answer object (also gets all answers details)
            $objAnswerTmp = new Answer($questionId);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
            // For "matching" type here, we need something a little bit special
            // because the match between the suggestions and the answers cannot be
            // done easily (suggestions and answers are in the same table), so we
            // have to go through answers first (elems with "correct" value to 0).
            $select_items = array();
            //This will contain the number of answers on the left side. We call them
            // suggestions here, for the sake of comprehensions, while the ones
            // on the right side are called answers
            $num_suggestions = 0;
            if (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
                if ($answerType == DRAGGABLE) {
                    $s .= '<div class="col-md-12 ui-widget ui-helper-clearfix">
                        <div class="clearfix">
                        <ul class="exercise-draggable-answer ui-helper-reset ui-helper-clearfix">';
                } else {
                    $s .= <<<HTML
                        <div id="drag{$questionId}_question" class="drag_question">
                            <table class="data_table">
HTML;
                }
                // Iterate through answers
                $x = 1;
                //mark letters for each answer
                $letter = 'A';
                $answer_matching = array();
                $cpt1 = array();
                for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $numAnswer = $objAnswerTmp->selectAutoId($answerId);
                    if ($answerCorrect == 0) {
                        // options (A, B, C, ...) that will be put into the list-box
                        // have the "correct" field set to 0 because they are answer
                        $cpt1[$x] = $letter;
                        $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId($numAnswer);
                        $x++;
                        $letter++;
                    }
                }
                $i = 1;
                $select_items[0]['id'] = 0;
                $select_items[0]['letter'] = '--';
                $select_items[0]['answer'] = '';
                foreach ($answer_matching as $id => $value) {
                    $select_items[$i]['id'] = $value['id'];
                    $select_items[$i]['letter'] = $cpt1[$id];
                    $select_items[$i]['answer'] = $value['answer'];
                    $i++;
                }
                $user_choice_array_position = array();
                if (!empty($user_choice)) {
//.........这里部分代码省略.........
开发者ID:secuencia24,项目名称:chamilo-lms,代码行数:101,代码来源:exercise.lib.php

示例4: showQuestion

    /**
     * Shows a question
     *
     * @param int    $questionId question id
     * @param bool   $only_questions if true only show the questions, no exercise title
     * @param bool   $origin  i.e = learnpath
     * @param string $current_item current item from the list of questions
     * @param bool   $show_title
     * @param bool   $freeze
     * @param array  $user_choice
     * @param bool   $show_comment
     * @param bool   $exercise_feedback
     * @param bool   $show_answers
     * */
    public static function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false)
    {
        $course_id = api_get_course_int_id();
        // Change false to true in the following line to enable answer hinting
        $debug_mark_answer = $show_answers;
        // Reads question information
        if (!($objQuestionTmp = Question::read($questionId))) {
            // Question not found
            return false;
        }
        if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
            $show_comment = false;
        }
        $answerType = $objQuestionTmp->selectType();
        $pictureName = $objQuestionTmp->selectPicture();
        $s = '';
        if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
            // Question is not a hotspot
            if (!$only_questions) {
                $questionDescription = $objQuestionTmp->selectDescription();
                if ($show_title) {
                    TestCategory::displayCategoryAndTitle($objQuestionTmp->id);
                    echo Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
                }
                if (!empty($questionDescription)) {
                    echo Display::div($questionDescription, array('class' => 'question_description'));
                }
            }
            if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
                return '';
            }
            echo '<div class="question_options row">';
            // construction of the Answer object (also gets all answers details)
            $objAnswerTmp = new Answer($questionId);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
            // For "matching" type here, we need something a little bit special
            // because the match between the suggestions and the answers cannot be
            // done easily (suggestions and answers are in the same table), so we
            // have to go through answers first (elems with "correct" value to 0).
            $select_items = array();
            //This will contain the number of answers on the left side. We call them
            // suggestions here, for the sake of comprehensions, while the ones
            // on the right side are called answers
            $num_suggestions = 0;
            if (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
                if ($answerType == DRAGGABLE) {
                    $s .= '<div class="col-md-12 ui-widget ui-helper-clearfix">
                        <div class="clearfix">
                        <ul class="exercise-draggable-answer ui-helper-reset ui-helper-clearfix">';
                } else {
                    $s .= '<div id="drag' . $questionId . '_question" class="drag_question">
                           <table class="data_table">';
                }
                // Iterate through answers
                $x = 1;
                //mark letters for each answer
                $letter = 'A';
                $answer_matching = array();
                $cpt1 = array();
                for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $numAnswer = $objAnswerTmp->selectAutoId($answerId);
                    if ($answerCorrect == 0) {
                        // options (A, B, C, ...) that will be put into the list-box
                        // have the "correct" field set to 0 because they are answer
                        $cpt1[$x] = $letter;
                        $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId($numAnswer);
                        $x++;
                        $letter++;
                    }
                }
                $i = 1;
                $select_items[0]['id'] = 0;
                $select_items[0]['letter'] = '--';
                $select_items[0]['answer'] = '';
                foreach ($answer_matching as $id => $value) {
                    $select_items[$i]['id'] = $value['id_auto'];
                    $select_items[$i]['letter'] = $cpt1[$id];
                    $select_items[$i]['answer'] = $value['answer'];
                    $i++;
                }
                $user_choice_array_position = array();
                if (!empty($user_choice)) {
                    foreach ($user_choice as $item) {
                        $user_choice_array_position[$item['position']] = $item['answer'];
//.........这里部分代码省略.........
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:101,代码来源:exercise.lib.php

示例5: duplicate

 /**
  * Duplicates answers by copying them into another question
  *
  * @author Olivier Brouckaert
  * @param  int question id
  * @param  array destination course info (result of the function api_get_course_info() )
  */
 public function duplicate($newQuestionId, $course_info = null)
 {
     if (empty($course_info)) {
         $course_info = $this->course;
     }
     $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
     $fixed_list = array();
     if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
         // Selecting origin options
         $origin_options = Question::readQuestionOption($this->selectQuestionId(), $this->course['real_id']);
         if (!empty($origin_options)) {
             foreach ($origin_options as $item) {
                 $new_option_list[] = $item['id'];
             }
         }
         $destination_options = Question::readQuestionOption($newQuestionId, $course_info['real_id']);
         $i = 0;
         if (!empty($destination_options)) {
             foreach ($destination_options as $item) {
                 $fixed_list[$new_option_list[$i]] = $item['id'];
                 $i++;
             }
         }
     }
     // if at least one answer
     if ($this->nbrAnswers) {
         // inserts new answers into data base
         $c_id = $course_info['real_id'];
         for ($i = 1; $i <= $this->nbrAnswers; $i++) {
             if ($this->course['id'] != $course_info['id']) {
                 $this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course($this->answer[$i], $this->course['id'], $course_info['id']);
                 $this->comment[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course($this->comment[$i], $this->course['id'], $course_info['id']);
             }
             $answer = $this->answer[$i];
             $correct = $this->correct[$i];
             if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
                 $correct = $fixed_list[intval($correct)];
             }
             $comment = $this->comment[$i];
             $weighting = $this->weighting[$i];
             $position = $this->position[$i];
             $hotspot_coordinates = $this->hotspot_coordinates[$i];
             $hotspot_type = $this->hotspot_type[$i];
             $destination = $this->destination[$i];
             $params = ['c_id' => $c_id, 'question_id' => $newQuestionId, 'answer' => $answer, 'correct' => $correct, 'comment' => $comment, 'ponderation' => $weighting, 'position' => $position, 'hotspot_coordinates' => $hotspot_coordinates, 'hotspot_type' => $hotspot_type, 'destination' => $destination];
             $id = Database::insert($TBL_REPONSES, $params);
             if ($id) {
                 $sql = "UPDATE {$TBL_REPONSES} SET id = id_auto WHERE id_auto = {$id}";
                 Database::query($sql);
             }
         }
     }
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:60,代码来源:answer.class.php

示例6: showQuestion

/**
 * Shows a question
 *
 * @param int    $questionId question id
 * @param bool   $only_questions if true only show the questions, no exercise title
 * @param bool   $origin  i.e = learnpath
 * @param string $current_item current item from the list of questions
 * @param bool   $show_title
 * @param bool   $freeze
 * @param array  $user_choice
 * @param bool   $show_comment
 * @param bool   $exercise_feedback
 * @param bool   $show_answers
 * */
function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false)
{
    // Text direction for the current language
    $is_ltr_text_direction = api_get_text_direction() != 'rtl';
    // Change false to true in the following line to enable answer hinting
    $debug_mark_answer = $show_answers;
    //api_is_allowed_to_edit() && false;
    // Reads question information
    if (!($objQuestionTmp = Question::read($questionId))) {
        // Question not found
        return false;
    }
    if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
        $show_comment = false;
    }
    $answerType = $objQuestionTmp->selectType();
    $pictureName = $objQuestionTmp->selectPicture();
    $s = '';
    if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
        // Question is not a hotspot
        if (!$only_questions) {
            $questionDescription = $objQuestionTmp->selectDescription();
            if ($show_title) {
                Testcategory::displayCategoryAndTitle($objQuestionTmp->id);
                echo Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
            }
            if (!empty($questionDescription)) {
                echo Display::div($questionDescription, array('class' => 'question_description'));
            }
        }
        if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
            return '';
        }
        echo '<div class="question_options">';
        // construction of the Answer object (also gets all answers details)
        $objAnswerTmp = new Answer($questionId);
        $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
        $course_id = api_get_course_int_id();
        $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
        // For "matching" type here, we need something a little bit special
        // because the match between the suggestions and the answers cannot be
        // done easily (suggestions and answers are in the same table), so we
        // have to go through answers first (elems with "correct" value to 0).
        $select_items = array();
        //This will contain the number of answers on the left side. We call them
        // suggestions here, for the sake of comprehensions, while the ones
        // on the right side are called answers
        $num_suggestions = 0;
        if ($answerType == MATCHING) {
            $s .= '<table class="data_table">';
            // Iterate through answers
            $x = 1;
            //mark letters for each answer
            $letter = 'A';
            $answer_matching = array();
            $cpt1 = array();
            for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                $numAnswer = $objAnswerTmp->selectAutoId($answerId);
                $answer = $objAnswerTmp->selectAnswer($answerId);
                if ($answerCorrect == 0) {
                    // options (A, B, C, ...) that will be put into the list-box
                    // have the "correct" field set to 0 because they are answer
                    $cpt1[$x] = $letter;
                    $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId($numAnswer);
                    $x++;
                    $letter++;
                }
            }
            $i = 1;
            $select_items[0]['id'] = 0;
            $select_items[0]['letter'] = '--';
            $select_items[0]['answer'] = '';
            foreach ($answer_matching as $id => $value) {
                $select_items[$i]['id'] = $value['id'];
                $select_items[$i]['letter'] = $cpt1[$id];
                $select_items[$i]['answer'] = $value['answer'];
                $i++;
            }
            $user_choice_array_position = array();
            if (!empty($user_choice)) {
                foreach ($user_choice as $item) {
                    $user_choice_array_position[$item['position']] = $item['answer'];
                }
            }
            $num_suggestions = $nbrAnswers - $x + 1;
//.........这里部分代码省略.........
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:101,代码来源:exercise.lib.php

示例7: showQuestion

    /**
     * Shows a question
     * @param Question $objQuestionTmp
     * @param bool $only_questions if true only show the questions, no exercise title
     * @param bool $origin origin i.e = learnpath
     * @param string $current_item current item from the list of questions
     * @param bool $show_title
     * @param bool $freeze
     * @param array $user_choice
     * @param bool $show_comment
     * @param null $exercise_feedback
     * @param bool $show_answers
     * @param null $modelType
     * @param bool $categoryMinusOne
     * @return bool|null|string
     */
    public function showQuestion(Question $objQuestionTmp, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false, $modelType = null, $categoryMinusOne = true)
    {
        // Text direction for the current language
        //$is_ltr_text_direction = api_get_text_direction() != 'rtl';
        // Change false to true in the following line to enable answer hinting
        $debug_mark_answer = $show_answers;
        //api_is_allowed_to_edit() && false;
        // Reads question information
        if (!$objQuestionTmp) {
            // Question not found
            return false;
        }
        $html = null;
        $questionId = $objQuestionTmp->id;
        if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
            $show_comment = false;
        }
        $answerType = $objQuestionTmp->selectType();
        $pictureName = $objQuestionTmp->selectPicture();
        $s = null;
        $form = new FormValidator('question');
        $renderer = $form->defaultRenderer();
        $form_template = '{content}';
        $renderer->setFormTemplate($form_template);
        if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
            // Question is not a hotspot
            if (!$only_questions) {
                $questionDescription = $objQuestionTmp->selectDescription();
                if ($show_title) {
                    $categoryName = TestCategory::getCategoryNamesForQuestion($objQuestionTmp->id, null, true, $categoryMinusOne);
                    $html .= $categoryName;
                    $html .= Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
                    if (!empty($questionDescription)) {
                        $html .= Display::div($questionDescription, array('class' => 'question_description'));
                    }
                } else {
                    $html .= '<div class="media">';
                    $html .= '<div class="pull-left">';
                    $html .= '<div class="media-object">';
                    $html .= Display::div($current_item, array('class' => 'question_no_title'));
                    $html .= '</div>';
                    $html .= '</div>';
                    $html .= '<div class="media-body">';
                    if (!empty($questionDescription)) {
                        $html .= Display::div($questionDescription, array('class' => 'question_description'));
                    }
                    $html .= '</div>';
                    $html .= '</div>';
                }
            }
            if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
                return null;
            }
            $html .= '<div class="question_options">';
            // construction of the Answer object (also gets all answers details)
            $objAnswerTmp = new Answer($questionId, null, $this);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            $course_id = api_get_course_int_id();
            $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
            // For "matching" type here, we need something a little bit special
            // because the match between the suggestions and the answers cannot be
            // done easily (suggestions and answers are in the same table), so we
            // have to go through answers first (elems with "correct" value to 0).
            $select_items = array();
            //This will contain the number of answers on the left side. We call them
            // suggestions here, for the sake of comprehensions, while the ones
            // on the right side are called answers
            $num_suggestions = 0;
            if ($answerType == MATCHING || $answerType == DRAGGABLE) {
                if ($answerType == DRAGGABLE) {
                    $s .= '<div class="ui-widget ui-helper-clearfix">
                            <ul class="drag_question ui-helper-reset ui-helper-clearfix">';
                } else {
                    $s .= '<div id="drag' . $questionId . '_question" class="drag_question">';
                    $s .= '<table class="data_table">';
                }
                $j = 1;
                //iterate through answers
                $letter = 'A';
                //mark letters for each answer
                $answer_matching = array();
                $capital_letter = array();
                //for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
                foreach ($objAnswerTmp->answer as $answerId => $answer_item) {
//.........这里部分代码省略.........
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:101,代码来源:exercise.class.php

示例8: display_multiple_answer_true_false

    /**
     * Display the answers to a multiple choice question
     *
     * @param integer Answer type
     * @param integer Student choice
     * @param string  Textual answer
     * @param string  Comment on answer
     * @param string  Correct answer comment
     * @param integer Exercise ID
     * @param integer Question ID
     * @param boolean Whether to show the answer comment or not
     * @return void
     */
    public static function display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans, $in_results_disabled)
    {
        $hide_expected_answer = false;
        if ($feedback_type == 0 && $in_results_disabled == 2) {
            $hide_expected_answer = true;
        }
        ?>
        <tr>
        <td width="5%">
        <?php 
        $question = new MultipleAnswerTrueFalse();
        $course_id = api_get_course_int_id();
        $new_options = Question::readQuestionOption($questionId, $course_id);
        //Your choice
        if (isset($new_options[$studentChoice])) {
            echo get_lang($new_options[$studentChoice]['name']);
        } else {
            echo '-';
        }
        ?>
        </td>
        <td width="5%">
        <?php 
        //Expected choice
        if (!$hide_expected_answer) {
            if (isset($new_options[$answerCorrect])) {
                echo get_lang($new_options[$answerCorrect]['name']);
            } else {
                echo '-';
            }
        } else {
            echo '-';
        }
        ?>
        </td>
        <td width="40%">
			<?php 
        echo $answer;
        ?>
        </td>

        <?php 
        if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
            ?>
        <td width="20%">
            <?php 
            $color = "black";
            if (isset($new_options[$studentChoice])) {
                if ($studentChoice == $answerCorrect) {
                    $color = "green";
                }
                echo '<span style="font-weight: bold; color: ' . $color . ';">' . nl2br($answerComment) . '</span>';
            }
            ?>
        </td>
            <?php 
            if ($ans == 1) {
                $comm = Event::get_comments($id, $questionId);
            }
            ?>
         <?php 
        } else {
            ?>
            <td>&nbsp;</td>
        <?php 
        }
        ?>
        </tr>
        <?php 
    }
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:83,代码来源:exercise_show_functions.lib.php

示例9: restore_quiz_question

 /**
  * Restore quiz-questions
  * @params int question id
  */
 public function restore_quiz_question($id)
 {
     $resources = $this->course->resources;
     $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null;
     $new_id = 0;
     if (is_object($question)) {
         if ($question->is_restored()) {
             return $question->destination_id;
         }
         $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
         $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
         $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
         // check resources inside html from ckeditor tool and copy correct urls into recipient course
         $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($question->description, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
         $params = ['c_id' => $this->destination_course_id, 'question' => self::DBUTF8($question->question), 'description' => self::DBUTF8($question->description), 'ponderation' => self::DBUTF8($question->ponderation), 'position' => self::DBUTF8($question->position), 'type' => self::DBUTF8($question->quiz_type), 'picture' => self::DBUTF8($question->picture), 'level' => self::DBUTF8($question->level), 'extra' => self::DBUTF8($question->extra)];
         $new_id = Database::insert($table_que, $params);
         if ($new_id) {
             $sql = "UPDATE {$table_que} SET id = iid WHERE iid = {$new_id}";
             Database::query($sql);
             if (!empty($question->picture)) {
                 $question_temp = Question::read($new_id, $this->destination_course_info['real_id']);
                 $documentPath = api_get_path(SYS_COURSE_PATH) . $this->destination_course_info['path'] . '/document';
                 // picture path
                 $picturePath = $documentPath . '/images';
                 $old_picture = api_get_path(SYS_COURSE_PATH) . $this->course->info['path'] . '/document/images/' . $question->picture;
                 if (file_exists($old_picture)) {
                     $picture_name = 'quiz-' . $new_id . '.jpg';
                     $result = $question_temp->uploadPicture($old_picture, $picture_name, $picturePath);
                     if ($result) {
                         $sql = "UPDATE {$table_que} SET\n                                        picture = '{$picture_name}'\n                                    WHERE\n                                        c_id = " . $this->destination_course_id . " AND\n                                        id = {$new_id} ";
                         Database::query($sql);
                     }
                 }
             }
         }
         if (in_array($question->quiz_type, [MATCHING, MATCHING_DRAGGABLE])) {
             $temp = array();
             foreach ($question->answers as $index => $answer) {
                 $temp[$answer['position']] = $answer;
             }
             foreach ($temp as $index => $answer) {
                 //id = '".$index."',
                 $params = ['c_id' => $this->destination_course_id, 'question_id' => $new_id, 'answer' => self::DBUTF8($answer['answer']), 'correct' => $answer['correct'], 'comment' => self::DBUTF8($answer['comment']), 'ponderation' => $answer['ponderation'], 'position' => $answer['position'], 'hotspot_coordinates' => $answer['hotspot_coordinates'], 'hotspot_type' => $answer['hotspot_type']];
                 $answerId = Database::insert($table_ans, $params);
                 if ($answerId) {
                     $sql = "UPDATE {$table_ans} SET id = iid, id_auto = iid WHERE iid = {$answerId}";
                     Database::query($sql);
                 }
             }
         } else {
             $correct_answers = array();
             foreach ($question->answers as $index => $answer) {
                 // check resources inside html from ckeditor tool and copy correct urls into recipient course
                 $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['answer'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                 $answer['comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['comment'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                 //                     id = '". ($index + 1)."',
                 $params = ['c_id' => $this->destination_course_id, 'question_id' => $new_id, 'answer' => self::DBUTF8($answer['answer']), 'correct' => $answer['correct'], 'comment' => self::DBUTF8($answer['comment']), 'ponderation' => $answer['ponderation'], 'position' => $answer['position'], 'hotspot_coordinates' => $answer['hotspot_coordinates'], 'hotspot_type' => $answer['hotspot_type']];
                 $answerId = Database::insert($table_ans, $params);
                 if ($answerId) {
                     $sql = "UPDATE {$table_ans} SET id = iid, id_auto = iid WHERE iid = {$answerId}";
                     Database::query($sql);
                 }
                 $correct_answers[$answerId] = $answer['correct'];
             }
         }
         //Current course id
         $course_id = api_get_course_int_id();
         //Moving quiz_question_options
         if ($question->quiz_type == MULTIPLE_ANSWER_TRUE_FALSE) {
             $question_option_list = Question::readQuestionOption($id, $course_id);
             //Question copied from the current platform
             if ($question_option_list) {
                 $old_option_ids = array();
                 foreach ($question_option_list as $item) {
                     $old_id = $item['id'];
                     unset($item['id']);
                     if (isset($item['iid'])) {
                         unset($item['iid']);
                     }
                     $item['question_id'] = $new_id;
                     $item['c_id'] = $this->destination_course_id;
                     $question_option_id = Database::insert($table_options, $item);
                     if ($question_option_id) {
                         $old_option_ids[$old_id] = $question_option_id;
                         $sql = "UPDATE {$table_options} SET id = iid WHERE iid = {$question_option_id}";
                         Database::query($sql);
                     }
                 }
                 if ($old_option_ids) {
                     $new_answers = Database::select('iid, correct', $table_ans, array('WHERE' => array('question_id = ? AND c_id = ? ' => array($new_id, $this->destination_course_id))));
                     foreach ($new_answers as $answer_item) {
                         $params = array();
                         $params['correct'] = $old_option_ids[$answer_item['correct']];
                         Database::update($table_ans, $params, array('iid = ? AND c_id = ? AND question_id = ? ' => array($answer_item['iid'], $this->destination_course_id, $new_id)), false);
                     }
                 }
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:CourseRestorer.class.php

示例10: processAnswersCreation

 /**
  * abstract function which creates the form to create / edit the answers of the question
  * @param FormValidator $form
  */
 public function processAnswersCreation($form)
 {
     $questionWeighting = $nbrGoodAnswers = 0;
     $objAnswer = new Answer($this->id);
     $nb_answers = $form->getSubmitValue('nb_answers');
     $options_count = $form->getSubmitValue('options_count');
     $course_id = api_get_course_int_id();
     $correct = array();
     $options = Question::readQuestionOption($this->id, $course_id);
     if (!empty($options)) {
         foreach ($options as $option_data) {
             $id = $option_data['id'];
             unset($option_data['id']);
             Question::updateQuestionOption($id, $option_data, $course_id);
         }
     } else {
         for ($i = 1; $i <= 3; $i++) {
             $last_id = Question::saveQuestionOption($this->id, $this->options[$i], $course_id, $i);
             $correct[$i] = $last_id;
         }
     }
     /* Getting quiz_question_options (true, false, doubt) because
        it's possible that there are more options in the future */
     $new_options = Question::readQuestionOption($this->id, $course_id);
     $sorted_by_position = array();
     foreach ($new_options as $item) {
         $sorted_by_position[$item['position']] = $item;
     }
     /* Saving quiz_question.extra values that has the correct scores of
        the true, false, doubt options registered in this format
        XX:YY:ZZZ where XX is a float score value.*/
     $extra_values = array();
     for ($i = 1; $i <= 3; $i++) {
         $score = trim($form->getSubmitValue('option[' . $i . ']'));
         $extra_values[] = $score;
     }
     $this->setExtra(implode(':', $extra_values));
     for ($i = 1; $i <= $nb_answers; $i++) {
         $answer = trim($form->getSubmitValue('answer[' . $i . ']'));
         $comment = trim($form->getSubmitValue('comment[' . $i . ']'));
         $goodAnswer = trim($form->getSubmitValue('correct[' . $i . ']'));
         if (empty($options)) {
             //If this is the first time that the question is created when
             // change the default values from the form 1 and 2 by the correct "option id" registered
             $goodAnswer = $sorted_by_position[$goodAnswer]['id'];
         }
         $questionWeighting += $extra_values[0];
         //By default 0 has the correct answers
         $objAnswer->createAnswer($answer, $goodAnswer, $comment, '', $i);
     }
     // saves the answers into the data base
     $objAnswer->save();
     // sets the total weighting of the question
     $this->updateWeighting($questionWeighting);
     $this->save();
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:60,代码来源:multiple_answer_true_false.class.php

示例11: duplicate

 /**
  * Duplicates answers by copying them into another question
  *
  * @author Olivier Brouckaert
  * @param  int question id
  * @param  array destination course info (result of the function api_get_course_info() )
  */
 public function duplicate($newQuestionId, $course_info = null)
 {
     if (empty($course_info)) {
         $course_info = $this->course;
     } else {
         $course_info = $course_info;
     }
     $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
     if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
         //Selecting origin options
         $origin_options = Question::readQuestionOption($this->selectQuestionId(), $this->course['real_id']);
         if (!empty($origin_options)) {
             foreach ($origin_options as $item) {
                 $new_option_list[] = $item['id'];
             }
         }
         $destination_options = Question::readQuestionOption($newQuestionId, $course_info['real_id']);
         $i = 0;
         $fixed_list = array();
         if (!empty($destination_options)) {
             foreach ($destination_options as $item) {
                 $fixed_list[$new_option_list[$i]] = $item['id'];
                 $i++;
             }
         }
     }
     // if at least one answer
     if ($this->nbrAnswers) {
         // inserts new answers into data base
         $c_id = $course_info['real_id'];
         $correct_answers = array();
         $new_ids = array();
         foreach ($this->answer as $answer_id => $answer_item) {
             $i = $answer_id;
             if ($this->course['id'] != $course_info['id']) {
                 $this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course($this->answer[$i], $this->course['id'], $course_info['id']);
                 $this->comment[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course($this->comment[$i], $this->course['id'], $course_info['id']);
             }
             $answer = Database::escape_string($this->answer[$i]);
             $correct = Database::escape_string($this->correct[$i]);
             if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
                 $correct = $fixed_list[intval($correct)];
             }
             $comment = Database::escape_string($this->comment[$i]);
             $weighting = Database::escape_string($this->weighting[$i]);
             $position = Database::escape_string($this->position[$i]);
             $hotspot_coordinates = Database::escape_string($this->hotspot_coordinates[$i]);
             $hotspot_type = Database::escape_string($this->hotspot_type[$i]);
             $destination = Database::escape_string($this->destination[$i]);
             $sql = "INSERT INTO {$TBL_REPONSES}(question_id, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type ,destination) VALUES";
             $sql .= "('{$newQuestionId}','{$answer}','{$correct}','{$comment}', '{$weighting}','{$position}','{$hotspot_coordinates}','{$hotspot_type}','{$destination}')";
             Database::query($sql);
             $new_id = Database::insert_id();
             $new_ids[$answer_id] = $new_id;
             if ($correct) {
                 $correct_answers[$new_id] = $correct;
             }
         }
         if (self::getQuestionType() == MATCHING) {
             if (!empty($correct_answers)) {
                 foreach ($correct_answers as $new_id => $correct_id) {
                     $correct = $new_ids[$correct_id];
                     $sql = "UPDATE {$TBL_REPONSES} SET correct = {$correct} WHERE iid = {$new_id}";
                     Database::query($sql);
                 }
             }
         }
     }
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:76,代码来源:answer.class.php


注:本文中的Question::readQuestionOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。