Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent da239fdb30
commit 074c81b67b
  1. 1
      main/exercice/exercise_result.php
  2. 24
      main/exercice/exercise_submit.php
  3. 370
      main/exercice/matching.class.php
  4. 1
      main/exercice/overview.php

@ -49,7 +49,6 @@ if ($debug) {
error_log('Entering exercise_result.php: '.print_r($_POST, 1)); error_log('Entering exercise_result.php: '.print_r($_POST, 1));
} }
// general parameters passed via POST/GET
// general parameters passed via POST/GET // general parameters passed via POST/GET
if (empty($origin)) { if (empty($origin)) {
$origin = Security::remove_XSS($_REQUEST['origin']); $origin = Security::remove_XSS($_REQUEST['origin']);

@ -794,8 +794,8 @@ if (!empty($error)) {
echo '<script> echo '<script>
$(function() { $(function() {
//$(".exercise_save_now_button").hide(); //$(".exercise_save_now_button").hide();
$(".main_question").mouseover(function() { $(".main_question").mouseover(function() {
//$(this).find(".exercise_save_now_button").show(); //$(this).find(".exercise_save_now_button").show();
//$(this).addClass("question_highlight"); //$(this).addClass("question_highlight");
}); });
@ -807,17 +807,17 @@ if (!empty($error)) {
$(".no_remind_highlight").hide(); $(".no_remind_highlight").hide();
// if the users validates the form using return key, prevent form action and simulates click on validation button // if the users validates the form using return key, prevent form action and simulates click on validation button
$("#exercise_form").submit(function(){ $("#exercise_form").submit(function(){
$(".question-validate-btn").first().trigger("click"); $(".question-validate-btn").first().trigger("click");
return false; return false;
}); });
}); });
function previous_question(question_num) { function previous_question(question_num) {
url = "exercise_submit.php?'.$params.'&num="+question_num; url = "exercise_submit.php?'.$params.'&num="+question_num;
window.location = url; window.location = url;
} }
function previous_question_and_save(previous_question_id, question_id_to_save) { function previous_question_and_save(previous_question_id, question_id_to_save) {
url = "exercise_submit.php?'.$params.'&num="+previous_question_id; url = "exercise_submit.php?'.$params.'&num="+previous_question_id;
@ -1048,7 +1048,7 @@ if (!empty($error)) {
//BUtton save and continue //BUtton save and continue
switch ($objExercise->type) { switch ($objExercise->type) {
case ONE_PER_PAGE: case ONE_PER_PAGE:
$exercise_actions .= $objExercise->show_button($questionId, $current_question); $exercise_actions .= $objExercise->show_button($questionId, $current_question);
break; break;
case ALL_ON_ONE_PAGE : case ALL_ON_ONE_PAGE :

@ -1,8 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/**
* Code
*/
/** /**
* *
* Class Matching * Class Matching
@ -14,76 +12,79 @@
* @author Eric Marguin * @author Eric Marguin
* @package chamilo.exercise * @package chamilo.exercise
*/ */
class Matching extends Question { class Matching extends Question
static $typePicture = 'matching.gif'; {
static $explanationLangVar = 'Matching'; static $typePicture = 'matching.gif';
static $explanationLangVar = 'Matching';
/**
* Constructor /**
*/ * Constructor
function Matching(){ */
parent::question(); public function Matching()
$this -> type = MATCHING; {
$this -> isContent = $this-> getIsContent(); parent::question();
} $this->type = MATCHING;
$this->isContent = $this-> getIsContent();
/** }
* function which redifines Question::createAnswersForm
* @param the formvalidator instance /**
*/ * function which redefines Question::createAnswersForm
function createAnswersForm ($form) { * @param FormValidator $form
$defaults = array(); */
$navigator_info = api_get_navigator(); public function createAnswersForm ($form)
{
$nb_matches = $nb_options = 2; $defaults = array();
if($form -> isSubmitted()) { $navigator_info = api_get_navigator();
$nb_matches = $form -> getSubmitValue('nb_matches');
$nb_options = $form -> getSubmitValue('nb_options'); $nb_matches = $nb_options = 2;
if(isset($_POST['lessMatches'])) if ($form -> isSubmitted()) {
$nb_matches--; $nb_matches = $form -> getSubmitValue('nb_matches');
if(isset($_POST['moreMatches'])) $nb_options = $form -> getSubmitValue('nb_options');
$nb_matches++; if(isset($_POST['lessMatches']))
if(isset($_POST['lessOptions'])) $nb_matches--;
$nb_options--; if(isset($_POST['moreMatches']))
if(isset($_POST['moreOptions'])) $nb_matches++;
$nb_options++; if(isset($_POST['lessOptions']))
$nb_options--;
} else if(!empty($this -> id)) { if(isset($_POST['moreOptions']))
$answer = new Answer($this -> id); $nb_options++;
$answer -> read();
if(count($answer->nbrAnswers)>0) { } else if(!empty($this -> id)) {
$a_matches = $a_options = array(); $answer = new Answer($this -> id);
$nb_matches = $nb_options = 0; $answer -> read();
for($i=1 ; $i<=$answer->nbrAnswers ; $i++){ if(count($answer->nbrAnswers)>0) {
if ($answer -> isCorrect($i)) { $a_matches = $a_options = array();
$nb_matches++; $nb_matches = $nb_options = 0;
$defaults['answer['.$nb_matches.']'] = $answer -> selectAnswer($i); for($i=1 ; $i<=$answer->nbrAnswers ; $i++){
$defaults['weighting['.$nb_matches.']'] = float_format($answer -> selectWeighting($i),1); if ($answer -> isCorrect($i)) {
$defaults['matches['.$nb_matches.']'] = $answer -> correct[$i]; $nb_matches++;
} else { $defaults['answer['.$nb_matches.']'] = $answer -> selectAnswer($i);
$nb_options++; $defaults['weighting['.$nb_matches.']'] = float_format($answer -> selectWeighting($i),1);
$defaults['option['.$nb_options.']'] = $answer -> selectAnswer($i); $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'; } else {
$defaults['option[1]'] = get_lang('DefaultMatchingOptA'); $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
$defaults['option[2]'] = get_lang('DefaultMatchingOptB'); $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
} $defaults['matches[2]'] = '2';
$a_matches = array(); $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
for($i=1 ; $i<=$nb_options ; ++$i) { $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
$a_matches[$i] = chr(64+$i); // fill the array with A, B, C..... }
} $a_matches = array();
for($i=1 ; $i<=$nb_options ; ++$i) {
$form -> addElement('hidden', 'nb_matches', $nb_matches); $a_matches[$i] = chr(64+$i); // fill the array with A, B, C.....
$form -> addElement('hidden', 'nb_options', $nb_options); }
// DISPLAY MATCHES $form -> addElement('hidden', 'nb_matches', $nb_matches);
$html='<table class="data_table"> $form -> addElement('hidden', 'nb_options', $nb_options);
// DISPLAY MATCHES
$html='<table class="data_table">
<tr> <tr>
<th width="10px"> <th width="10px">
'.get_lang('Number').' '.get_lang('Number').'
@ -99,42 +100,42 @@ class Matching extends Question {
</th> </th>
</tr>'; </tr>';
$form -> addElement ('label', get_lang('MakeCorrespond').'<br /> <img src="../img/fill_field.png">', $html); $form -> addElement ('label', get_lang('MakeCorrespond').'<br /> <img src="../img/fill_field.png">', $html);
if ($nb_matches < 1) { if ($nb_matches < 1) {
$nb_matches = 1; $nb_matches = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
} }
for($i = 1 ; $i <= $nb_matches ; ++$i) { for($i = 1 ; $i <= $nb_matches ; ++$i) {
$form -> addElement ('html', '<tr><td>'); $form -> addElement ('html', '<tr><td>');
$group = array(); $group = array();
$puce = $form->createElement('text', null,null,'value="'.$i.'"'); $puce = $form->createElement('text', null,null,'value="'.$i.'"');
$puce->freeze(); $puce->freeze();
$group[] = $puce; $group[] = $puce;
$group[] = $form->createElement('text', 'answer['.$i.']',null, 'size="60" style="margin-left: 0em;"'); $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('select', 'matches['.$i.']',null,$a_matches);
$group[] = $form->createElement('text', 'weighting['.$i.']',null, array('class' => 'span1', 'value' => 10)); $group[] = $form->createElement('text', 'weighting['.$i.']',null, array('class' => 'span1', 'value' => 10));
$form -> addGroup($group, null, null, '</td><td>'); $form -> addGroup($group, null, null, '</td><td>');
$form -> addElement ('html', '</td></tr>'); $form -> addElement ('html', '</td></tr>');
} }
$form -> addElement ('html', '</table></div></div>'); $form -> addElement ('html', '</table></div></div>');
$group = array(); $group = array();
if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') { 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', 'lessMatches', get_lang('DelElem'),'class="btn minus"');
$group[] = $form->createElement('submit', 'moreMatches', get_lang('AddElem'),'class="btn plus"'); $group[] = $form->createElement('submit', 'moreMatches', get_lang('AddElem'),'class="btn plus"');
} else { } else {
$group[] = $form->createElement('style_submit_button', 'moreMatches', get_lang('AddElem'),'class="btn plus"'); $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', 'lessMatches', get_lang('DelElem'),'class="btn minus"');
} }
$form -> addGroup($group); $form -> addGroup($group);
// DISPLAY OPTIONS // DISPLAY OPTIONS
$html='<table class="data_table"> $html='<table class="data_table">
<tr style="text-align: center;"> <tr style="text-align: center;">
<th width="10px"> <th width="10px">
'.get_lang('Number').' '.get_lang('Number').'
@ -143,95 +144,102 @@ class Matching extends Question {
'.get_lang('Answer').' '.get_lang('Answer').'
</th> </th>
</tr>'; </tr>';
//$form -> addElement ('html', $html); //$form -> addElement ('html', $html);
$form -> addElement ('label', null, $html); $form -> addElement ('label', null, $html);
if ($nb_options < 1) { if ($nb_options < 1) {
$nb_options = 1; $nb_options = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
} }
for($i = 1 ; $i <= $nb_options ; ++$i) { for($i = 1 ; $i <= $nb_options ; ++$i) {
$form -> addElement ('html', '<tr><td>'); $form -> addElement ('html', '<tr><td>');
$group = array(); $group = array();
$puce = $form->createElement('text', null,null,'value="'.chr(64+$i).'"'); $puce = $form->createElement('text', null,null,'value="'.chr(64+$i).'"');
$puce->freeze(); $puce->freeze();
$group[] = $puce; $group[] = $puce;
$group[] = $form->createElement('text', 'option['.$i.']',null, array('class' =>'span6')); $group[] = $form->createElement('text', 'option['.$i.']',null, array('class' =>'span6'));
$form -> addGroup($group, null, null, '</td><td>'); $form -> addGroup($group, null, null, '</td><td>');
$form -> addElement ('html', '</td></tr>'); $form -> addElement ('html', '</td></tr>');
} }
$form -> addElement ('html', '</table></div></div>'); $form -> addElement ('html', '</table></div></div>');
$group = array(); $group = array();
global $text, $class; global $text, $class;
if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') { if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
// setting the save button here and not in the question class.php // setting the save button here and not in the question class.php
$group[] = $form->createElement('submit','submitQuestion',$text, 'class="'.$class.'"'); $group[] = $form->createElement('submit','submitQuestion',$text, 'class="'.$class.'"');
$group[] = $form->createElement('submit', 'lessOptions', get_lang('DelElem'),'class="minus"'); $group[] = $form->createElement('submit', 'lessOptions', get_lang('DelElem'),'class="minus"');
$group[] = $form->createElement('submit', 'moreOptions',get_lang('AddElem'),'class="plus"'); $group[] = $form->createElement('submit', 'moreOptions',get_lang('AddElem'),'class="plus"');
} else { } else {
// setting the save button here and not in the question class.php // 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', 'lessOptions', get_lang('DelElem'),'class="minus"');
$group[] = $form->createElement('style_submit_button', 'moreOptions',get_lang('AddElem'),' class="plus"'); $group[] = $form->createElement('style_submit_button', 'moreOptions',get_lang('AddElem'),' class="plus"');
$group[] = $form->createElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"'); $group[] = $form->createElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
} }
$form -> addGroup($group); $form -> addGroup($group);
if (!empty($this -> id)) { if (!empty($this -> id)) {
$form -> setDefaults($defaults); $form -> setDefaults($defaults);
} else { } else {
if ($this -> isContent == 1) { if ($this -> isContent == 1) {
$form -> setDefaults($defaults); $form -> setDefaults($defaults);
} }
} }
$form->setConstants(array('nb_matches' => $nb_matches,'nb_options' => $nb_options)); $form->setConstants(array('nb_matches' => $nb_matches,'nb_options' => $nb_options));
} }
/** /**
* abstract function which creates the form to create / edit the answers of the question * abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance * @param FormValidator $form
*/ */
function processAnswersCreation($form) { public function processAnswersCreation($form)
{
$nb_matches = $form -> getSubmitValue('nb_matches'); $nb_matches = $form -> getSubmitValue('nb_matches');
$nb_options = $form -> getSubmitValue('nb_options'); $nb_options = $form -> getSubmitValue('nb_options');
$this -> weighting = 0; $this -> weighting = 0;
$objAnswer = new Answer($this->id); $objAnswer = new Answer($this->id);
$position = 0; $position = 0;
// insert the options // insert the options
for($i=1 ; $i<=$nb_options; ++$i) { for($i=1 ; $i<=$nb_options; ++$i) {
$position++; $position++;
$option = $form -> getSubmitValue('option['.$i.']'); $option = $form -> getSubmitValue('option['.$i.']');
$objAnswer->createAnswer($option, 0, '', 0, $position); $objAnswer->createAnswer($option, 0, '', 0, $position);
} }
// insert the answers // insert the answers
for($i=1 ; $i<=$nb_matches ; ++$i) { for($i=1 ; $i<=$nb_matches ; ++$i) {
$position++; $position++;
$answer = $form -> getSubmitValue('answer['.$i.']'); $answer = $form -> getSubmitValue('answer['.$i.']');
$matches = $form -> getSubmitValue('matches['.$i.']'); $matches = $form -> getSubmitValue('matches['.$i.']');
$weighting = $form -> getSubmitValue('weighting['.$i.']'); $weighting = $form -> getSubmitValue('weighting['.$i.']');
$this -> weighting += $weighting; $this -> weighting += $weighting;
$objAnswer->createAnswer($answer,$matches,'',$weighting,$position); $objAnswer->createAnswer($answer,$matches,'',$weighting,$position);
} }
$objAnswer->save(); $objAnswer->save();
$this->save(); $this->save();
} }
function return_header($feedback_type = null, $counter = null, $score = null) { /**
$header = parent::return_header($feedback_type, $counter, $score); * @param null $feedback_type
* @param null $counter
* @param null $score
* @return string
*/
public function return_header($feedback_type = null, $counter = null, $score = null)
{
$header = parent::return_header($feedback_type, $counter, $score);
$header .= '<table class="'.$this->question_table_class .'">'; $header .= '<table class="'.$this->question_table_class .'">';
$header .= '<tr> $header .= '<tr>
<th>'.get_lang('ElementList').'</th> <th>'.get_lang('ElementList').'</th>
<th>'.get_lang('CorrespondsTo').'</th> <th>'.get_lang('CorrespondsTo').'</th>
</tr>'; </tr>';
return $header; return $header;
} }
} }

@ -98,7 +98,6 @@ if (isset($exercise_stat_info['exe_id'])) {
} }
//1. Check if this is a new attempt or a previous //1. Check if this is a new attempt or a previous
//$countNotFinished = isset($exercise_stat_info['num_exe']) ? $exercise_stat_info['num_exe'] : null;
$label = get_lang('StartTest'); $label = get_lang('StartTest');
if ($time_control && !empty($clock_expired_time) || !empty($attempt_list)) { if ($time_control && !empty($clock_expired_time) || !empty($attempt_list)) {
$label = get_lang('ContinueTest'); $label = get_lang('ContinueTest');

Loading…
Cancel
Save