Minor - Format code

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 4d7736b6fe
commit 5b53e6078e
  1. 155
      main/exercice/matching.class.php

@ -30,42 +30,40 @@ class Matching extends Question
* function which redefines Question::createAnswersForm * function which redefines Question::createAnswersForm
* @param FormValidator $form * @param FormValidator $form
*/ */
public function createAnswersForm ($form) public function createAnswersForm($form)
{ {
$defaults = array(); $defaults = array();
$navigator_info = api_get_navigator(); $navigator_info = api_get_navigator();
$nb_matches = $nb_options = 2; $nb_matches = $nb_options = 2;
if ($form -> isSubmitted()) { if ($form->isSubmitted()) {
$nb_matches = $form -> getSubmitValue('nb_matches'); $nb_matches = $form->getSubmitValue('nb_matches');
$nb_options = $form -> getSubmitValue('nb_options'); $nb_options = $form->getSubmitValue('nb_options');
if(isset($_POST['lessMatches'])) if (isset($_POST['lessMatches']))
$nb_matches--; $nb_matches--;
if(isset($_POST['moreMatches'])) if (isset($_POST['moreMatches']))
$nb_matches++; $nb_matches++;
if(isset($_POST['lessOptions'])) if (isset($_POST['lessOptions']))
$nb_options--; $nb_options--;
if(isset($_POST['moreOptions'])) if (isset($_POST['moreOptions']))
$nb_options++; $nb_options++;
} else if (!empty($this->id)) {
} else if(!empty($this -> id)) { $answer = new Answer($this->id);
$answer = new Answer($this -> id); $answer->read();
$answer -> read(); if (count($answer->nbrAnswers) > 0) {
if(count($answer->nbrAnswers)>0) {
$a_matches = $a_options = array(); $a_matches = $a_options = array();
$nb_matches = $nb_options = 0; $nb_matches = $nb_options = 0;
for($i=1 ; $i<=$answer->nbrAnswers ; $i++){ for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
if ($answer -> isCorrect($i)) { if ($answer->isCorrect($i)) {
$nb_matches++; $nb_matches++;
$defaults['answer['.$nb_matches.']'] = $answer -> selectAnswer($i); $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
$defaults['weighting['.$nb_matches.']'] = float_format($answer -> selectWeighting($i),1); $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1);
$defaults['matches['.$nb_matches.']'] = $answer -> correct[$i]; $defaults['matches[' . $nb_matches . ']'] = $answer->correct[$i];
} else { } else {
$nb_options++; $nb_options++;
$defaults['option['.$nb_options.']'] = $answer -> selectAnswer($i); $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
} }
} }
} }
} else { } else {
$defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1'); $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
@ -75,120 +73,115 @@ class Matching extends Question
$defaults['option[2]'] = get_lang('DefaultMatchingOptB'); $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
} }
$a_matches = array(); $a_matches = array();
for($i=1 ; $i<=$nb_options ; ++$i) { for ($i = 1; $i <= $nb_options; ++$i) {
$a_matches[$i] = chr(64+$i); // fill the array with A, B, C..... $a_matches[$i] = chr(64 + $i); // fill the array with A, B, C.....
} }
$form -> addElement('hidden', 'nb_matches', $nb_matches); $form->addElement('hidden', 'nb_matches', $nb_matches);
$form -> addElement('hidden', 'nb_options', $nb_options); $form->addElement('hidden', 'nb_options', $nb_options);
// DISPLAY MATCHES // DISPLAY MATCHES
$html='<table class="data_table"> $html = '<table class="data_table">
<tr> <tr>
<th width="10px"> <th width="10px">' . get_lang('Number') . '</th>
'.get_lang('Number').' <th width="40%">' . get_lang('Answer') . '</th>
</th> <th width="40%">' . get_lang('MatchesTo') . '</th>
<th width="40%"> <th width="50px">' . get_lang('Weighting') . '</th>
'.get_lang('Answer').'
</th>
<th width="40%">
'.get_lang('MatchesTo').'
</th>
<th width="50px">
'.get_lang('Weighting').'
</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); $group[] = $form->createElement('text', 'answer[' . $i . ']', null);
$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(
$form -> addGroup($group, null, null, '</td><td>'); 'text',
$form -> addElement ('html', '</td></tr>'); '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>'); $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'),
$group[] = $form->createElement('style_submit_button', 'lessMatches', get_lang('DelElem'),'class="btn minus"'); 'class="btn plus"');
$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') . '</th>
'.get_lang('Number').' <th width="90%"' . get_lang('Answer') . '</th>
</th>
<th width="90%"
'.get_lang('Answer').'
</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));
} }

Loading…
Cancel
Save