From 5b53e6078e79a2321645871991619a245c8926e9 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 20 Mar 2015 09:29:21 -0500 Subject: [PATCH 1/3] Minor - Format code --- main/exercice/matching.class.php | 155 +++++++++++++++---------------- 1 file changed, 74 insertions(+), 81 deletions(-) diff --git a/main/exercice/matching.class.php b/main/exercice/matching.class.php index 5abd240456..660e32ec0d 100755 --- a/main/exercice/matching.class.php +++ b/main/exercice/matching.class.php @@ -30,42 +30,40 @@ class Matching extends Question * function which redefines Question::createAnswersForm * @param FormValidator $form */ - public function createAnswersForm ($form) + public 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'])) + 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'])) + if (isset($_POST['moreMatches'])) $nb_matches++; - if(isset($_POST['lessOptions'])) + if (isset($_POST['lessOptions'])) $nb_options--; - if(isset($_POST['moreOptions'])) + if (isset($_POST['moreOptions'])) $nb_options++; - - } else if(!empty($this -> id)) { - $answer = new Answer($this -> id); - $answer -> read(); - if(count($answer->nbrAnswers)>0) { + } 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; - for($i=1 ; $i<=$answer->nbrAnswers ; $i++){ - if ($answer -> isCorrect($i)) { + 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]; + $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); + $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i); } } - } } else { $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1'); @@ -75,120 +73,115 @@ class Matching extends Question $defaults['option[2]'] = get_lang('DefaultMatchingOptB'); } $a_matches = array(); - for($i=1 ; $i<=$nb_options ; ++$i) { - $a_matches[$i] = chr(64+$i); // fill the array with A, B, C..... + for ($i = 1; $i <= $nb_options; ++$i) { + $a_matches[$i] = chr(64 + $i); // fill the array with A, B, C..... } - $form -> addElement('hidden', 'nb_matches', $nb_matches); - $form -> addElement('hidden', 'nb_options', $nb_options); + $form->addElement('hidden', 'nb_matches', $nb_matches); + $form->addElement('hidden', 'nb_options', $nb_options); // DISPLAY MATCHES - $html=' + $html = '
- - - - + + + + '; - $form -> addElement ('label', get_lang('MakeCorrespond').'
', $html); + $form->addElement('label', get_lang('MakeCorrespond') . '
', $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', ''); + $group[] = $form->createElement('text', 'answer[' . $i . ']', null); + $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, ''); } - $form -> addElement ('html', '
- '.get_lang('Number').' - - '.get_lang('Answer').' - - '.get_lang('MatchesTo').' - - '.get_lang('Weighting').' - ' . get_lang('Number') . '' . get_lang('Answer') . '' . get_lang('MatchesTo') . '' . get_lang('Weighting') . '
'); + for ($i = 1; $i <= $nb_matches; ++$i) { + $form->addElement('html', '
'); $group = array(); - $puce = $form->createElement('text', null,null,'value="'.$i.'"'); + $puce = $form->createElement('text', null, null, 'value="' . $i . '"'); $puce->freeze(); $group[] = $puce; - $group[] = $form->createElement('text', 'answer['.$i.']',null); - $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, ''); - $form -> addElement ('html', '
'); + $form->addElement('html', '
'); + $form->addElement('html', ''); $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"'); + 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"'); + $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); + $form->addGroup($group); // DISPLAY OPTIONS - $html=' + $html = '
- - + '; //$form -> addElement ('html', $html); - $form -> addElement ('label', null, $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', ''); + $group[] = $form->createElement('text', 'option[' . $i . ']', null, array('class' => 'span6')); + $form->addGroup($group, null, null, ''); } - $form -> addElement ('html', '
- '.get_lang('Number').' - + ' . get_lang('Number') . '
'); + for ($i = 1; $i <= $nb_options; ++$i) { + $form->addElement('html', '
'); $group = array(); - $puce = $form->createElement('text', null,null,'value="'.chr(64+$i).'"'); + $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, ''); - $form -> addElement ('html', '
'); + $form->addElement('html', '
'); + $form->addElement('html', ''); $group = array(); 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 - $group[] = $form->createElement('submit','submitQuestion',$text, 'class="'.$class.'"'); - $group[] = $form->createElement('submit', 'lessOptions', get_lang('DelElem'),'class="minus"'); - $group[] = $form->createElement('submit', 'moreOptions',get_lang('AddElem'),'class="plus"'); + $group[] = $form->createElement('submit', 'submitQuestion', $text, 'class="' . $class . '"'); + $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',$text, 'class="'.$class.'"'); + $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', $text, 'class="' . $class . '"'); } - $form -> addGroup($group); + $form->addGroup($group); - if (!empty($this -> id)) { - $form -> setDefaults($defaults); + if (!empty($this->id)) { + $form->setDefaults($defaults); } else { - if ($this -> isContent == 1) { - $form -> setDefaults($defaults); + if ($this->isContent == 1) { + $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)); } From 60e30130c44d2f3ba81573c444e3e0e80a522fe7 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 20 Mar 2015 14:30:23 -0500 Subject: [PATCH 2/3] Fix Matching answers add/edit form --- main/exercice/matching.class.php | 114 ++++++++++++++++++------------- 1 file changed, 67 insertions(+), 47 deletions(-) diff --git a/main/exercice/matching.class.php b/main/exercice/matching.class.php index 660e32ec0d..e9247244b9 100755 --- a/main/exercice/matching.class.php +++ b/main/exercice/matching.class.php @@ -81,15 +81,19 @@ class Matching extends Question $form->addElement('hidden', 'nb_options', $nb_options); // DISPLAY MATCHES - $html = ' - - - - - - '; + $html = '
' . get_lang('Number') . '' . get_lang('Answer') . '' . get_lang('MatchesTo') . '' . get_lang('Weighting') . '
+ + + + + + + + + '; - $form->addElement('label', get_lang('MakeCorrespond') . '
', $html); + $form->addHeader(get_lang('MakeCorrespond')); + $form->addHtml($html); if ($nb_matches < 1) { $nb_matches = 1; @@ -97,47 +101,58 @@ class Matching extends Question } for ($i = 1; $i <= $nb_matches; ++$i) { - $form->addElement('html', '', + "answer[$i]" + ); + $renderer->setElementTemplate( + '', + "matches[$i]" + ); + $renderer->setElementTemplate( + '', + "weighting[$i]" ); - $form->addGroup($group, null, null, ''); + + $form->addHtml(''); + + $form->addHtml(""); + $form->addText("answer[$i]", null); + $form->addSelect("matches[$i]", null, $a_matches); + $form->addText("weighting[$i]", null, true, ['value' => 10]); + + $form->addHtml(''); } - $form->addElement('html', '
' . get_lang('Number') . '' . get_lang('Answer') . '' . get_lang('MatchesTo') . '' . get_lang('Weighting') . '
'); - $group = array(); - $puce = $form->createElement('text', null, null, 'value="' . $i . '"'); - $puce->freeze(); - $group[] = $puce; - - $group[] = $form->createElement('text', 'answer[' . $i . ']', null); - $group[] = $form->createElement('select', 'matches[' . $i . ']', null, $a_matches); - $group[] = $form->createElement( - 'text', - 'weighting[' . $i . ']', - null, - array('class' => 'span1', 'value' => 10) + $renderer = &$form->defaultRenderer(); + + $renderer->setElementTemplate( + '{error}{element}{error}{element}{error}{element}'); - $form->addElement('html', '
$i
'); + $form->addHtml(''); $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"'); + $renderer->setElementTemplate('
{element}', 'lessMatches'); + $renderer->setElementTemplate('{element}
', 'moreMatches'); + + $group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessMatches', true); + $group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreMatches', true); } $form->addGroup($group); // DISPLAY OPTIONS - $html = ' - - - '; - //$form -> addElement ('html', $html); - $form->addElement('label', null, $html); + $html = '
' . get_lang('Number') . ' -
+ + + + + + + '; + + $form->addHtml($html); if ($nb_options < 1) { $nb_options = 1; @@ -145,17 +160,22 @@ class Matching extends Question } for ($i = 1; $i <= $nb_options; ++$i) { - $form->addElement('html', ''); + $renderer = &$form->defaultRenderer(); + + $renderer->setElementTemplate( + '', + "option[$i]" + ); + + $form->addHtml(''); + + $form->addHtml(''); + $form->addText("option[$i]", null); + + $form->addHtml(''); } - $form->addElement('html', '
' . get_lang('Number') . '' . get_lang('Answer') . '
'); - $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, ''); - $form->addElement('html', '
{error}{element}
' . chr(64 + $i) . '
'); + $form->addHtml(''); $group = array(); global $text, $class; @@ -166,9 +186,9 @@ class Matching extends Question $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', $text, 'class="' . $class . '"'); + $group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessOptions', true); + $group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreOptions', true); + $group[] = $form->addButtonSave($text, 'submitQuestion', true); } $form->addGroup($group); From b862c79b25e2388a15f743fd9f07a085f6ded79f Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 20 Mar 2015 15:31:12 -0500 Subject: [PATCH 3/3] Fix button template --- main/inc/lib/pear/HTML/QuickForm/button.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/inc/lib/pear/HTML/QuickForm/button.php b/main/inc/lib/pear/HTML/QuickForm/button.php index 073a6bfbdd..bcb51ef8a9 100755 --- a/main/inc/lib/pear/HTML/QuickForm/button.php +++ b/main/inc/lib/pear/HTML/QuickForm/button.php @@ -98,7 +98,7 @@ class HTML_QuickForm_button extends HTML_QuickForm_input return $this->_getTabs() . ' - ';