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


PHP Answer::read方法代码示例

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


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

示例1: copyQuestionAction

 /**
  * @param Application $app
  * @param int $exerciseId
  * @param int $questionId
  * @return Response
  */
 public function copyQuestionAction(Application $app, $exerciseId, $questionId)
 {
     $question = \Question::read($questionId);
     if ($question) {
         $newQuestionTitle = $question->selectTitle() . ' - ' . get_lang('Copy');
         $question->updateTitle($newQuestionTitle);
         //Duplicating the source question, in the current course
         $courseInfo = api_get_course_info();
         $newId = $question->duplicate($courseInfo);
         // Reading new question
         $newQuestion = \Question::read($newId);
         $newQuestion->addToList($exerciseId);
         // Reading Answers obj of the current course
         $newAnswer = new \Answer($questionId);
         $newAnswer->read();
         //Duplicating the Answers in the current course
         $newAnswer->duplicate($newId);
         /*$params = array(
               'cidReq' => api_get_course_id(),
               'id_session' => api_get_session_id(),
               'id' => $newId,
               'exerciseId' => $exerciseId
           );
           $url = $app['url_generator']->generate('exercise_question_pool', $params);
           return $app->redirect($url);*/
         $response = \Display::return_message(get_lang('QuestionCopied') . ": " . $newQuestionTitle);
         return new Response($response, 200, array());
     }
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:35,代码来源:ExerciseController.php

示例2: createAnswersForm

 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     // Getting the exercise list
     $obj_ex = $_SESSION['objExercise'];
     $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
     //this line defines how many questions by default appear when creating a choice question
     // The previous default value was 2. See task #1759.
     $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4;
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     /*
         Types of Feedback
         $feedback_option[0]=get_lang('Feedback');
        $feedback_option[1]=get_lang('DirectFeedback');
        $feedback_option[2]=get_lang('NoFeedback');
     */
     $feedback_title = '';
     if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
         //Scenario
         $editor_config['Width'] = '250';
         $editor_config['Height'] = '110';
         $comment_title = '<th width="500px" >' . get_lang('Comment') . '</th>';
         $feedback_title = '<th width="350px" >' . get_lang('Scenario') . '</th>';
     } else {
         $comment_title = '<th>' . get_lang('Comment') . '</th>';
     }
     $html = '<table class="data_table">
             <tr style="text-align: center;">
                 <th width="10px">
                     ' . get_lang('Number') . '
                 </th>
                 <th width="10px" >
                     ' . get_lang('True') . '
                 </th>
                 <th width="50%">
                     ' . get_lang('Answer') . '
                 </th>
                     ' . $comment_title . '
                     ' . $feedback_title . '
                 <th width="50px">
                     ' . get_lang('Weighting') . '
                 </th>
             </tr>';
     $form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html);
     $defaults = array();
     $correct = 0;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     //Feedback SELECT
     $question_list = $obj_ex->selectQuestionList();
     $select_question = array();
     $select_question[0] = get_lang('SelectTargetQuestion');
     require_once '../newscorm/learnpathList.class.php';
     if (is_array($question_list)) {
         foreach ($question_list as $key => $questionid) {
             //To avoid warning messages
             if (!is_numeric($questionid)) {
                 continue;
             }
             $question = Question::read($questionid);
             $select_question[$questionid] = 'Q' . $key . ' :' . cut($question->selectTitle(), 20);
         }
     }
     $select_question[-1] = get_lang('ExitTest');
     $list = new LearnpathList(api_get_user_id());
     $flat_list = $list->get_flat_list();
     $select_lp_id = array();
     $select_lp_id[0] = get_lang('SelectTargetLP');
     foreach ($flat_list as $id => $details) {
         $select_lp_id[$id] = cut($details['lp_name'], 20);
     }
     $temp_scenario = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_answers; ++$i) {
         $form->addElement('html', '<tr>');
         if (isset($answer) && is_object($answer)) {
             if ($answer->correct[$i]) {
                 $correct = $i;
             }
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
             $item_list = explode('@@', $answer->destination[$i]);
             $try = $item_list[0];
             $lp = $item_list[1];
             $list_dest = $item_list[2];
             $url = $item_list[3];
             if ($try == 0) {
//.........这里部分代码省略.........
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:101,代码来源:unique_answer.class.php

示例3: copy_exercise

 /**
  * Copies an exercise (duplicate all questions and answers)
  */
 public function copy_exercise()
 {
     $exercise_obj = new Exercise();
     $exercise_obj = $this;
     // force the creation of a new exercise
     $exercise_obj->updateTitle($exercise_obj->selectTitle() . ' - ' . get_lang('Copy'));
     //Hides the new exercise
     $exercise_obj->updateStatus(false);
     $exercise_obj->updateId(0);
     $exercise_obj->save();
     $new_exercise_id = $exercise_obj->selectId();
     $question_list = $exercise_obj->selectQuestionList();
     if (!empty($question_list)) {
         //Question creation
         foreach ($question_list as $old_question_id) {
             $old_question_obj = Question::read($old_question_id);
             $new_id = $old_question_obj->duplicate();
             if ($new_id) {
                 $new_question_obj = Question::read($new_id);
                 if (isset($new_question_obj) && $new_question_obj) {
                     $new_question_obj->addToList($new_exercise_id);
                     // This should be moved to the duplicate function
                     $new_answer_obj = new Answer($old_question_id);
                     $new_answer_obj->read();
                     $new_answer_obj->duplicate($new_id);
                 }
             }
         }
     }
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:33,代码来源:exercise.class.php

示例4: createAnswersForm

 /**
  * function which redifines Question::createAnswersForm
  * @param FormValidator $form
  * @param the answers number to display
  */
 function createAnswersForm($form)
 {
     // getting the exercise list
     $obj_ex = Session::read('objExercise');
     $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
     //this line define how many question by default appear when creating a choice question
     $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 3;
     // The previous default value was 2. See task #1759.
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     /*
      Types of Feedback
      $feedback_option[0]=get_lang('Feedback');
      $feedback_option[1]=get_lang('DirectFeedback');
      $feedback_option[2]=get_lang('NoFeedback');
     */
     $feedback_title = '';
     $comment_title = '';
     if ($obj_ex->selectFeedbackType() == 1) {
         $editor_config['Width'] = '250';
         $editor_config['Height'] = '110';
         $comment_title = '<th width="50%" >' . get_lang('Comment') . '</th>';
         $feedback_title = '<th width="50%" >' . get_lang('Scenario') . '</th>';
     } else {
         $comment_title = '<th width="50%">' . get_lang('Comment') . '</th>';
     }
     $html = '<table class="table table-striped table-hover">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th>' . get_lang('Number') . '</th>';
     $html .= '<th>' . get_lang('True') . '</th>';
     $html .= '<th width="50%">' . get_lang('Answer') . '</th>';
     $html .= $comment_title . $feedback_title;
     $html .= '<th>' . get_lang('Weighting') . '</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     $html .= '<tbody>';
     $form->addHeader(get_lang('Answers'));
     $form->addHtml($html);
     $defaults = array();
     $correct = 0;
     $answer = false;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $temp_scenario = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     $editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : false;
     if ($editQuestion) {
         //fixing $nb_answers
         $new_list = array();
         $count = 1;
         if (isset($_POST['lessAnswers'])) {
             $lessFromSession = Session::read('less_answer');
             if (!isset($lessFromSession)) {
                 Session::write('less_answer', $this->id);
                 $nb_answers--;
             }
         }
         for ($k = 1; $k <= $nb_answers; ++$k) {
             if ($answer->position[$k] != '666') {
                 $new_list[$count] = $count;
                 $count++;
             }
         }
     } else {
         for ($k = 1; $k <= $nb_answers; ++$k) {
             $new_list[$k] = $k;
         }
     }
     $i = 1;
     //for ($k = 1 ; $k <= $real_nb_answers; $k++) {
     foreach ($new_list as $key) {
         $i = $key;
         $form->addElement('html', '<tr>');
         if (is_object($answer)) {
             if ($answer->position[$i] == 666) {
                 //we set nothing
             } else {
                 if ($answer->correct[$i]) {
                     $correct = $i;
                 }
                 $answer_result = $answer->answer[$i];
                 $weight_result = float_format($answer->weighting[$i], 1);
                 if ($nb_answers == $i) {
                     $weight_result = '0';
                 }
                 $defaults['answer[' . $i . ']'] = $answer_result;
                 $defaults['comment[' . $i . ']'] = $answer->comment[$i];
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:unique_answer_no_option.class.php

示例5: createAnswersForm

    /**
     * function which redefines Question::createAnswersForm
     * @param FormValidator instance
     */
    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
        $obj_ex = $this->exercise;
        $html = '<table class="data_table">
					<tr style="text-align: center;">
						<th width="10px">
							' . get_lang('Number') . '
						</th>
						<th width="10px">
							' . get_lang('True') . '
						</th>
						<th width="50%">
							' . get_lang('Answer') . '
						</th>';
        // show column comment when feedback is enable
        if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
            $html .= '<th>' . get_lang('Comment') . '</th>';
        }
        $html .= '</tr>';
        $form->addElement('label', get_lang('Answers') . '<br />' . Display::return_icon('fill_field.png'), $html);
        $defaults = array();
        $correct = 0;
        if (!empty($this->id)) {
            $answer = new Answer($this->id);
            $answer->read();
            if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
                $nb_answers = $answer->nbrAnswers;
            }
        }
        $form->addElement('hidden', 'nb_answers');
        $boxes_names = array();
        if ($nb_answers < 1) {
            $nb_answers = 1;
            Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
        }
        for ($i = 1; $i <= $nb_answers; ++$i) {
            if (isset($answer) && is_object($answer)) {
                $answer_id = $answer->getRealAnswerIdFromList($i);
                $defaults['answer[' . $i . ']'] = $answer->answer[$answer_id];
                $defaults['comment[' . $i . ']'] = $answer->comment[$answer_id];
                $defaults['weighting[' . $i . ']'] = Text::float_format($answer->weighting[$answer_id], 1);
                $defaults['correct[' . $i . ']'] = $answer->correct[$answer_id];
            } else {
                $defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2');
                $defaults['comment[1]'] = get_lang('DefaultMultipleComment2');
                $defaults['correct[1]'] = true;
                $defaults['weighting[1]'] = 10;
                $defaults['answer[2]'] = get_lang('DefaultMultipleAnswer1');
                $defaults['comment[2]'] = get_lang('DefaultMultipleComment1');
                $defaults['correct[2]'] = false;
            }
            $renderer =& $form->defaultRenderer();
            $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
            $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
            $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
            $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
            $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
            $answer_number->freeze();
            $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox" style="margin-left: 0em;"');
            $boxes_names[] = 'correct[' . $i . ']';
            if ($obj_ex->fastEdition) {
                $form->addElement('textarea', 'answer[' . $i . ']', null, $this->textareaSettings);
            } else {
                $form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
            }
            $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
            if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
                if ($obj_ex->fastEdition) {
                    $form->addElement('textarea', 'comment[' . $i . ']', null, $this->textareaSettings);
                } else {
                    $form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
                }
            }
            //only 1 answer the all deal ...
            //$form->addElement('text', 'weighting['.$i.']',null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="10"');
            $form->addElement('html', '</tr>');
        }
        $form->addElement('html', '</table>');
        $form->addElement('html', '<br />');
        $form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
        //only 1 answer the all deal ...
        $form->addElement('text', 'weighting[1]', get_lang('Score'), array('class' => "span1", 'value' => '10'));
        $navigator_info = api_get_navigator();
        //ie6 fix
        if ($obj_ex->edit_exercise_in_lp == true) {
            if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
                $form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
                $form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
                $form->addElement('submit', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"');
            } else {
                $form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
                $form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
                $form->addElement('style_submit_button', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"');
                // setting the save button here and not in the question class.php
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:multiple_answer_combination.class.php

示例6: createAnswersForm

 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     $defaults = array();
     $nb_matches = $nb_options = 2;
     $matches = array();
     $answer = null;
     $counter = 1;
     if (isset($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0) {
             for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                 $correct = $answer->isCorrect($i);
                 if (empty($correct)) {
                     $matches[$answer->selectAutoId($i)] = chr(64 + $counter);
                     $counter++;
                 }
             }
         }
     }
     if ($form->isSubmitted()) {
         $nb_matches = $form->getSubmitValue('nb_matches');
         $nb_options = $form->getSubmitValue('nb_options');
         if (isset($_POST['lessOptions'])) {
             $nb_matches--;
             $nb_options--;
         }
         if (isset($_POST['moreOptions'])) {
             $nb_matches++;
             $nb_options++;
         }
     } else {
         if (!empty($this->id)) {
             if (count($answer->nbrAnswers) > 0) {
                 $nb_matches = $nb_options = 0;
                 for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                     if ($answer->isCorrect($i)) {
                         $nb_matches++;
                         $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
                         $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1);
                         $defaults['matches[' . $nb_matches . ']'] = $answer->correct[$i];
                     } else {
                         $nb_options++;
                         $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
                     }
                 }
             }
         } else {
             $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
             $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
             $defaults['matches[2]'] = '2';
             $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
             $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
         }
     }
     if (empty($matches)) {
         for ($i = 1; $i <= $nb_options; ++$i) {
             // fill the array with A, B, C.....
             $matches[$i] = chr(64 + $i);
         }
     } else {
         for ($i = $counter; $i <= $nb_options; ++$i) {
             // fill the array with A, B, C.....
             $matches[$i] = chr(64 + $i);
         }
     }
     $form->addElement('hidden', 'nb_matches', $nb_matches);
     $form->addElement('hidden', 'nb_options', $nb_options);
     // DISPLAY MATCHES
     $html = '<table class="table table-striped table-hover">
         <thead>
             <tr>
                 <th width="5%">' . get_lang('Number') . '</th>
                 <th width="70%">' . get_lang('Answer') . '</th>
                 <th width="15%">' . get_lang('MatchesTo') . '</th>
                 <th width="10%">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHeader(get_lang('MakeCorrespond'));
     $form->addHtml($html);
     if ($nb_matches < 1) {
         $nb_matches = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_matches; ++$i) {
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]");
         $form->addHtml('<tr>');
         $form->addHtml("<td>{$i}</td>");
         $form->addText("answer[{$i}]", null);
         $form->addSelect("matches[{$i}]", null, $matches);
         $form->addText("weighting[{$i}]", null, true, ['value' => 10]);
         $form->addHtml('</tr>');
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:matching.class.php

示例7: array

    }
    $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
    $row++;
}
$content = $table->toHtml();
// Format B.
$headers = array(get_lang('Question'), get_lang('Answer'), get_lang('Correct'), get_lang('NumberStudentWhoSelectedIt'));
$data = array();
if (!empty($question_list)) {
    $id = 0;
    foreach ($question_list as $row) {
        $question_id = $row['question_id'];
        $question_obj = Question::read($question_id);
        $exercise_stats = ExerciseLib::get_student_stats_by_question($question_id, $exercise_id, api_get_course_int_id(), api_get_session_id());
        $answer = new Answer($question_id);
        $answer->read();
        $mainCounter = 1;
        $counter = 1;
        foreach ($answer->answer as $answer_id => $answer_item) {
            $answer_info = $answer->selectAnswer($answer_id);
            $is_correct = $answer->isCorrect($answer_id);
            $correct_answer = $is_correct == 1 ? get_lang('Yes') : get_lang('No');
            // Overwriting values depending of the question.
            switch ($question_obj->type) {
                case FILL_IN_BLANKS:
                    $answer_info_db = $answer_info;
                    $answer_info = substr($answer_info, 0, strpos($answer_info, '::'));
                    $correct_answer = $is_correct;
                    $answers = $objExercise->fill_in_blank_answer_to_array($answer_info);
                    $counter = 0;
                    foreach ($answers as $answer_item) {
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:31,代码来源:stats.php

示例8: createAnswersForm

 /**
  * function which redifines Question::createAnswersForm
  * @param the formvalidator instance
  * @param the answers number to display
  */
 function createAnswersForm($form)
 {
     $editorConfig = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
     $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
     // The previous default value was 2. See task #1759.
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     $obj_ex = $_SESSION['objExercise'];
     $form->addHeader(get_lang('Answers'));
     $html = '<table class="table table-striped table-hover">
         <thead>
             <tr>
                 <th width="10">' . get_lang('Number') . '</th>
                 <th width="10">' . get_lang('True') . '</th>
                 <th width="50%">' . get_lang('Answer') . '</th>
                 <th width="50%">' . get_lang('Comment') . '</th>
                 <th width="10">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHtml($html);
     $defaults = array();
     $correct = 0;
     $answer = false;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     $boxes_names = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_answers; ++$i) {
         $form->addHtml('<tr>');
         if (is_object($answer)) {
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
             $defaults['correct[' . $i . ']'] = $answer->correct[$i];
         } else {
             $defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2');
             $defaults['comment[1]'] = get_lang('DefaultMultipleComment2');
             $defaults['correct[1]'] = true;
             $defaults['weighting[1]'] = 10;
             $defaults['answer[2]'] = get_lang('DefaultMultipleAnswer1');
             $defaults['comment[2]'] = get_lang('DefaultMultipleComment1');
             $defaults['correct[2]'] = false;
             $defaults['weighting[2]'] = -5;
         }
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']');
         $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
         $answer_number->freeze();
         $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox" style="margin-left: 0em;"');
         $boxes_names[] = 'correct[' . $i . ']';
         $form->addHtmlEditor("answer[{$i}]", null, null, true, $editorConfig);
         $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
         $form->addHtmlEditor("comment[{$i}]", null, null, true, $editorConfig);
         $form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "col-md-1", 'value' => '0'));
         $form->addHtml('</tr>');
     }
     $form->addHtml('</tbody>');
     $form->addHtml('</table>');
     $form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
     $buttonGroup = [];
     global $text, $class;
     if ($obj_ex->edit_exercise_in_lp == true) {
         // setting the save button here and not in the question class.php
         $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
         $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true);
         $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true);
     }
     $form->addGroup($buttonGroup);
     $defaults['correct'] = $correct;
     if (!empty($this->id)) {
         $form->setDefaults($defaults);
     } else {
         if ($this->isContent == 1) {
             $form->setDefaults($defaults);
         }
     }
     $form->setConstants(array('nb_answers' => $nb_answers));
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:96,代码来源:multiple_answer.class.php

示例9: save

 /**
  * Records answers into the data base
  *
  * @author Olivier Brouckaert
  */
 public function save()
 {
     $answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER);
     $questionId = intval($this->questionId);
     $c_id = $this->course['real_id'];
     $correctList = [];
     $answerList = [];
     for ($i = 1; $i <= $this->new_nbrAnswers; $i++) {
         $answer = $this->new_answer[$i];
         $correct = $this->new_correct[$i];
         $comment = $this->new_comment[$i];
         $weighting = $this->new_weighting[$i];
         $position = $this->new_position[$i];
         $hotspot_coordinates = $this->new_hotspot_coordinates[$i];
         $hotspot_type = $this->new_hotspot_type[$i];
         $destination = $this->new_destination[$i];
         $autoId = $this->selectAutoId($i);
         if (!isset($this->position[$i])) {
             $params = ['c_id' => $c_id, 'question_id' => $questionId, 'answer' => $answer, 'correct' => $correct, 'comment' => $comment, 'ponderation' => $weighting, 'position' => $position, 'hotspot_coordinates' => $hotspot_coordinates, 'hotspot_type' => $hotspot_type, 'destination' => $destination];
             $autoId = Database::insert($answerTable, $params);
             if ($autoId) {
                 $sql = "UPDATE {$answerTable} SET id = iid, id_auto = iid WHERE iid = {$autoId}";
                 Database::query($sql);
                 $questionType = $this->getQuestionType();
                 if (in_array($questionType, [MATCHING, MATCHING_DRAGGABLE])) {
                     $answer = new Answer($this->questionId);
                     $answer->read();
                     $correctAnswerId = $answer->selectAnswerIdByPosition($correct);
                     $correctAnswerAutoId = $answer->selectAutoId($correctAnswerId);
                     Database::update($answerTable, ['correct' => $correctAnswerAutoId ? $correctAnswerAutoId : 0], ['iid = ?' => $autoId]);
                 }
             }
         } else {
             // https://support.chamilo.org/issues/6558
             // function updateAnswers already escape_string, error if we do it twice.
             // Feed function updateAnswers with none escaped strings
             $this->updateAnswers($autoId, $this->new_answer[$i], $this->new_comment[$i], $this->new_correct[$i], $this->new_weighting[$i], $this->new_position[$i], $this->new_destination[$i], $this->new_hotspot_coordinates[$i], $this->new_hotspot_type[$i]);
         }
         $answerList[$i] = $autoId;
         if ($correct) {
             $correctList[$autoId] = true;
         }
     }
     $questionType = self::getQuestionType();
     if ($questionType == DRAGGABLE) {
         foreach ($this->new_correct as $value => $status) {
             if (!empty($status)) {
                 $correct = $answerList[$status];
                 $myAutoId = $answerList[$value];
                 $sql = "UPDATE {$answerTable}\n                            SET correct = '{$correct}'\n                            WHERE\n                                id_auto = {$myAutoId}\n                            ";
                 Database::query($sql);
             }
         }
     }
     if (count($this->position) > $this->new_nbrAnswers) {
         $i = $this->new_nbrAnswers + 1;
         while ($this->position[$i]) {
             $position = $this->position[$i];
             $sql = "DELETE FROM {$answerTable}\n                \t\tWHERE\n                \t\t\tc_id = {$this->course_id} AND\n                \t\t\tquestion_id = '" . $questionId . "' AND\n                \t\t\tposition ='{$position}'";
             Database::query($sql);
             $i++;
         }
     }
     // moves $new_* arrays
     $this->answer = $this->new_answer;
     $this->correct = $this->new_correct;
     $this->comment = $this->new_comment;
     $this->weighting = $this->new_weighting;
     $this->position = $this->new_position;
     $this->hotspot_coordinates = $this->new_hotspot_coordinates;
     $this->hotspot_type = $this->new_hotspot_type;
     $this->nbrAnswers = $this->new_nbrAnswers;
     $this->destination = $this->new_destination;
     // clears $new_* arrays
     $this->cancel();
 }
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:81,代码来源:answer.class.php

示例10: createAnswersForm

    /**
     * Function which redefines Question::createAnswersForm
     * @param FormValidator instance
     */
    public function createAnswersForm($form)
    {
        $defaults = array();
        $nb_matches = $nb_options = 2;
        if ($form->isSubmitted()) {
            $nb_matches = $form->getSubmitValue('nb_matches');
            $nb_options = $form->getSubmitValue('nb_options');
            if (isset($_POST['lessMatches'])) {
                $nb_matches--;
            }
            if (isset($_POST['moreMatches'])) {
                $nb_matches++;
            }
            if (isset($_POST['lessOptions'])) {
                $nb_options--;
            }
            if (isset($_POST['moreOptions'])) {
                $nb_options++;
            }
        } else {
            if (!empty($this->id)) {
                $answer = new Answer($this->id, api_get_course_int_id());
                $answer->read();
                if (count($answer->nbrAnswers) > 0) {
                    $nb_matches = $nb_options = 0;
                    //for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                    foreach ($answer->answer as $answerId => $answer_item) {
                        //$answer_id = $answer->getRealAnswerIdFromList($answerId);
                        if ($answer->isCorrect($answerId)) {
                            $nb_matches++;
                            $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($answerId);
                            $defaults['weighting[' . $nb_matches . ']'] = Text::float_format($answer->selectWeighting($answerId), 1);
                            $defaults['matches[' . $nb_matches . ']'] = $answer->correct[$answerId];
                            //$nb_matches;
                        } else {
                            $nb_options++;
                            $defaults['option[' . $nb_options . ']'] = $nb_options;
                        }
                    }
                }
            } else {
                $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
                $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
                $defaults['matches[2]'] = '2';
                $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
                $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
            }
        }
        $a_matches = array();
        for ($i = 1; $i <= $nb_matches; ++$i) {
            $a_matches[$i] = $i;
            // fill the array with A, B, C.....
        }
        $form->addElement('hidden', 'nb_matches', $nb_matches);
        $form->addElement('hidden', 'nb_options', $nb_options);
        // DISPLAY MATCHES
        $html = '<table class="data_table">
					<tr>
						<th width="40%">
							' . get_lang('Answer') . '
						</th>
						<th width="40%">
							' . get_lang('MatchesTo') . '
						</th>
						<th width="50px">
							' . get_lang('Weighting') . '
						</th>
					</tr>';
        $form->addElement('label', get_lang('MakeCorrespond') . '<br /> ' . Display::return_icon('fill_field.png'), $html);
        if ($nb_matches < 1) {
            $nb_matches = 1;
            Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
        }
        for ($i = 1; $i <= $nb_matches; ++$i) {
            $form->addElement('html', '<tr><td>');
            $group = array();
            $group[] = $form->createElement('text', 'answer[' . $i . ']', null, ' size="60" style="margin-left: 0em;"');
            $group[] = $form->createElement('select', 'matches[' . $i . ']', null, $a_matches);
            $group[] = $form->createElement('text', 'weighting[' . $i . ']', null, array('class' => 'span1', 'value' => 10));
            $form->addGroup($group, null, null, '</td><td>');
            $form->addElement('html', '</td></tr>');
            $defaults['option[' . $i . ']'] = $i;
        }
        $form->addElement('html', '</table></div></div>');
        $group = array();
        $group[] = $form->createElement('style_submit_button', 'moreMatches', get_lang('AddElem'), 'class="btn plus"');
        $group[] = $form->createElement('style_submit_button', 'lessMatches', get_lang('DelElem'), 'class="btn minus"');
        $group[] = $form->createElement('style_submit_button', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"');
        $form->addGroup($group);
        $form->addElement('html', '</table></div></div>');
        if (!empty($this->id)) {
            $form->setDefaults($defaults);
        } else {
            if ($this->isContent == 1) {
                $form->setDefaults($defaults);
            }
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:draggable.class.php

示例11: createAnswersForm

 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
     // The previous default value was 2. See task #1759.
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : isset($_POST['moreAnswers']) ? 1 : 0;
     $course_id = api_get_course_int_id();
     $obj_ex = $_SESSION['objExercise'];
     $renderer =& $form->defaultRenderer();
     $defaults = array();
     $html = '<table class="table table-striped table-hover">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th>' . get_lang('Number') . '</th>';
     $html .= '<th>' . get_lang('True') . '</th>';
     $html .= '<th>' . get_lang('False') . '</th>';
     $html .= '<th>' . get_lang('Answer') . '</th>';
     // show column comment when feedback is enable
     if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
         $html .= '<th>' . get_lang('Comment') . '</th>';
     }
     $html .= '</tr>';
     $html .= '</thead>';
     $html .= '<tbody>';
     $form->addHeader(get_lang('Answers'));
     $form->addHtml($html);
     $correct = 0;
     $answer = null;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     $boxes_names = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     // Can be more options
     $option_data = Question::readQuestionOption($this->id, $course_id);
     for ($i = 1; $i <= $nb_answers; ++$i) {
         $form->addHtml('<tr>');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
         $answer_number->freeze();
         if (is_object($answer)) {
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $correct = $answer->correct[$i];
             $defaults['correct[' . $i . ']'] = $correct;
             $j = 1;
             if (!empty($option_data)) {
                 foreach ($option_data as $id => $data) {
                     $form->addElement('radio', 'correct[' . $i . ']', null, null, $id);
                     $j++;
                     if ($j == 3) {
                         break;
                     }
                 }
             }
         } else {
             $form->addElement('radio', 'correct[' . $i . ']', null, null, 1);
             $form->addElement('radio', 'correct[' . $i . ']', null, null, 2);
             $defaults['answer[' . $i . ']'] = '';
             $defaults['comment[' . $i . ']'] = '';
             $defaults['correct[' . $i . ']'] = '';
         }
         $boxes_names[] = 'correct[' . $i . ']';
         $form->addHtmlEditor("answer[{$i}]", get_lang('ThisFieldIsRequired'), true, true, ['ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100']);
         // show comment when feedback is enable
         if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
             $form->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
         }
         $form->addHtml('</tr>');
     }
     $form->addHtml('</tbody></table>');
     $correctInputTemplate = '<div class="form-group">';
     $correctInputTemplate .= '<label class="col-sm-2 control-label">';
     $correctInputTemplate .= '<span class="form_required">*</span>' . get_lang('Score');
     $correctInputTemplate .= '</label>';
     $correctInputTemplate .= '<div class="col-sm-8">';
     $correctInputTemplate .= '<table>';
     $correctInputTemplate .= '<tr>';
     $correctInputTemplate .= '<td>';
     $correctInputTemplate .= get_lang('Correct') . '{element}';
     $correctInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->';
     $correctInputTemplate .= '</td>';
     $wrongInputTemplate = '<td>';
     $wrongInputTemplate .= get_lang('Wrong') . '{element}';
     $wrongInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->';
     $wrongInputTemplate .= '</td>';
//.........这里部分代码省略.........
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:101,代码来源:multiple_answer_true_false.class.php

示例12: createAnswersForm

 public function createAnswersForm($form)
 {
     /** @var Exercise $objExercise */
     $objExercise = Session::read('objExercise');
     $editorConfig = array('ToolbarSet' => 'TestFreeAnswer', 'Width' => '100%', 'Height' => '125');
     //this line defines how many questions by default appear when creating a choice question
     // The previous default value was 2. See task #1759.
     $numberAnswers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4;
     $numberAnswers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     $feedbackTitle = '';
     if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
         //Scenario
         $commentTitle = '<th>' . get_lang('Comment') . '</th>';
         $feedbackTitle = '<th>' . get_lang('Scenario') . '</th>';
     } else {
         $commentTitle = '<th >' . get_lang('Comment') . '</th>';
     }
     $html = '<div class="alert alert-success" role="alert">' . get_lang('UniqueAnswerImagePreferredSize200x150') . '</div>';
     $html .= '<table class="table table-striped table-hover">
         <thead>
             <tr style="text-align: center;">
                 <th width="10">' . get_lang('Number') . '</th>
                 <th>' . get_lang('True') . '</th>
                 <th>' . get_lang('Answer') . '</th>
                     ' . $commentTitle . '
                     ' . $feedbackTitle . '
                 <th width="15">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHeader(get_lang('Answers'));
     $form->addHtml($html);
     $defaults = array();
     $correct = 0;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $numberAnswers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     //Feedback SELECT
     $questionList = $objExercise->selectQuestionList();
     $selectQuestion = array();
     $selectQuestion[0] = get_lang('SelectTargetQuestion');
     if (is_array($questionList)) {
         foreach ($questionList as $key => $questionid) {
             //To avoid warning messages
             if (!is_numeric($questionid)) {
                 continue;
             }
             $question = Question::read($questionid);
             $selectQuestion[$questionid] = 'Q' . $key . ' :' . cut($question->selectTitle(), 20);
         }
     }
     $selectQuestion[-1] = get_lang('ExitTest');
     $list = new LearnpathList(api_get_user_id());
     $flatList = $list->get_flat_list();
     $selectLpId = array();
     $selectLpId[0] = get_lang('SelectTargetLP');
     foreach ($flatList as $id => $details) {
         $selectLpId[$id] = cut($details['lp_name'], 20);
     }
     $tempScenario = array();
     if ($numberAnswers < 1) {
         $numberAnswers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $numberAnswers; ++$i) {
         $form->addHtml('<tr>');
         if (isset($answer) && is_object($answer)) {
             if ($answer->correct[$i]) {
                 $correct = $i;
             }
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
             $itemList = explode('@@', $answer->destination[$i]);
             $try = $itemList[0];
             $lp = $itemList[1];
             $listDestination = $itemList[2];
             $url = $itemList[3];
             $try = 0;
             if ($try != 0) {
                 $tryResult = 1;
             }
             $urlResult = '';
             if ($url != 0) {
                 $urlResult = $url;
             }
             $tempScenario['url' . $i] = $urlResult;
             $tempScenario['try' . $i] = $tryResult;
             $tempScenario['lp' . $i] = $lp;
             $tempScenario['destination' . $i] = $listDestination;
         } else {
             $defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1');
             $defaults['weighting[1]'] = 10;
             $defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2');
             $defaults['weighting[2]'] = 0;
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:UniqueAnswerImage.php

示例13: createAnswersForm

    /**
     * Redefines Question::createAnswersForm
     * @param the formvalidator instance
     */
    function createAnswersForm($form)
    {
        $defaults = array();
        $navigator_info = api_get_navigator();
        $nb_matches = $nb_options = 2;
        if ($form->isSubmitted()) {
            $nb_matches = $form->getSubmitValue('nb_matches');
            $nb_options = $form->getSubmitValue('nb_options');
            if (isset($_POST['lessMatches'])) {
                $nb_matches--;
            }
            if (isset($_POST['moreMatches'])) {
                $nb_matches++;
            }
            if (isset($_POST['lessOptions'])) {
                $nb_options--;
            }
            if (isset($_POST['moreOptions'])) {
                $nb_options++;
            }
        } else {
            if (!empty($this->id)) {
                $answer = new Answer($this->id);
                $answer->read();
                if (count($answer->nbrAnswers) > 0) {
                    $a_matches = $a_options = array();
                    $nb_matches = $nb_options = 0;
                    foreach ($answer->answer as $i => $answer_item) {
                        if ($answer->isCorrect($i)) {
                            $nb_matches++;
                            $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
                            $defaults['weighting[' . $nb_matches . ']'] = Text::float_format($answer->selectWeighting($i), 1);
                            $correct_answer_id = $answer->correct[$i];
                            $defaults['matches[' . $nb_matches . ']'] = $answer->getCorrectAnswerPosition($correct_answer_id);
                        } else {
                            $nb_options++;
                            $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
                        }
                    }
                }
            } else {
                $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
                $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
                $defaults['matches[2]'] = '2';
                $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
                $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
            }
        }
        $a_matches = array();
        for ($i = 1; $i <= $nb_options; ++$i) {
            // fill the array with A, B, C.....
            $a_matches[$i] = chr(64 + $i);
        }
        $form->addElement('hidden', 'nb_matches', $nb_matches);
        $form->addElement('hidden', 'nb_options', $nb_options);
        // DISPLAY MATCHES
        $html = '<table class="data_table">
					<tr>
						<th width="10px">
							' . get_lang('Number') . '
						</th>
						<th width="40%">
							' . get_lang('Answer') . '
						</th>
						<th width="40%">
							' . get_lang('MatchesTo') . '
						</th>
						<th width="50px">
							' . get_lang('Weighting') . '
						</th>
					</tr>';
        $form->addElement('label', get_lang('MakeCorrespond') . '<br /> ' . Display::return_icon('fill_field.png'), $html);
        if ($nb_matches < 1) {
            $nb_matches = 1;
            Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
        }
        for ($i = 1; $i <= $nb_matches; ++$i) {
            $form->addElement('html', '<tr><td>');
            $group = array();
            $puce = $form->createElement('text', null, null, 'value="' . $i . '"');
            $puce->freeze();
            $group[] = $puce;
            $group[] = $form->createElement('text', 'answer[' . $i . ']', null, 'size="60" style="margin-left: 0em;"');
            $group[] = $form->createElement('select', 'matches[' . $i . ']', null, $a_matches);
            $group[] = $form->createElement('text', 'weighting[' . $i . ']', null, array('class' => 'span1', 'value' => 10));
            $form->addGroup($group, null, null, '</td><td>');
            $form->addElement('html', '</td></tr>');
        }
        $form->addElement('html', '</table></div></div>');
        $group = array();
        if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
            $group[] = $form->createElement('submit', 'lessMatches', get_lang('DelElem'), 'class="btn minus"');
            $group[] = $form->createElement('submit', 'moreMatches', get_lang('AddElem'), 'class="btn plus"');
        } else {
            $group[] = $form->createElement('style_submit_button', 'moreMatches', get_lang('AddElem'), 'class="btn plus"');
            $group[] = $form->createElement('style_submit_button', 'lessMatches', get_lang('DelElem'), 'class="btn minus"');
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:matching.class.php

示例14: createAnswersForm

    /**
     * function which redefines Question::createAnswersForm
     * @param FormValidator instance
     * @param the answers number to display
     */
    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        // The previous default value was 2. See task #1759.
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
        $course_id = api_get_course_int_id();
        $obj_ex = $this->exercise;
        $renderer =& $form->defaultRenderer();
        $defaults = array();
        $html = '<table class="data_table">
					<tr style="text-align: center;">
						<th>
							' . get_lang('Number') . '
						</th>
						<th>
							' . get_lang('True') . '
						</th>
                        <th>
                            ' . get_lang('False') . '
                        </th>
						<th>
							' . get_lang('Answer') . '
						</th>';
        // show column comment when feedback is enable
        if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
            $html .= '<th>' . get_lang('Comment') . '</th>';
        }
        $html .= '</tr>';
        $form->addElement('label', get_lang('Answers') . '<br />' . Display::return_icon('fill_field.png'), $html);
        $correct = 0;
        if (!empty($this->id)) {
            $answer = new Answer($this->id);
            $answer->read();
            if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
                $nb_answers = $answer->nbrAnswers;
            }
        }
        $form->addElement('hidden', 'nb_answers');
        $boxes_names = array();
        if ($nb_answers < 1) {
            $nb_answers = 1;
            Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
        }
        // Can be more options
        $option_data = Question::readQuestionOption($this->id, $course_id);
        for ($i = 1; $i <= $nb_answers; ++$i) {
            $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
            $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
            $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
            $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
            $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
            $answer_number->freeze();
            if (isset($answer) && is_object($answer)) {
                $answer_id = $answer->getRealAnswerIdFromList($i);
                $defaults['answer[' . $i . ']'] = $answer->answer[$answer_id];
                $defaults['comment[' . $i . ']'] = $answer->comment[$answer_id];
                $correct = $answer->correct[$answer_id];
                $defaults['correct[' . $i . ']'] = $correct;
                $j = 1;
                if (!empty($option_data)) {
                    foreach ($option_data as $id => $data) {
                        $form->addElement('radio', 'correct[' . $i . ']', null, null, $id);
                        $j++;
                        if ($j == 3) {
                            break;
                        }
                    }
                }
            } else {
                $form->addElement('radio', 'correct[' . $i . ']', null, null, 1);
                $form->addElement('radio', 'correct[' . $i . ']', null, null, 2);
                $defaults['answer[' . $i . ']'] = '';
                $defaults['comment[' . $i . ']'] = '';
                $defaults['correct[' . $i . ']'] = '';
            }
            $boxes_names[] = 'correct[' . $i . ']';
            if ($obj_ex->fastEdition) {
                $form->addElement('textarea', 'answer[' . $i . ']', null, $this->textareaSettings);
            } else {
                $form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
            }
            $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
            // show comment when feedback is enable
            if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
                if ($obj_ex->fastEdition) {
                    $form->addElement('textarea', 'comment[' . $i . ']', null, $this->textareaSettings);
                } else {
                    $form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
                }
            }
            $form->addElement('html', '</tr>');
        }
        $form->addElement('html', '</table>');
        $form->addElement('html', '<br />');
        $form->addElement('html', '<table><tr><td></td><td>' . get_lang('Correct') . '</td><td>' . get_lang('Wrong') . '</td><td>' . get_lang('DoubtScore') . '</td></tr>');
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:multiple_answer_true_false.class.php

示例15: createAnswersForm

 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     $obj_ex = Session::read('objExercise');
     /* Mise en variable de Affichage "Reponses" et son icone, "N�", "Vrai", "Reponse" */
     $html = '<table class="data_table">
             <tr>
                 <th width="10px">
                     ' . get_lang('Number') . '
                 </th>
                 <th width="10px">
                     ' . get_lang('True') . '
                 </th>
                 <th width="50%">
                     ' . get_lang('Answer') . '
                 </th>';
     $html .= '<th>' . get_lang('Comment') . '</th>';
     $html .= '</tr>';
     $form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html);
     $defaults = array();
     $correct = 0;
     $answer = false;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     #le nombre de r�ponses est bien enregistr� sous la forme int(nb)
     /* Ajout mise en forme nb reponse */
     $form->addElement('hidden', 'nb_answers');
     $boxes_names = array();
     /* V�rification : Cr�action d'au moins une r�ponse */
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     //D�but affichage score global dans la modification d'une question
     $scoreA = "0";
     //par reponse
     $scoreG = "0";
     //Global
     /* boucle pour sauvegarder les donn�es dans le tableau defaults */
     for ($i = 1; $i <= $nb_answers; ++$i) {
         /* si la reponse est de type objet */
         if (is_object($answer)) {
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['correct[' . $i . ']'] = $answer->correct[$i];
             // start
             $scoreA = $answer->weighting[$i];
         }
         if ($scoreA > 0) {
             $scoreG = $scoreG + $scoreA;
         }
         //------------- Fin
         //------------- Debut si un des scores par reponse est egal � 0 : la coche vaut 1 (coch�)
         if ($scoreA == 0) {
             $defaults['pts'] = 1;
         }
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         //$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting['.$i.']');
         $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
         $answer_number->freeze();
         $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox"');
         $boxes_names[] = 'correct[' . $i . ']';
         $form->addHtmlEditor('answer[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
         $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
         $form->addHtmlEditor('comment[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
         $form->addElement('html', '</tr>');
     }
     //--------- Mise en variable du score global lors d'une modification de la question/r�ponse
     $defaults['weighting[1]'] = round($scoreG);
     $form->addElement('html', '</div></div></table>');
     //$form -> addElement ('html', '<br />');
     $form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
     //only 1 answer the all deal ...
     $form->addElement('text', 'weighting[1]', get_lang('Score'));
     global $pts;
     //--------- Creation coche pour ne pas prendre en compte les n�gatifs
     $form->addElement('checkbox', 'pts', '', get_lang('NoNegativeScore'));
     $form->addElement('html', '<br />');
     // Affiche un message si le score n'est pas renseign�
     $form->addRule('weighting[1]', get_lang('ThisFieldIsRequired'), 'required');
     global $text, $class;
     if ($obj_ex->edit_exercise_in_lp == true) {
         $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers');
         $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers');
         $form->addButtonSave($text, 'submitQuestion');
         // setting the save button here and not in the question class.php
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:global_multiple_answer.class.php


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