Commit 28a27ef1 authored by pichetp's avatar pichetp
Browse files

MDL-10110 Adding multichoice option in calculated question

parent d578c197
......@@ -128,7 +128,7 @@ class question_dataset_dependent_items_form extends moodleform {
$key1++;
}
$addremoveoptions = Array();
$addremoveoptions = array();
$addremoveoptions['1']='1';
for ($i=10; $i<=100 ; $i+=10){
$addremoveoptions["$i"]="$i";
......@@ -262,10 +262,14 @@ class question_dataset_dependent_items_form extends moodleform {
}
$j--;
}
if($question->options->multichoice == 1 ){
$comment = $this->qtypeobj->multichoice_comment_on_datasetitems($question->id,$answers, $data, $itemnumber);
}else {
$comment = $this->qtypeobj->comment_on_datasetitems($question->id,$answers, $data, $itemnumber);
if ($comment->outsidelimit) {
$this->outsidelimit=$comment->outsidelimit ;
}
}
$totalcomment='';
foreach ($question->options->answers as $key => $answer) {
$totalcomment .= $comment->stranswers[$key].'<br/>';
......@@ -313,10 +317,15 @@ class question_dataset_dependent_items_form extends moodleform {
}
//default answercomment will get ignored if answer element is not in the form.
if($question->options->multichoice == 1 ){
$comment = $this->qtypeobj->multichoice_comment_on_datasetitems($question->id,$answers, $data, $itemnumber);
}else {
$comment = $this->qtypeobj->comment_on_datasetitems($question->id,$answers, $data, ($this->noofitems+1));
if ($comment->outsidelimit) {
$this->outsidelimit=$comment->outsidelimit ;
}
}
$key1 = 1;
foreach ($question->options->answers as $key => $answer) {
$formdata['answercomment['.($this->noofitems+$key1).']'] = $comment->stranswers[$key];
......
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="question/type/calculated/db" VERSION="20090819" COMMENT="XMLDB file for Moodle question/type/calculated. This question type also relies on the question_numerical_units table created by the numerical question type, and the tables created by the datasetdependent question type base class.">
<XMLDB PATH="question/type/calculated/db" VERSION="20090921" COMMENT="XMLDB file for Moodle question/type/calculated. This question type also relies on the question_numerical_units table created by the numerical question type, and the tables created by the datasetdependent question type base class."
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="question_calculated" COMMENT="Options for questions of type calculated" NEXT="question_calculated_options">
<FIELDS>
......@@ -23,11 +26,18 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="question"/>
<FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="synchronize"/>
<FIELD NAME="synchronize" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="question"/>
<FIELD NAME="synchronize" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="question" NEXT="multiplechoice"/>
<FIELD NAME="multiplechoice" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="set for multiple choice calculated question" PREVIOUS="synchronize" NEXT="single"/>
<FIELD NAME="single" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="If 0 it multiple response (checkboxes). Otherwise it is radio buttons." PREVIOUS="multiplechoice" NEXT="shuffleanswers"/>
<FIELD NAME="shuffleanswers" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Whether the choices can be randomly shuffled." PREVIOUS="single" NEXT="correctfeedback"/>
<FIELD NAME="correctfeedback" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Feedback shown for any correct response." PREVIOUS="shuffleanswers" NEXT="partiallycorrectfeedback"/>
<FIELD NAME="partiallycorrectfeedback" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Feedback shown for any partially correct response." PREVIOUS="correctfeedback" NEXT="incorrectfeedback"/>
<FIELD NAME="incorrectfeedback" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Feedback shown for any incorrect response." PREVIOUS="partiallycorrectfeedback" NEXT="answernumbering"/>
<FIELD NAME="answernumbering" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="abc" SEQUENCE="false" COMMENT="Indicates how and whether the choices should be numbered." PREVIOUS="incorrectfeedback"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="question"/>
<KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
<KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
</TABLE>
<TABLE NAME="question_dataset_definitions" COMMENT="Organises and stores properties for dataset items" PREVIOUS="question_calculated_options" NEXT="question_dataset_items">
......
......@@ -33,7 +33,9 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
}
upgrade_plugin_savepoint($result, 2008091700, 'qtype', 'calculated');
}
if ($result && $oldversion < 2009082000 ) { //New version in version.php
// this should be changed if merged to 1.9
// let if ($dbman->table_exists()) replace the normal $oldversion test
// as in any case the question question_calculated_options should be created
......@@ -44,6 +46,14 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('question', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('synchronize', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('multichoice', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0','synchronize');
$table->add_field('single', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0','multichoice');
$table->add_field('shuffleanswers', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0','single');
$table->add_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null,'shuffleanswers');
$table->add_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'correctfeedback');
$table->add_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'partiallycorrectfeedback');
$table->add_field('answernumbering', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'abc', 'incorrectfeedback');
/// Adding keys to table question_calculated_options
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
......@@ -54,7 +64,73 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
// $dbman->create_table doesnt return a result, we just have to trust it
$dbman->create_table($table);
}
upgrade_plugin_savepoint($result, 2009092000, 'qtype', 'calculated');
}
if ($result && $oldversion >= 2009082000 && $oldversion < 2009092000 ) { //New version in version.php
/// Define field multichoice to be added to question_calculated_options
$table = new xmldb_table('question_calculated_options');
$field = new xmldb_field('multichoice', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'synchronize');
/// Conditionally launch add field multichoice
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field single to be added to question_calculated_options
$table = new xmldb_table('question_calculated_options');
$field = new xmldb_field('single', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'multichoice');
/// Conditionally launch add field single
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field shuffleanswers to be added to question_calculated_options
$table = new xmldb_table('question_calculated_options');
$field = new xmldb_field('shuffleanswers', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'single');
/// Conditionally launch add field shuffleanswers
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field correctfeedback to be added to question_calculated_options
$table = new xmldb_table('question_calculated_options');
$field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'shuffleanswers');
/// Conditionally launch add field correctfeedback
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field partiallycorrectfeedback to be added to question_calculated_options
$table = new xmldb_table('question_calculated_options');
$field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'correctfeedback');
/// Conditionally launch add field partiallycorrectfeedback
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field incorrectfeedback to be added to question_calculated_options
$table = new xmldb_table('question_calculated_options');
$field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'partiallycorrectfeedback');
/// Conditionally launch add field incorrectfeedback
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field answernumbering to be added to question_calculated_options
$table = new xmldb_table('question_calculated_options');
$field = new xmldb_field('answernumbering', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'abc', 'incorrectfeedback');
/// Conditionally launch add field answernumbering
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_plugin_savepoint($result, 2009092000, 'qtype', 'calculated');
}
/// calculated savepoint reached
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of database_manager methods
......
......@@ -20,15 +20,52 @@ class question_edit_calculated_form extends question_edit_form {
*/
var $qtypeobj;
/**
* Get the list of form elements to repeat, one for each answer.
* @param object $mform the form being built.
* @param $label the label to use for each option.
* @param $gradeoptions the possible grades for each answer.
* @param $repeatedoptions reference to array of repeated options to fill
* @param $answersoption reference to return the name of $question->options field holding an array of answers
* @return array of form fields.
*/
/* function get_per_answer_fields(&$mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption) {
$repeated = array();
$repeated[] =& $mform->createElement('header', 'answerhdr', $label);
$repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'), array('size' => 50));
$repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions);
$repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz'),
array('course' => $this->coursefilesid));
$repeatedoptions['answer']['type'] = PARAM_RAW;
$repeatedoptions['fraction']['default'] = 0;
$answersoption = 'answers';
return $repeated;
}*/
function get_per_answer_fields(&$mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption) {
$repeated = parent::get_per_answer_fields($mform, $label, $gradeoptions, $repeatedoptions, $answersoption);
// $repeated = parent::get_per_answer_fields($mform, $label, $gradeoptions, $repeatedoptions, $answersoption);
$repeated = array();
$repeated[] =& $mform->createElement('header', 'answerhdr', $label);
// if ($this->editasmultichoice == 1){
$repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'), array('size' => 50));
$repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions);
$repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz'),
array('course' => $this->coursefilesid));
$repeatedoptions['answer']['type'] = PARAM_RAW;
$repeatedoptions['fraction']['default'] = 0;
$answersoption = 'answers';
$mform->setType('answer', PARAM_NOTAGS);
$addrepeated = array();
$addrepeated[] =& $mform->createElement('text', 'tolerance', get_string('tolerance', 'qtype_calculated'));
if ($this->editasmultichoice == 1){
$addrepeated[] =& $mform->createElement('hidden', 'tolerance');
$addrepeated[] =& $mform->createElement('hidden', 'tolerancetype');
}else {
$addrepeated[] =& $mform->createElement('text', 'tolerance', get_string('tolerance', 'qtype_calculated'));
$addrepeated[] =& $mform->createElement('select', 'tolerancetype', get_string('tolerancetype', 'quiz'), $this->qtypeobj->tolerance_types());
}
$repeatedoptions['tolerance']['type'] = PARAM_NUMBER;
$repeatedoptions['tolerance']['default'] = 0.01;
$addrepeated[] =& $mform->createElement('select', 'tolerancetype', get_string('tolerancetype', 'quiz'), $this->qtypeobj->tolerance_types());
$addrepeated[] =& $mform->createElement('select', 'correctanswerlength', get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
$repeatedoptions['correctanswerlength']['default'] = 2;
......@@ -36,7 +73,12 @@ class question_edit_calculated_form extends question_edit_form {
$answerlengthformats = array('1' => get_string('decimalformat', 'quiz'), '2' => get_string('significantfiguresformat', 'quiz'));
$addrepeated[] =& $mform->createElement('select', 'correctanswerformat', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
array_splice($repeated, 3, 0, $addrepeated);
$repeated[1]->setLabel(get_string('correctanswerformula', 'quiz').'=');
if ($this->editasmultichoice == 1){
$repeated[1]->setLabel('...<strong>{={x}+..}</strong>...');
}else {
$repeated[1]->setLabel(get_string('correctanswerformula', 'quiz').'=');
}
return $repeated;
}
......@@ -49,6 +91,8 @@ class question_edit_calculated_form extends question_edit_form {
function definition_inner(&$mform) {
global $QTYPES;
$this->qtypeobj =& $QTYPES[$this->qtype()];
// echo code left for testing period
// echo "<p>question ".optional_param('multichoice', '', PARAM_RAW)." optional<pre>";print_r($this->question);echo "</pre></p>";
$label = get_string("sharedwildcards", "qtype_datasetdependent");
$mform->addElement('hidden', 'initialcategory', 1);
$html2 = $this->qtypeobj->print_dataset_definitions_category($this->question);
......@@ -56,20 +100,93 @@ class question_edit_calculated_form extends question_edit_form {
$addfieldsname='updatecategory';
$addstring=get_string("updatecategory", "qtype_calculated");
$mform->registerNoSubmitButton($addfieldsname);
$this->editasmultichoice = 0 ;
if ( isset($this->question->options->multichoice) && $this->question->options->multichoice == '1'){
$this->editasmultichoice = 1 ;
}else {
if ( !isset($this->question->id ) && '' != optional_param('createoptionbutton', '', PARAM_RAW) && 1 == optional_param('multichoice', '', PARAM_RAW)){
$this->editasmultichoice = 1 ;
}
if ( !isset($this->question->id )== 0 && '' != optional_param('createoptionbutton', '', PARAM_RAW) && 0 == optional_param('multichoice', '', PARAM_RAW)){
$this->editasmultichoice = 0 ;
}
}
/* if ( '' != optional_param('changetomultichoice', '', PARAM_RAW)){
$this->editasmultichoice = 1 ;
}
if ( '' != optional_param('changetocalculated', '', PARAM_RAW)){
$this->editasmultichoice = 0 ;
}*/
$mform->insertElementBefore( $mform->createElement('submit', $addfieldsname, $addstring),'listcategory');
$mform->registerNoSubmitButton('createoptionbutton');
if(!isset($this->question->id ) ){
$mform->addElement('header', 'choicehdr',get_string('Choosingcreationmode', 'qtype_calculated'));
$createoptions = Array();
$createoptions['0']=get_string('Regularcalculated', 'qtype_calculated');
$createoptions['1']=get_string('Multiplechoicecalculated', 'qtype_calculated');
$addgrp1 = array();
$addgrp1[] =& $mform->createElement('submit', 'createoptionbutton', get_string('Createas', 'qtype_calculatedsimple'));
$addgrp1[] =& $mform->createElement('select', "multichoice",'' , $createoptions);
$mform->addGroup($addgrp1, 'addgrp1', '', ' ', false);
}else {
$mform->addElement('hidden', 'multichoice',$this->editasmultichoice);
}
if ($this->editasmultichoice == 1){
$mform->addElement('header', 'choicehdr',get_string('multichoicecalculatedquestion', 'qtype_calculated'));
$menu = array(get_string('answersingleno', 'qtype_multichoice'), get_string('answersingleyes', 'qtype_multichoice'));
$mform->addElement('select', 'single', get_string('answerhowmany', 'qtype_multichoice'), $menu);
$mform->setDefault('single', 1);
$mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffleanswers', 'qtype_multichoice'), null, null, array(0,1));
$mform->setHelpButton('shuffleanswers', array('multichoiceshuffle', get_string('shuffleanswers','qtype_multichoice'), 'qtype_multichoice'));
$mform->setDefault('shuffleanswers', 1);
$numberingoptions = $QTYPES['multichoice']->get_numbering_styles();
$menu = array();
foreach ($numberingoptions as $numberingoption) {
$menu[$numberingoption] = get_string('answernumbering' . $numberingoption, 'qtype_multichoice');
}
$mform->addElement('select', 'answernumbering', get_string('answernumbering', 'qtype_multichoice'), $menu);
$mform->setDefault('answernumbering', 'abc');
}else { //editing as regular
$mform->addElement('header', 'choicehdr', get_string('regularcalculatedquestion', 'qtype_calculated'));
$mform->addElement('hidden','single', '1');
$mform->addElement('hidden','shuffleanswers', '1');
$mform->addElement('hidden','answernumbering', 'abc');
}
$creategrades = get_grade_options();
$this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'),
if ($this->editasmultichoice == 1){
$this->add_per_answer_fields($mform, get_string('choiceno', 'qtype_multichoice', '{no}'),
$creategrades->gradeoptionsfull, max(5, QUESTION_NUMANS_START));
}else{
$this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'),
$creategrades->gradeoptions, 1, 1);
}
$repeated = array();
$repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}'));
if ($this->editasmultichoice == 1){
$nounits = optional_param('nounits', 1, PARAM_INT);
$mform->addElement('hidden', 'nounits', $nounits);
$mform->setConstants(array('nounits'=>$nounits));
for ($i=0; $i< $nounits; $i++) {
$mform->addElement('hidden','unit'."[$i]", optional_param('unit'."[$i]", '', PARAM_NOTAGS));
$mform->addElement('hidden', 'multiplier'."[$i]", optional_param('multiplier'."[$i]", '', PARAM_NUMBER));
}
$repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz'));
}else {
$repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}'));
$repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz'));
$repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz'));
$mform->setType('unit', PARAM_NOTAGS);
$repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz'));
$mform->setType('multiplier', PARAM_NUMBER);
if (isset($this->question->options)){
......@@ -84,12 +201,28 @@ class question_edit_calculated_form extends question_edit_form {
}
$this->repeat_elements($repeated, $repeatsatstart, array(), 'nounits', 'addunits', 2, get_string('addmoreunitblanks', 'qtype_calculated', '{no}'));
}
if ($mform->elementExists('multiplier[0]')){
$firstunit =& $mform->getElement('multiplier[0]');
$firstunit->freeze();
$firstunit->setValue('1.0');
$firstunit->setPersistantFreeze(true);
}
if ($this->editasmultichoice == 1){
$mform->setType('addunits','hidden');
$mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'qtype_multichoice'));
foreach (array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback') as $feedbackname) {
$mform->addElement('htmleditor', $feedbackname, get_string($feedbackname, 'qtype_multichoice'),
array('course' => $this->coursefilesid));
$mform->setType($feedbackname, PARAM_RAW);
}
}else {
foreach (array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback') as $feedbackname) {
$mform->addElement('hidden', $feedbackname);
$mform->setType($feedbackname, PARAM_RAW);
}
}
//hidden elements
$mform->addElement('hidden', 'synchronize', '');
if (isset($this->question->options)&& isset($this->question->options->synchronize) ){
......@@ -104,6 +237,9 @@ class question_edit_calculated_form extends question_edit_form {
}
function set_data($question) {
if (isset($this->editasmultichoice)){
$default_values['multichoice']= 1 ; //$this->editasmultichoice ;
}
if (isset($question->options)){
$answers = $question->options->answers;
if (count($answers)) {
......@@ -119,20 +255,30 @@ class question_edit_calculated_form extends question_edit_form {
$key++;
}
}
$units = array_values($question->options->units);
// make sure the default unit is at index 0
usort($units, create_function('$a, $b',
'if (1.0 === (float)$a->multiplier) { return -1; } else '.
'if (1.0 === (float)$b->multiplier) { return 1; } else { return 0; }'));
if (count($units)) {
$key = 0;
foreach ($units as $unit){
$default_values['unit['.$key.']'] = $unit->unit;
$default_values['multiplier['.$key.']'] = $unit->multiplier;
$key++;
if (isset($question->options->units)){
$units = array_values($question->options->units);
// make sure the default unit is at index 0
usort($units, create_function('$a, $b',
'if (1.0 === (float)$a->multiplier) { return -1; } else '.
'if (1.0 === (float)$b->multiplier) { return 1; } else { return 0; }'));
if (count($units)) {
$key = 0;
foreach ($units as $unit){
$default_values['unit['.$key.']'] = $unit->unit;
$default_values['multiplier['.$key.']'] = $unit->multiplier;
$key++;
}
}
}
}
if (isset($question->options->single)){
$default_values['single'] = $question->options->single;
$default_values['answernumbering'] = $question->options->answernumbering;
$default_values['shuffleanswers'] = $question->options->shuffleanswers;
$default_values['correctfeedback'] = $question->options->correctfeedback;
$default_values['partiallycorrectfeedback'] = $question->options->partiallycorrectfeedback;
$default_values['incorrectfeedback'] = $question->options->incorrectfeedback;
}
$default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
$default_values['makecopy'] = get_string('makecopynextpage', 'qtype_calculated');
/* set the wild cards category display given that on loading the category element is
......@@ -166,6 +312,11 @@ class question_edit_calculated_form extends question_edit_form {
}
function validation($data, $files) {
// echo code left for testing period
// echo "<p>question <pre>";print_r($this->question);echo "</pre></p>";
// echo "<p>data <pre>";print_r($data);echo "</pre></p>";
$errors = parent::validation($data, $files);
//verifying for errors in {=...} in question text;
$qtext = "";
......@@ -201,6 +352,48 @@ class question_edit_calculated_form extends question_edit_form {
$errors['answer['.$key.']'] = get_string('atleastonewildcard', 'qtype_datasetdependent');
}
}
if ($data['multichoice']== 1 ){
foreach ($answers as $key => $answer){
$trimmedanswer = trim($answer);
if (($trimmedanswer!='')||$answercount==0){
//verifying for errors in {=...} in answer text;
$qanswer = "";
$qanswerremaining = $trimmedanswer ;
$possibledatasets = $this->qtypeobj->find_dataset_names($trimmedanswer);
foreach ($possibledatasets as $name => $value) {
$qanswerremaining = str_replace('{'.$name.'}', '1', $qanswerremaining);
}
// echo "numericalquestion qanswerremaining <pre>";print_r($possibledatasets);
while (preg_match('~\{=([^[:space:]}]*)}~', $qanswerremaining, $regs1)) {
$qanswersplits = explode($regs1[0], $qanswerremaining, 2);
$qanswer =$qanswer.$qanswersplits[0];
$qanswerremaining = $qanswersplits[1];
if (!empty($regs1[1]) && $formulaerrors = qtype_calculated_find_formula_errors($regs1[1])) {
if(!isset($errors['answer['.$key.']'])){
$errors['answer['.$key.']'] = $formulaerrors.':'.$regs1[1] ;
}else {
$errors['answer['.$key.']'] .= '<br/>'.$formulaerrors.':'.$regs1[1];
}
}
}
}
if ($trimmedanswer!=''){
if ('2' == $data['correctanswerformat'][$key]
&& '0' == $data['correctanswerlength'][$key]) {
$errors['correctanswerlength['.$key.']'] = get_string('zerosignificantfiguresnotallowed','quiz');
}
if (!is_numeric($data['tolerance'][$key])){
$errors['tolerance['.$key.']'] = get_string('mustbenumeric', 'qtype_calculated');
}
if ($data['fraction'][$key] == 1) {
$maxgrade = true;
}
$answercount++;
}
}
}else{
foreach ($answers as $key => $answer){
//check no of choices
// the * for everykind of answer not actually implemented
......@@ -237,6 +430,7 @@ class question_edit_calculated_form extends question_edit_form {
}
}*/
}
}
//grade checking :
/// Perform sanity checks on fractional grades
/*if ( ) {
......
This diff is collapsed.
<?PHP // $Id$
$plugin->version = 2009082000;
$plugin->version = 2009092000;
$plugin->requires = 2007101000;
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment