Source for file matching.class.php
Documentation is available at matching.class.php
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
* File containing the Matching class.
* @package dokeos.exercise
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER),
* extending the class question
* @package dokeos.exercise
static $typePicture = 'matching.gif';
static $explanationLangVar = 'Matching';
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
$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(isset ($_POST['moreMatches']))
if(isset ($_POST['lessOptions']))
if(isset ($_POST['moreOptions']))
else if(!empty($this -> id))
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))
$defaults['answer['. $nb_matches. ']'] = $answer -> selectAnswer($i);
$defaults['matches['. $nb_matches. ']'] = $answer -> correct[$i];
$defaults['option['. $nb_options. ']'] = $answer -> selectAnswer($i);
$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');
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);
<table class="data_table">
<tr style="text-align: center">
$form -> addElement ('html', $html);
for($i = 1 ; $i <= $nb_matches ; ++ $i)
$form -> addElement ('html', '<tr><td>');
$puce = FormValidator :: createElement ('text', null,null,'value="'. $i. '"');
$group[] = FormValidator :: createElement ('text', 'answer['. $i. ']',null, 'size="30" style="margin-left: 0em;"');
$group[] = FormValidator :: createElement ('select', 'matches['. $i. ']',null,$a_matches);
$group[] = FormValidator :: createElement ('text', 'weighting['. $i. ']',null, 'style="vertical-align:middle;margin-left: 0em;" size="2" value="10"');
$form -> addGroup($group, null, null, '</td><td width="0">');
$form -> addElement ('html', '</td></tr>');
$form -> addElement ('html', '</table></div></div>');
$form -> addGroup($group);
<div class="formw"><br /><br />
<table class="data_table">
<tr style="text-align: center;">
$form -> addElement ('html', $html);
for($i = 1 ; $i <= $nb_options ; ++ $i)
$form -> addElement ('html', '<tr><td>');
$puce = FormValidator :: createElement ('text', null,null,'value="'. chr(64+ $i). '"');
$group[] = FormValidator :: createElement ('text', 'option['. $i. ']',null, 'size="30" style="margin-left: 0em;"');
$form -> addGroup($group, null, null, '</td><td width="0">');
$form -> addElement ('html', '</td></tr>');
$form -> addElement ('html', '</table></div></div>');
$form -> addGroup($group);
$form -> setDefaults($defaults);
$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
* @param the formvalidator instance
$nb_matches = $form -> getSubmitValue('nb_matches');
$nb_options = $form -> getSubmitValue('nb_options');
for($i= 1 ; $i<= $nb_options ; ++ $i)
$option = $form -> getSubmitValue('option['. $i. ']');
$objAnswer->createAnswer($option, 0, '', 0, $position);
for($i= 1 ; $i<= $nb_matches ; ++ $i)
$answer = $form -> getSubmitValue('answer['. $i. ']');
$matches = $form -> getSubmitValue('matches['. $i. ']');
$weighting = $form -> getSubmitValue('weighting['. $i. ']');
$objAnswer->createAnswer($answer,$matches,'',$weighting,$position);
|