/** * function which redifines Question::createAnswersForm * @param the formvalidator instance */ function createAnswersForm($form) { $form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1')); // setting the save button here and not in the question class.php $form->addElement('style_submit_button', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"'); if (!empty($this->id)) { $form->setDefaults(array('weighting' => Text::float_format($this->weighting, 1))); } else { if ($this->isContent == 1) { $form->setDefaults(array('weighting' => '10')); } } }
/** * function which redefines Question::createAnswersForm * @param FormValidator instance */ public function createAnswersForm($form) { if ($this->exercise->getModelType() == EXERCISE_MODEL_TYPE_NORMAL) { $form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1')); if (!empty($this->id)) { $form->setDefaults(array('weighting' => Text::float_format($this->weighting, 1))); } else { if ($this->isContent == 1) { $form->setDefaults(array('weighting' => '10')); } } } if ($form->isFrozen() == false) { // Setting the save button here and not in the question class.php. $form->addElement('style_submit_button', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"'); } }
/** * Get average score by score (NO Exercises in LPs ) * @param int exercise id * @param int course id * @param int session id * * @return float Best average score */ public static function get_best_average_score_by_exercise($exercise_id, $course_code, $session_id, $user_count) { $user_results = self::get_best_exercise_results_by_user($exercise_id, $course_code, $session_id); $avg_score = 0; if (!empty($user_results)) { foreach ($user_results as $result) { if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { $score = $result['exe_result'] / $result['exe_weighting']; $avg_score += $score; } } //We asume that all exe_weighting //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']); //$avg_score = ($avg_score / count($user_results)); if (!empty($user_count)) { $avg_score = Text::float_format($avg_score / $user_count, 1) * 100; } else { $avg_score = 0; } } return $avg_score; }
/** * 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 } } $renderer->setElementTemplate('{element} ', 'lessAnswers'); $renderer->setElementTemplate('{element} ', 'submitQuestion'); $renderer->setElementTemplate('{element} ', 'moreAnswers'); $form->addElement('html', '</div></div>'); $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)); }
/** * function which redifines Question::createAnswersForm * @param the formvalidator instance * @param the answers number to display */ function createAnswersForm($form) { // getting the exercise list $obj_ex = $this->exercise; $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() == 0) { $comment_title = '<th>' . get_lang('Comment') . '</th>'; } elseif ($obj_ex->selectFeedbackType() == 1) { $editor_config['Width'] = '250'; $editor_config['Height'] = '110'; $comment_title = '<th width="500" >' . get_lang('Comment') . '</th>'; $feedback_title = '<th width="350px" >' . get_lang('Scenario') . '</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="60px"> ' . get_lang('Weighting') . ' </th> </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; } } $temp_scenario = array(); if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } if ($_GET['editQuestion']) { //fixing $nb_answers $new_list = array(); $count = 1; if (isset($_POST['lessAnswers'])) { if (!isset($_SESSION['less_answer'])) { $_SESSION['less_answer'] = $this->id; $nb_answers--; } } for ($k = 1; $k <= $nb_answers; ++$k) { $answer_id = $answer->getRealAnswerIdFromList($k); if ($answer->position[$answer_id] != '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>'); $answer_id = $answer->getRealAnswerIdFromList($i); if (is_object($answer)) { if ($answer->position[$answer_id] == 666) { //we set nothing } else { if ($answer->correct[$answer_id]) { $correct = $i; } $answer_result = $answer->answer[$answer_id]; $weight_result = Text::float_format($answer->weighting[$answer_id], 1); if ($nb_answers == $i) { $weight_result = '0'; } $defaults['answer[' . $i . ']'] = $answer_result; $defaults['comment[' . $i . ']'] = $answer->comment[$answer_id]; $defaults['weighting[' . $i . ']'] = $weight_result; $item_list = explode('@@', $answer->destination[$answer_id]); $try = $item_list[0]; $lp = $item_list[1]; $list_dest = $item_list[2]; $url = $item_list[3]; if ($try == 0) { $try_result = 0; } else { $try_result = 1; } if ($url == 0) { $url_result = ''; } else { $url_result = $url; } $temp_scenario['url' . $i] = $url_result; $temp_scenario['try' . $i] = $try_result; $temp_scenario['lp' . $i] = $lp; $temp_scenario['destination' . $i] = $list_dest; } } $defaults['scenario'] = $temp_scenario; $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $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('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); $form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config); if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) { // feedback $form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config); } elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { } $form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "span1", 'value' => '0')); $form->addElement('html', '</tr>'); $i++; } if (empty($this->id)) { $form->addElement('hidden', 'new_question', 1); } //Adding the "I don't know" question answer //if (empty($this -> id)) { $i = 666; $form->addElement('html', '<tr>'); $defaults['answer[' . $i . ']'] = get_lang('DontKnow'); $defaults['weighting[' . $i . ']'] = 0; $defaults['scenario'] = $temp_scenario; $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $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="-"'); $answer_number->freeze(); $form->addElement('hidden', 'position[' . $i . ']', '666'); $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); $form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) { // feedback $form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config); } elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { } //$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple'); $form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "span1", 'value' => '0', 'readonly' => 'readonly')); $form->addElement('html', '</tr>'); //} $form->addElement('html', '</table>'); $form->addElement('html', '<br />'); $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', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"'); $form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"'); $form->addElement('submit', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"'); } else { //setting the save button here and not in the question class.php $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 . '"'); } } $renderer->setElementTemplate('{element} ', 'submitQuestion'); $renderer->setElementTemplate('{element} ', 'lessAnswers'); $renderer->setElementTemplate('{element} ', 'moreAnswers'); $form->addElement('html', '</div></div>'); //We check the first radio button to be sure a radio button will be check if ($correct == 0) { $correct = 1; } $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { $form->setDefaults($defaults); } $form->addElement('hidden', 'nb_answers'); $form->setConstants(array('nb_answers' => $nb_answers)); }
/** * function which redifines Question::createAnswersForm * @param FormValidator instance */ public function createAnswersForm($form) { // Getting the exercise list /** @var Exercise $obj_ex */ $obj_ex = $this->exercise; $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125'); //this line define how many question 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); $feedback_title = ''; $comment_title = ''; if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) { $comment_title = '<th>' . get_lang('Comment') . '</th>'; } elseif ($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>'; } $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 />' . 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'); $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] = Text::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)) { $answer_id = $answer->getRealAnswerIdFromList($i); if ($answer->correct[$answer_id]) { $correct = $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); if (!empty($answer->destination[$answer_id])) { $item_list = explode('@@', $answer->destination[$answer_id]); $try = $item_list[0]; $lp = $item_list[1]; $list_dest = $item_list[2]; $url = $item_list[3]; if ($try == 0) { $try_result = 0; } else { $try_result = 1; } if ($url == 0) { $url_result = ''; } else { $url_result = $url; } $temp_scenario['url' . $i] = $url_result; $temp_scenario['try' . $i] = $try_result; $temp_scenario['lp' . $i] = $lp; $temp_scenario['destination' . $i] = $list_dest; } } else { $defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1'); $defaults['weighting[1]'] = 10; $defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2'); $defaults['weighting[2]'] = 0; $temp_scenario['destination' . $i] = array('0'); $temp_scenario['lp' . $i] = array('0'); } $defaults['scenario'] = $temp_scenario; $renderer = $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $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('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); if ($obj_ex->fastEdition) { $form->addElement('textarea', 'answer[' . $i . ']', null, $this->textareaSettings); } else { $form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config); } $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) { if ($obj_ex->fastEdition) { // feedback $form->addElement('textarea', 'comment[' . $i . ']', null, $this->textareaSettings); } else { // feedback $form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config); } } elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { // Feedback SELECT $question_list = $obj_ex->selectQuestionList(); $select_question = array(); $select_question[0] = get_lang('SelectTargetQuestion'); // @todo improve this loop if you have 5000 questions it will blow! if (is_array($question_list)) { foreach ($question_list as $key => $questionid) { //To avoid warning messages if (!is_numeric($questionid)) { continue; } $question = Question::read($questionid); if ($question) { $select_question[$questionid] = 'Q' . $key . ' :' . Text::cut($question->selectTitle(), 20); } } } $select_question[-1] = get_lang('ExitTest'); $form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config); // Direct feedback //Adding extra feedback fields $group = array(); $group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain')); $group['lp' . $i] = $form->createElement('select', 'lp' . $i, get_lang('SeeTheory') . ': ', $select_lp_id); $group['destination' . $i] = $form->createElement('select', 'destination' . $i, get_lang('GoToQuestion') . ': ', $select_question); $group['url' . $i] = $form->createElement('text', 'url' . $i, get_lang('Other') . ': ', array('class' => 'span2', 'placeholder' => get_lang('Other'))); $form->addGroup($group, 'scenario'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}', 'scenario'); } $form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "span1", 'value' => '0')); $form->addElement('html', '</tr>'); } $form->addElement('html', '</table>'); $form->addElement('html', '<br />'); $navigator_info = api_get_navigator(); // ie6 fix. if ($form->isFrozen() == false) { 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 { //setting the save button here and not in the question class.php $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 . '"'); } } $renderer->setElementTemplate('{element} ', 'submitQuestion'); $renderer->setElementTemplate('{element} ', 'lessAnswers'); $renderer->setElementTemplate('{element} ', 'moreAnswers'); } $form->addElement('html', '</div></div>'); //We check the first radio button to be sure a radio button will be check if ($correct == 0) { $correct = 1; } $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)); }
/** * 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); } } $form->setConstants(array('nb_matches' => $nb_matches, 'nb_options' => $nb_options)); }
/** * 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"'); } $form->addGroup($group); // DISPLAY OPTIONS $html = '<table class="data_table"> <tr style="text-align: center;"> <th width="10px"> ' . get_lang('Number') . ' </th> <th width="90%" ' . get_lang('Answer') . ' </th> </tr>'; //$form -> addElement ('html', $html); $form->addElement('label', null, $html); if ($nb_options < 1) { $nb_options = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_options; ++$i) { $form->addElement('html', '<tr><td>'); $group = array(); $puce = $form->createElement('text', null, null, 'value="' . chr(64 + $i) . '"'); $puce->freeze(); $group[] = $puce; $group[] = $form->createElement('text', 'option[' . $i . ']', null, array('class' => 'span6')); $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') { // setting the save button here and not in the question class.php $group[] = $form->createElement('submit', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"'); $group[] = $form->createElement('submit', 'lessOptions', get_lang('DelElem'), 'class="minus"'); $group[] = $form->createElement('submit', 'moreOptions', get_lang('AddElem'), 'class="plus"'); } else { // setting the save button here and not in the question class.php $group[] = $form->createElement('style_submit_button', 'lessOptions', get_lang('DelElem'), 'class="minus"'); $group[] = $form->createElement('style_submit_button', 'moreOptions', get_lang('AddElem'), ' class="plus"'); $group[] = $form->createElement('style_submit_button', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"'); } $form->addGroup($group); if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { $form->setDefaults($defaults); } } $form->setConstants(array('nb_matches' => $nb_matches, 'nb_options' => $nb_options)); }
<td colspan="2">' . $time . '</td> <td>' . $correct_test_link . '</td>'; $output .= '</tr>'; } if (!empty($export_csv)) { $temp = array(); $temp[] = api_html_entity_decode($title, ENT_QUOTES); $temp[] = api_html_entity_decode($my_lesson_status, ENT_QUOTES); if ($row['item_type'] == 'quiz') { if (!$is_allowed_to_edit && $result_disabled_ext_all) { $temp[] = '/'; } else { $temp[] = $score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . Text::float_format($maxscore, 1)); } } else { $temp[] = $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . Text::float_format($maxscore, 1)); } $temp[] = $time; $csv_content[] = $temp; } } $counter++; //var_dump($extend_this_attempt, $extend_all); if ($extend_this_attempt or $extend_all) { $list1 = learnpath::get_iv_interactions_array($row['iv_id']); foreach ($list1 as $id => $interaction) { if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; }
/** * This function draw the graphic to be displayed on the user view as an image * * @param array $sql_result * @param string $start_date * @param string $end_date * @param string $type * @author Jorge Frisancho Jibaja * @version OCT-22- 2010 * @return string */ function grapher($sql_result, $start_date, $end_date, $type = "") { if (empty($start_date)) { $start_date = ""; } if (empty($end_date)) { $end_date = ""; } if ($type == "") { $type = 'day'; } $main_year = $main_month_year = $main_day = array(); // get last 8 days/months $last_days = 5; $last_months = 3; for ($i = $last_days; $i >= 0; $i--) { $main_day[date('d-m-Y', mktime() - $i * 3600 * 24)] = 0; } for ($i = $last_months; $i >= 0; $i--) { $main_month_year[date('m-Y', mktime() - $i * 30 * 3600 * 24)] = 0; } $i = 0; if (is_array($sql_result) && count($sql_result) > 0) { foreach ($sql_result as $key => $data) { //creating the main array $main_month_year[date('m-Y', $data['login'])] += Text::float_format(($data['logout'] - $data['login']) / 60, 0); $main_day[date('d-m-Y', $data['login'])] += Text::float_format(($data['logout'] - $data['login']) / 60, 0); if ($i > 500) { break; } $i++; } switch ($type) { case 'day': $main_date = $main_day; break; case 'month': $main_date = $main_month_year; break; case 'year': $main_date = $main_year; break; } // the nice graphics :D $labels = array_keys($main_date); if (count($main_date) == 1) { $labels = $labels[0]; $main_date = $main_date[$labels]; } $data_set = new pData(); $data_set->AddPoint($main_date, 'Q'); if (count($main_date) != 1) { $data_set->AddPoint($labels, 'Date'); } $data_set->AddAllSeries(); $data_set->RemoveSerie('Date'); $data_set->SetAbsciseLabelSerie('Date'); $data_set->SetYAxisName(get_lang('Minutes', '')); $graph_id = api_get_user_id() . 'AccessDetails' . api_get_course_id() . $start_date . $end_date . $type; $data_set->AddAllSeries(); $cache = new pCache(api_get_path(SYS_ARCHIVE_PATH)); // the graph id $data = $data_set->GetData(); if ($cache->IsInCache($graph_id, $data_set->GetData())) { //if (0) { //if we already created the img // echo 'in cache'; $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } else { // if the image does not exist in the archive/ folder // Initialise the graph $test = new pChart(760, 230); //which schema of color will be used $quant_resources = count($data[0]) - 1; // Adding the color schemma $test->loadColorPalette(api_get_path(LIBRARY_PATH) . 'pchart/palette/default.txt'); $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8); $test->setGraphArea(70, 30, 680, 200); $test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240); $test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230); $test->drawGraphArea(255, 255, 255, TRUE); $test->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0); $test->drawGrid(4, TRUE, 230, 230, 230, 50); $test->setLineStyle(2); // Draw the 0 line $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 6); $test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); if (count($main_date) == 1) { //Draw a graph echo '<strong>' . $labels . '</strong><br/>'; $test->drawBarGraph($data_set->GetData(), $data_set->GetDataDescription(), TRUE); } else { //Draw the line graph $test->drawLineGraph($data_set->GetData(), $data_set->GetDataDescription()); $test->drawPlotGraph($data_set->GetData(), $data_set->GetDataDescription(), 3, 2, 255, 255, 255); } // Finish the graph $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8); $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 10); $test->drawTitle(60, 22, get_lang('AccessDetails'), 50, 50, 50, 585); //------------------ //echo 'not in cache'; $cache->WriteToCache($graph_id, $data_set->GetData(), $test); ob_start(); $test->Stroke(); ob_end_clean(); $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } $foo_img = '<img src="' . api_get_path(WEB_ARCHIVE_PATH) . $img_file . '">'; return $foo_img; } else { $foo_img = api_convert_encoding('<div id="messages" class="warning-message">' . get_lang('GraphicNotAvailable') . '</div>', 'UTF-8'); return $foo_img; } }