MDL-27410 Big cleanup of the coding style in qtype_calculated.
This commit is contained in:
@@ -71,8 +71,8 @@ class backup_qtype_calculated_plugin extends backup_qtype_plugin {
|
||||
$calculatedoptions = new backup_nested_element('calculated_options');
|
||||
$calculatedoption = new backup_nested_element('calculated_option', array('id'), array(
|
||||
'synchronize', 'single', 'shuffleanswers', 'correctfeedback',
|
||||
'correctfeedbackformat', 'partiallycorrectfeedback', 'partiallycorrectfeedbackformat', 'incorrectfeedback',
|
||||
'incorrectfeedbackformat', 'answernumbering'));
|
||||
'correctfeedbackformat', 'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
|
||||
'incorrectfeedback', 'incorrectfeedbackformat', 'answernumbering'));
|
||||
|
||||
// Now the own qtype tree
|
||||
$pluginwrapper->add_child($calculatedrecords);
|
||||
@@ -82,8 +82,10 @@ class backup_qtype_calculated_plugin extends backup_qtype_plugin {
|
||||
$calculatedoptions->add_child($calculatedoption);
|
||||
|
||||
// set source to populate the data
|
||||
$calculatedrecord->set_source_table('question_calculated', array('question' => backup::VAR_PARENTID));
|
||||
$calculatedoption->set_source_table('question_calculated_options', array('question' => backup::VAR_PARENTID));
|
||||
$calculatedrecord->set_source_table('question_calculated',
|
||||
array('question' => backup::VAR_PARENTID));
|
||||
$calculatedoption->set_source_table('question_calculated_options',
|
||||
array('question' => backup::VAR_PARENTID));
|
||||
|
||||
// don't need to annotate ids nor files
|
||||
|
||||
|
||||
@@ -53,11 +53,11 @@ class restore_qtype_calculated_plugin extends restore_qtype_plugin {
|
||||
|
||||
// Add own qtype stuff
|
||||
$elename = 'calculated_record';
|
||||
$elepath = $this->get_pathfor('/calculated_records/calculated_record'); // we used get_recommended_name() so this works
|
||||
$elepath = $this->get_pathfor('/calculated_records/calculated_record');
|
||||
$paths[] = new restore_path_element($elename, $elepath);
|
||||
|
||||
$elename = 'calculated_option';
|
||||
$elepath = $this->get_pathfor('/calculated_options/calculated_option'); // we used get_recommended_name() so this works
|
||||
$elepath = $this->get_pathfor('/calculated_options/calculated_option');
|
||||
$paths[] = new restore_path_element($elename, $elepath);
|
||||
|
||||
return $paths; // And we return the interesting paths
|
||||
@@ -75,19 +75,17 @@ class restore_qtype_calculated_plugin extends restore_qtype_plugin {
|
||||
// Detect if the question is created or mapped
|
||||
$oldquestionid = $this->get_old_parentid('question');
|
||||
$newquestionid = $this->get_new_parentid('question');
|
||||
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
|
||||
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ?
|
||||
true : false;
|
||||
|
||||
// If the question has been created by restore, we need to create its question_calculated too
|
||||
// If the question has been created by restore, we need to create its
|
||||
// question_calculated too
|
||||
if ($questioncreated) {
|
||||
// Adjust some columns
|
||||
$data->question = $newquestionid;
|
||||
$data->answer = $this->get_mappingid('question_answer', $data->answer);
|
||||
// Insert record
|
||||
$newitemid = $DB->insert_record('question_calculated', $data);
|
||||
// Create mapping (not needed, no files nor childs nor states here)
|
||||
//$this->set_mapping('question_calculated', $oldid, $newitemid);
|
||||
} else {
|
||||
// Nothing to remap if the question already existed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,18 +101,16 @@ class restore_qtype_calculated_plugin extends restore_qtype_plugin {
|
||||
// Detect if the question is created or mapped
|
||||
$oldquestionid = $this->get_old_parentid('question');
|
||||
$newquestionid = $this->get_new_parentid('question');
|
||||
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
|
||||
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ?
|
||||
true : false;
|
||||
|
||||
// If the question has been created by restore, we need to create its question_calculated too
|
||||
// If the question has been created by restore, we need to create its
|
||||
// question_calculated too
|
||||
if ($questioncreated) {
|
||||
// Adjust some columns
|
||||
$data->question = $newquestionid;
|
||||
// Insert record
|
||||
$newitemid = $DB->insert_record('question_calculated_options', $data);
|
||||
// Create mapping (not needed, no files nor childs nor states here)
|
||||
// $this->set_mapping('question_calculated_option', $oldid, $newitemid);
|
||||
} else {
|
||||
// Nothing to remap if the question already existed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,42 +41,43 @@ class question_dataset_dependent_definitions_form extends moodleform {
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
var $question;
|
||||
protected $question;
|
||||
/**
|
||||
* Reference to question type object
|
||||
*
|
||||
* @var question_dataset_dependent_questiontype
|
||||
*/
|
||||
var $qtypeobj;
|
||||
protected $qtypeobj;
|
||||
/**
|
||||
* Add question-type specific form fields.
|
||||
*
|
||||
* @param MoodleQuickForm $mform the form being built.
|
||||
*/
|
||||
function question_dataset_dependent_definitions_form($submiturl, $question){
|
||||
global $QTYPES, $DB;
|
||||
public function __construct($submiturl, $question) {
|
||||
global $DB;
|
||||
$this->question = $question;
|
||||
$this->qtypeobj =& $QTYPES[$this->question->qtype];
|
||||
$this->qtypeobj = $QTYPES[$this->question->qtype];
|
||||
// Validate the question category.
|
||||
if (!$category = $DB->get_record('question_categories', array('id' => $question->category))) {
|
||||
if (!$category = $DB->get_record('question_categories',
|
||||
array('id' => $question->category))) {
|
||||
print_error('categorydoesnotexist', 'question', $returnurl);
|
||||
}
|
||||
$this->category = $category;
|
||||
$this->categorycontext = get_context_instance_by_id($category->contextid);
|
||||
parent::moodleform($submiturl);
|
||||
parent::__construct($submiturl);
|
||||
}
|
||||
|
||||
protected function definition() {
|
||||
global $SESSION;
|
||||
$mform =& $this->_form;
|
||||
$mform = $this->_form;
|
||||
$possibledatasets = $this->qtypeobj->find_dataset_names($this->question->questiontext);
|
||||
$mandatorydatasets = array();
|
||||
if (isset($this->question->options->answers)){
|
||||
if (isset($this->question->options->answers)) {
|
||||
foreach ($this->question->options->answers as $answer) {
|
||||
$mandatorydatasets += $this->qtypeobj->find_dataset_names($answer->answer);
|
||||
}
|
||||
}else{
|
||||
foreach ($SESSION->calculated->questionform->answers as $answer){
|
||||
} else {
|
||||
foreach ($SESSION->calculated->questionform->answers as $answer) {
|
||||
$mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
|
||||
}
|
||||
}
|
||||
@@ -86,8 +87,10 @@ class question_dataset_dependent_definitions_form extends moodleform {
|
||||
$datadefscat = $this->qtypeobj->get_dataset_definitions_category($this->question);
|
||||
$datasetmenus = array();
|
||||
$label = "<div class='mdl-align'>".get_string('datasetrole', 'qtype_calculated')."</div>";
|
||||
$mform->addElement('html', $label);// explaining the role of datasets so other strings can be shortened
|
||||
$mform->addElement('header', 'mandatoryhdr', get_string('mandatoryhdr', 'qtype_calculated'));
|
||||
// explaining the role of datasets so other strings can be shortened
|
||||
$mform->addElement('html', $label);
|
||||
$mform->addElement('header', 'mandatoryhdr',
|
||||
get_string('mandatoryhdr', 'qtype_calculated'));
|
||||
$labelsharedwildcard = get_string('sharedwildcard', 'qtype_calculated');
|
||||
|
||||
foreach ($mandatorydatasets as $datasetname) {
|
||||
@@ -95,52 +98,60 @@ class question_dataset_dependent_definitions_form extends moodleform {
|
||||
list($options, $selected) =
|
||||
$this->qtypeobj->dataset_options($this->question, $datasetname);
|
||||
unset($options['0']); // Mandatory...
|
||||
$label = get_string("wildcard", "qtype_calculated"). " <strong>$datasetname</strong> ";
|
||||
$label = get_string('wildcard', 'qtype_calculated').
|
||||
" <strong>$datasetname</strong> ";
|
||||
$mform->addElement('select', "dataset[$key]", $label, $options);
|
||||
if (isset($datadefscat[$datasetname])){
|
||||
$mform->addElement('static', "there is a category", get_string('sharedwildcard', 'qtype_calculated',$datasetname ), get_string('dataitemdefined','qtype_calculated', $datadefscat[$datasetname]));
|
||||
}
|
||||
if (isset($datadefscat[$datasetname])) {
|
||||
$mform->addElement('static', "there is a category",
|
||||
get_string('sharedwildcard', 'qtype_calculated', $datasetname),
|
||||
get_string('dataitemdefined', 'qtype_calculated',
|
||||
$datadefscat[$datasetname]));
|
||||
}
|
||||
$mform->setDefault("dataset[$key]", $selected);
|
||||
$datasetmenus[$datasetname]='';
|
||||
$datasetmenus[$datasetname] = '';
|
||||
$key++;
|
||||
}
|
||||
}
|
||||
$mform->addElement('header', 'possiblehdr', get_string('possiblehdr', 'qtype_calculated'));
|
||||
|
||||
$mform->addElement('header', 'possiblehdr', get_string('possiblehdr', 'qtype_calculated'));
|
||||
|
||||
foreach ($possibledatasets as $datasetname) {
|
||||
if (!isset($datasetmenus[$datasetname])) {
|
||||
list($options, $selected) =
|
||||
$this->qtypeobj->dataset_options($this->question, $datasetname,false);
|
||||
$label = get_string("wildcard", "qtype_calculated"). " <strong>$datasetname</strong> ";
|
||||
list($options, $selected) = $this->qtypeobj->dataset_options(
|
||||
$this->question, $datasetname, false);
|
||||
$label = get_string('wildcard', 'qtype_calculated') .
|
||||
" <strong>$datasetname</strong> ";
|
||||
$mform->addElement('select', "dataset[$key]", $label, $options);
|
||||
// $mform->addRule("dataset[$key]", null, 'required', null, 'client');
|
||||
if (isset($datadefscat[$datasetname])){
|
||||
$mform->addElement('static', "there is a category", get_string('sharedwildcard', 'qtype_calculated',$datasetname ), get_string('dataitemdefined',"qtype_calculated", $datadefscat[$datasetname]));
|
||||
}
|
||||
if (isset($datadefscat[$datasetname])) {
|
||||
$mform->addElement('static', "there is a category",
|
||||
get_string('sharedwildcard', 'qtype_calculated', $datasetname),
|
||||
get_string('dataitemdefined', 'qtype_calculated',
|
||||
$datadefscat[$datasetname]));
|
||||
}
|
||||
|
||||
// $selected ="0";
|
||||
$mform->setDefault("dataset[$key]", $selected);
|
||||
$datasetmenus[$datasetname]='';
|
||||
$datasetmenus[$datasetname] = '';
|
||||
$key++;
|
||||
}
|
||||
}
|
||||
// temporary strings
|
||||
// temporary strings
|
||||
$mform->addElement('header', 'synchronizehdr', get_string('synchronize', 'qtype_calculated'));
|
||||
$mform->addElement('radio', 'synchronize', '', get_string('synchronizeno', 'qtype_calculated'),0);
|
||||
$mform->addElement('radio', 'synchronize', '', get_string('synchronizeyes', 'qtype_calculated'),1);
|
||||
$mform->addElement('radio', 'synchronize', '', get_string('synchronizeyesdisplay', 'qtype_calculated'),2);
|
||||
if (isset($this->question->options)&& isset($this->question->options->synchronize) ){
|
||||
$mform->setDefault("synchronize", $this->question->options->synchronize);
|
||||
$mform->addElement('header', 'synchronizehdr',
|
||||
get_string('synchronize', 'qtype_calculated'));
|
||||
$mform->addElement('radio', 'synchronize', '',
|
||||
get_string('synchronizeno', 'qtype_calculated'), 0);
|
||||
$mform->addElement('radio', 'synchronize', '',
|
||||
get_string('synchronizeyes', 'qtype_calculated'), 1);
|
||||
$mform->addElement('radio', 'synchronize', '',
|
||||
get_string('synchronizeyesdisplay', 'qtype_calculated'), 2);
|
||||
if (isset($this->question->options) &&
|
||||
isset($this->question->options->synchronize)) {
|
||||
$mform->setDefault('synchronize', $this->question->options->synchronize);
|
||||
} else {
|
||||
$mform->setDefault("synchronize", 0 );
|
||||
$mform->setDefault('synchronize', 0);
|
||||
}
|
||||
|
||||
$this->add_action_buttons(false, get_string('nextpage', 'qtype_calculated'));
|
||||
|
||||
|
||||
//hidden elements
|
||||
// Hidden elements
|
||||
$mform->addElement('hidden', 'returnurl');
|
||||
$mform->setType('returnurl', PARAM_LOCALURL);
|
||||
$mform->setDefault('returnurl', 0);
|
||||
@@ -163,28 +174,22 @@ class question_dataset_dependent_definitions_form extends moodleform {
|
||||
$mform->addElement('hidden', 'wizard', 'datasetitems');
|
||||
$mform->setType('wizard', PARAM_ALPHA);
|
||||
}
|
||||
/* function set_data($question) {
|
||||
$formdata = array();
|
||||
$fromform = new stdClass();
|
||||
$default_values['synchronize'] = $question->options->synchronize ;
|
||||
$question = (object)((array)$question + $default_values);
|
||||
}*/
|
||||
function validation($data, $files) {
|
||||
|
||||
public function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
$datasets = $data['dataset'];
|
||||
$countvalid = 0 ;
|
||||
foreach ($datasets as $key => $dataset){
|
||||
if ($dataset !="0") {
|
||||
$countvalid = 0;
|
||||
foreach ($datasets as $key => $dataset) {
|
||||
if ($dataset != '0') {
|
||||
$countvalid++;
|
||||
}
|
||||
}
|
||||
if (!$countvalid){
|
||||
foreach ($datasets as $key => $dataset){
|
||||
$errors['dataset['.$key.']'] = get_string('atleastonerealdataset', 'qtype_calculated');
|
||||
if (!$countvalid) {
|
||||
foreach ($datasets as $key => $dataset) {
|
||||
$errors['dataset['.$key.']'] =
|
||||
get_string('atleastonerealdataset', 'qtype_calculated');
|
||||
}
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -57,33 +57,37 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
|
||||
public $noofitems;
|
||||
|
||||
public $outsidelimit = false ;
|
||||
public $outsidelimit = false;
|
||||
|
||||
public $commentanswers = array();
|
||||
|
||||
/**
|
||||
* Add question-type specific form fields.
|
||||
*
|
||||
* @param MoodleQuickForm $mform the form being built.
|
||||
*/
|
||||
function question_dataset_dependent_items_form($submiturl, $question, $regenerate){
|
||||
global $QTYPES, $SESSION, $CFG, $DB;
|
||||
public function __construct($submiturl, $question, $regenerate) {
|
||||
global $SESSION, $CFG, $DB;
|
||||
$this->regenerate = $regenerate;
|
||||
$this->question = $question;
|
||||
$this->qtypeobj =& $QTYPES[$this->question->qtype];
|
||||
// Validate the question category.
|
||||
if (!$category = $DB->get_record('question_categories', array('id' => $question->category))) {
|
||||
if (!$category = $DB->get_record('question_categories',
|
||||
array('id' => $question->category))) {
|
||||
print_error('categorydoesnotexist', 'question', $returnurl);
|
||||
}
|
||||
$this->category = $category;
|
||||
$this->categorycontext = get_context_instance_by_id($category->contextid);
|
||||
//get the dataset defintions for this question
|
||||
if (empty($question->id)) {
|
||||
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset);
|
||||
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions(
|
||||
$question->id, $SESSION->calculated->definitionform->dataset);
|
||||
} else {
|
||||
if (empty($question->options)) {
|
||||
$this->get_question_options($question);
|
||||
}
|
||||
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
|
||||
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions(
|
||||
$question->id, array());
|
||||
}
|
||||
|
||||
foreach ($this->datasetdefs as $datasetdef) {
|
||||
@@ -94,45 +98,45 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
}
|
||||
foreach ($this->datasetdefs as $defid => $datasetdef) {
|
||||
if (isset($datasetdef->id)) {
|
||||
$this->datasetdefs[$defid]->items = $this->qtypeobj->get_database_dataset_items($datasetdef->id);
|
||||
$this->datasetdefs[$defid]->items =
|
||||
$this->qtypeobj->get_database_dataset_items($datasetdef->id);
|
||||
}
|
||||
}
|
||||
parent::moodleform($submiturl);
|
||||
parent::__construct($submiturl);
|
||||
}
|
||||
|
||||
protected function definition() {
|
||||
$labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated");
|
||||
|
||||
$mform =& $this->_form;
|
||||
$strquestionlabel = $this->qtypeobj->comment_header($this->question);
|
||||
if ($this->maxnumber != -1){
|
||||
if ($this->maxnumber != -1 ) {
|
||||
$this->noofitems = $this->maxnumber;
|
||||
} else {
|
||||
$this->noofitems = 0;
|
||||
}
|
||||
$label = get_string("sharedwildcards", "qtype_calculated");
|
||||
//
|
||||
$html2 = $this->qtypeobj->print_dataset_definitions_category_shared($this->question,$this->datasetdefs);
|
||||
$mform->addElement('static','listcategory',$label,$html2);
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
$mform->addElement('submit', 'updatedatasets', get_string('updatedatasetparam', 'qtype_calculated'));
|
||||
|
||||
$html2 = $this->qtypeobj->print_dataset_definitions_category_shared(
|
||||
$this->question, $this->datasetdefs);
|
||||
$mform->addElement('static', 'listcategory', $label, $html2);
|
||||
//----------------------------------------------------------------------
|
||||
$mform->addElement('submit', 'updatedatasets',
|
||||
get_string('updatedatasetparam', 'qtype_calculated'));
|
||||
$mform->registerNoSubmitButton('updatedatasets');
|
||||
$mform->addElement('header', 'additemhdr', get_string('itemtoadd', 'qtype_calculated'));
|
||||
$mform->addElement('header', 'additemhdr',
|
||||
get_string('itemtoadd', 'qtype_calculated'));
|
||||
$idx = 1;
|
||||
$data = array();
|
||||
$j = (($this->noofitems) * count($this->datasetdefs))+1;
|
||||
foreach ($this->datasetdefs as $defkey => $datasetdef){
|
||||
if($datasetdef->category |= 0 ) {
|
||||
$name = get_string('sharedwildcardname', 'qtype_calculated',$datasetdef->name) ;
|
||||
}else {
|
||||
foreach ($this->datasetdefs as $defkey => $datasetdef) {
|
||||
if ($datasetdef->category |= 0 ) {
|
||||
$name = get_string('sharedwildcardname', 'qtype_calculated', $datasetdef->name);
|
||||
} else {
|
||||
$name = get_string('wildcard', 'qtype_calculated', $datasetdef->name);
|
||||
}
|
||||
$mform->addElement('text', "number[$j]", $name);
|
||||
$mform->setType("number[$j]", PARAM_NUMBER);
|
||||
/* if($datasetdef->category |= 0 && $datasetdef->category == $this->category){
|
||||
$mform->addElement('static', "there is a category", $labelsharedwildcard." <strong>$datasetdef->name </strong>", get_string('dataitemdefined',"qtype_calculated", $datasetdef->itemcount));
|
||||
}else if($datasetdef->category |= 0 && $datasetdef->category != $this->category){
|
||||
$mform->addElement('static', "BAD a category", $labelsharedwildcard." <strong>$datasetdef->name </strong>", get_string('dataitemdefined',"qtype_calculated", $datasetdef->itemcount));
|
||||
}*/
|
||||
$this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);
|
||||
$idx++;
|
||||
$mform->addElement('hidden', "definition[$j]");
|
||||
@@ -143,124 +147,148 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
$mform->setType("divider[$j]", PARAM_RAW);
|
||||
$j++;
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'updateanswershdr', get_string('answerstoleranceparam', 'qtype_calculated'));
|
||||
$mform->addElement('submit', 'updateanswers', get_string('updatetolerancesparam', 'qtype_calculated'));
|
||||
$mform->setAdvanced('updateanswers',true);
|
||||
|
||||
$mform->addElement('header', 'updateanswershdr',
|
||||
get_string('answerstoleranceparam', 'qtype_calculated'));
|
||||
$mform->addElement('submit', 'updateanswers',
|
||||
get_string('updatetolerancesparam', 'qtype_calculated'));
|
||||
$mform->setAdvanced('updateanswers', true);
|
||||
$mform->registerNoSubmitButton('updateanswers');
|
||||
|
||||
$answers = fullclone($this->question->options->answers);
|
||||
$key1 =1;
|
||||
foreach ($answers as $key => $answer) {
|
||||
if ('' === $answer->answer){
|
||||
}else if ('*' === $answer->answer){
|
||||
$mform->addElement('static', 'answercomment['.($this->noofitems+$key1).']', $answer->answer);
|
||||
if ('' === $answer->answer) {
|
||||
// Do nothing.
|
||||
} else if ('*' === $answer->answer) {
|
||||
$mform->addElement('static',
|
||||
'answercomment[' . ($this->noofitems+$key1) . ']', $answer->answer);
|
||||
$mform->addElement('hidden', 'tolerance['.$key.']', '');
|
||||
$mform->setType('tolerance['.$key.']', PARAM_RAW);
|
||||
$mform->setAdvanced('tolerance['.$key.']',true);
|
||||
$mform->setAdvanced('tolerance['.$key.']', true);
|
||||
$mform->addElement('hidden', 'tolerancetype['.$key.']', '');
|
||||
$mform->setType('tolerancetype['.$key.']', PARAM_RAW);
|
||||
$mform->setAdvanced('tolerancetype['.$key.']',true);
|
||||
$mform->setAdvanced('tolerancetype['.$key.']', true);
|
||||
$mform->addElement('hidden', 'correctanswerlength['.$key.']', '');
|
||||
$mform->setType('correctanswerlength['.$key.']', PARAM_RAW);
|
||||
$mform->setAdvanced('correctanswerlength['.$key.']',true);
|
||||
$mform->setAdvanced('correctanswerlength['.$key.']', true);
|
||||
$mform->addElement('hidden', 'correctanswerformat['.$key.']', '');
|
||||
$mform->setType('correctanswerformat['.$key.']', PARAM_RAW);
|
||||
$mform->setAdvanced('correctanswerformat['.$key.']',true);
|
||||
}else {
|
||||
$mform->addElement('static', 'answercomment['.($this->noofitems+$key1).']', $answer->answer);
|
||||
$mform->addElement('text', 'tolerance['.$key.']', get_string('tolerance', 'qtype_calculated'));
|
||||
$mform->setAdvanced('tolerance['.$key.']',true);
|
||||
$mform->addElement('select', 'tolerancetype['.$key.']', get_string('tolerancetype', 'qtype_numerical'), $this->qtypeobj->tolerance_types());
|
||||
$mform->setAdvanced('tolerancetype['.$key.']',true);
|
||||
$mform->setAdvanced('correctanswerformat['.$key.']', true);
|
||||
} else {
|
||||
$mform->addElement('static', 'answercomment[' . ($this->noofitems+$key1) . ']',
|
||||
$answer->answer);
|
||||
$mform->addElement('text', 'tolerance['.$key.']',
|
||||
get_string('tolerance', 'qtype_calculated'));
|
||||
$mform->setAdvanced('tolerance['.$key.']', true);
|
||||
$mform->addElement('select', 'tolerancetype['.$key.']',
|
||||
get_string('tolerancetype', 'qtype_numerical'),
|
||||
$this->qtypeobj->tolerance_types());
|
||||
$mform->setAdvanced('tolerancetype['.$key.']', true);
|
||||
|
||||
$mform->addElement('select', 'correctanswerlength['.$key.']', get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
|
||||
$mform->setAdvanced('correctanswerlength['.$key.']',true);
|
||||
$mform->addElement('select', 'correctanswerlength['.$key.']',
|
||||
get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
|
||||
$mform->setAdvanced('correctanswerlength['.$key.']', true);
|
||||
|
||||
$answerlengthformats = array('1' => get_string('decimalformat', 'qtype_numerical'), '2' => get_string('significantfiguresformat', 'quiz'));
|
||||
$mform->addElement('select', 'correctanswerformat['.$key.']', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
|
||||
$mform->setAdvanced('correctanswerformat['.$key.']',true);
|
||||
$answerlengthformats = array(
|
||||
'1' => get_string('decimalformat', 'qtype_numerical'),
|
||||
'2' => get_string('significantfiguresformat', 'quiz')
|
||||
);
|
||||
$mform->addElement('select', 'correctanswerformat['.$key.']',
|
||||
get_string('correctanswershowsformat', 'qtype_calculated'),
|
||||
$answerlengthformats);
|
||||
$mform->setAdvanced('correctanswerformat['.$key.']', true);
|
||||
$mform->addElement('static', 'dividertolerance', '', '<hr />');
|
||||
$mform->setAdvanced('dividertolerance',true);
|
||||
$mform->setAdvanced('dividertolerance', true);
|
||||
}
|
||||
$key1++;
|
||||
}
|
||||
|
||||
$addremoveoptions = array();
|
||||
$addremoveoptions['1']='1';
|
||||
for ($i=10; $i<=100 ; $i+=10){
|
||||
for ($i=10; $i<=100; $i+=10) {
|
||||
$addremoveoptions["$i"]="$i";
|
||||
}
|
||||
$showoptions = Array();
|
||||
$showoptions['1']='1';
|
||||
$showoptions['2']='2';
|
||||
$showoptions['5']='5';
|
||||
for ($i=10; $i<=100 ; $i+=10){
|
||||
for ($i=10; $i<=100; $i+=10) {
|
||||
$showoptions["$i"]="$i";
|
||||
}
|
||||
$mform->addElement('header', 'additemhdr', get_string('add', 'moodle'));
|
||||
$mform->closeHeaderBefore('additemhdr');
|
||||
|
||||
if ($this->qtypeobj->supports_dataset_item_generation()){
|
||||
if ($this->qtypeobj->supports_dataset_item_generation()) {
|
||||
$radiogrp = array();
|
||||
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]', null, get_string('reuseifpossible', 'qtype_calculated'), 0);
|
||||
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]', null, get_string('forceregenerationshared', 'qtype_calculated'), 1);
|
||||
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]', null, get_string('forceregenerationall', 'qtype_calculated'), 2);
|
||||
$mform->addGroup($radiogrp, 'forceregenerationgrp', get_string('nextitemtoadd', 'qtype_calculated'), "<br/>", false);
|
||||
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]',
|
||||
null, get_string('reuseifpossible', 'qtype_calculated'), 0);
|
||||
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]',
|
||||
null, get_string('forceregenerationshared', 'qtype_calculated'), 1);
|
||||
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]',
|
||||
null, get_string('forceregenerationall', 'qtype_calculated'), 2);
|
||||
$mform->addGroup($radiogrp, 'forceregenerationgrp',
|
||||
get_string('nextitemtoadd', 'qtype_calculated'), "<br/>", false);
|
||||
}
|
||||
|
||||
$mform->addElement('submit', 'getnextbutton', get_string('getnextnow', 'qtype_calculated'));
|
||||
$mform->addElement('static', "dividera", '', '<hr />');
|
||||
$addgrp = array();
|
||||
$addgrp[] =& $mform->createElement('submit', 'addbutton', get_string('add', 'moodle'));
|
||||
$addgrp[] =& $mform->createElement('select', "selectadd", get_string('additem', 'qtype_calculated'), $addremoveoptions);
|
||||
$addgrp[] = & $mform->createElement('static',"stat","Items",get_string('newsetwildcardvalues', 'qtype_calculatedsimple'));
|
||||
$mform->addGroup($addgrp, 'addgrp', get_string('additem', 'qtype_calculated'), ' ', false);
|
||||
$addgrp[] =& $mform->createElement('select', "selectadd",
|
||||
get_string('additem', 'qtype_calculated'), $addremoveoptions);
|
||||
$addgrp[] = & $mform->createElement('static', "stat", "Items",
|
||||
get_string('newsetwildcardvalues', 'qtype_calculatedsimple'));
|
||||
$mform->addGroup($addgrp, 'addgrp', get_string('additem', 'qtype_calculated'), ' ', false);
|
||||
$mform->addElement('static', "divideradd", '', '');
|
||||
// $mform->closeHeaderBefore('divideradd');
|
||||
if ($this->noofitems > 0) {
|
||||
$mform->addElement('header', 'additemhdr', get_string('delete', 'moodle'));
|
||||
$deletegrp = array();
|
||||
$deletegrp[] =& $mform->createElement('submit', 'deletebutton', get_string('delete', 'moodle'));
|
||||
$deletegrp[] =& $mform->createElement('select', 'selectdelete', get_string('deleteitem', 'qtype_calculated')."1", $addremoveoptions);
|
||||
$deletegrp[] = & $mform->createElement('static',"stat","Items",get_string('setwildcardvalues', 'qtype_calculatedsimple'));
|
||||
$deletegrp[] = $mform->createElement('submit', 'deletebutton',
|
||||
get_string('delete', 'moodle'));
|
||||
$deletegrp[] = $mform->createElement('select', 'selectdelete',
|
||||
get_string('deleteitem', 'qtype_calculated')."1", $addremoveoptions);
|
||||
$deletegrp[] = $mform->createElement('static', "stat", "Items",
|
||||
get_string('setwildcardvalues', 'qtype_calculatedsimple'));
|
||||
$mform->addGroup($deletegrp, 'deletegrp', '', ' ', false);
|
||||
// $mform->addElement('static', "dividerdelete", '', '<hr />');
|
||||
// $mform->closeHeaderBefore('dividerdelete');
|
||||
} else {
|
||||
$mform->addElement('static','warning','','<span class="error">'.get_string('youmustaddatleastoneitem', 'qtype_calculated').'</span>');
|
||||
$mform->addElement('static', 'warning', '', '<span class="error">' .
|
||||
get_string('youmustaddatleastoneitem', 'qtype_calculated').'</span>');
|
||||
}
|
||||
|
||||
// $mform->addElement('header', 'additemhdr', get_string('showitems', 'moodle'));
|
||||
$addgrp1 = array();
|
||||
$addgrp1[] =& $mform->createElement('submit', 'showbutton', get_string('showitems', 'qtype_calculated'));
|
||||
$addgrp1[] =& $mform->createElement('select', "selectshow",'' , $showoptions);
|
||||
$addgrp1[] = & $mform->createElement('static',"stat",'',get_string('setwildcardvalues', 'qtype_calculated'));
|
||||
$addgrp1[] = $mform->createElement('submit', 'showbutton',
|
||||
get_string('showitems', 'qtype_calculated'));
|
||||
$addgrp1[] = $mform->createElement('select', "selectshow", '' , $showoptions);
|
||||
$addgrp1[] = $mform->createElement('static', "stat", '',
|
||||
get_string('setwildcardvalues', 'qtype_calculated'));
|
||||
$mform->addGroup($addgrp1, 'addgrp1', '', ' ', false);
|
||||
$mform->registerNoSubmitButton('showbutton');
|
||||
$mform->closeHeaderBefore('addgrp1');
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
$j = $this->noofitems * count($this->datasetdefs);
|
||||
$k = 1 ;
|
||||
if ("" != optional_param('selectshow', '', PARAM_INT)){
|
||||
$k = 1;
|
||||
if ("" != optional_param('selectshow', '', PARAM_INT)) {
|
||||
$k = optional_param('selectshow', '', PARAM_INT);
|
||||
}
|
||||
for ($i = $this->noofitems; $i >= 1 ; $i--){
|
||||
if($k > 0 ){ //|| $this->outsidelimit || !empty($this->numbererrors )
|
||||
$mform->addElement('header', '',"<b>".get_string('setno', 'qtype_calculated', $i)."</b> ");
|
||||
// $mform->addElement('header', '', get_string('itemno', 'qtype_calculated', $i));
|
||||
}
|
||||
foreach ($this->datasetdefs as $defkey => $datasetdef){
|
||||
if($k > 0 ){ //|| $this->outsidelimit || !empty($this->numbererrors )
|
||||
if($datasetdef->category == 0 ){
|
||||
$mform->addElement('text', "number[$j]", get_string('wildcard', 'qtype_calculated', $datasetdef->name));
|
||||
}else {
|
||||
$mform->addElement('text', "number[$j]", get_string('sharedwildcardname', 'qtype_calculated', $datasetdef->name));
|
||||
for ($i = $this->noofitems; $i >= 1; $i--) {
|
||||
if ($k > 0) {
|
||||
$mform->addElement('header', '', "<b>" .
|
||||
get_string('setno', 'qtype_calculated', $i)."</b> ");
|
||||
}
|
||||
foreach ($this->datasetdefs as $defkey => $datasetdef) {
|
||||
if ($k > 0) {
|
||||
if ($datasetdef->category == 0 ) {
|
||||
$mform->addElement('text', "number[$j]",
|
||||
get_string('wildcard', 'qtype_calculated', $datasetdef->name));
|
||||
} else {
|
||||
$mform->addElement('text', "number[$j]", get_string(
|
||||
'sharedwildcardname', 'qtype_calculated', $datasetdef->name));
|
||||
}
|
||||
|
||||
}else {
|
||||
$mform->addElement('hidden',"number[$j]" , '');
|
||||
}
|
||||
|
||||
} else {
|
||||
$mform->addElement('hidden', "number[$j]" , '');
|
||||
}
|
||||
$mform->setType("number[$j]", PARAM_NUMBER);
|
||||
$mform->addElement('hidden', "itemid[$j]");
|
||||
$mform->setType("itemid[$j]", PARAM_INT);
|
||||
@@ -271,36 +299,37 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
|
||||
$j--;
|
||||
}
|
||||
if('' != $strquestionlabel && ($k > 0 )){ //|| $this->outsidelimit || !empty($this->numbererrors )
|
||||
$repeated[] =& $mform->addElement('static', "answercomment[$i]", $strquestionlabel);
|
||||
if ('' != $strquestionlabel && ($k > 0 )) {
|
||||
//|| $this->outsidelimit || !empty($this->numbererrors )
|
||||
$repeated[] = $mform->addElement('static', "answercomment[$i]", $strquestionlabel);
|
||||
// decode equations in question text
|
||||
$qtext = $this->qtypeobj->substitute_variables($this->question->questiontext, $data);
|
||||
$qtext = $this->qtypeobj->substitute_variables(
|
||||
$this->question->questiontext, $data);
|
||||
$textequations = $this->qtypeobj->find_math_equations($qtext);
|
||||
if($textequations != '' && count($textequations) > 0 ){
|
||||
$mform->addElement('static', "divider1[$j]", '', 'Formulas {=..} in question text');
|
||||
foreach($textequations as $key=>$equation){
|
||||
if( $formulaerrors = qtype_calculated_find_formula_errors($equation)){
|
||||
$str=$formulaerrors ;
|
||||
}else {
|
||||
eval('$str = '.$equation.';');
|
||||
}
|
||||
|
||||
$mform->addElement('static', "textequation","{=$equation}","=".$str);
|
||||
if ($textequations != '' && count($textequations) > 0 ) {
|
||||
$mform->addElement('static', "divider1[$j]", '',
|
||||
'Formulas {=..} in question text');
|
||||
foreach ($textequations as $key => $equation) {
|
||||
if ($formulaerrors = qtype_calculated_find_formula_errors($equation)) {
|
||||
$str=$formulaerrors;
|
||||
} else {
|
||||
eval('$str = '.$equation.';');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$k-- ;
|
||||
$mform->addElement('static', "textequation", "{=$equation}", "=".$str);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$k--;
|
||||
|
||||
}
|
||||
// if ($this->outsidelimit){
|
||||
$mform->addElement('static','outsidelimit','','');
|
||||
// }
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
//non standard name for button element needed so not using add_action_buttons
|
||||
if ( !($this->noofitems==0) ){
|
||||
$mform->addElement('submit', 'savechanges', get_string('savechanges'));
|
||||
$mform->closeHeaderBefore('savechanges');
|
||||
$mform->addElement('static', 'outsidelimit', '', '');
|
||||
//----------------------------------------------------------------------
|
||||
// Non standard name for button element needed so not using add_action_buttons
|
||||
if (!($this->noofitems==0) ) {
|
||||
$mform->addElement('submit', 'savechanges', get_string('savechanges'));
|
||||
$mform->closeHeaderBefore('savechanges');
|
||||
}
|
||||
//hidden elements
|
||||
$mform->addElement('hidden', 'id');
|
||||
@@ -326,46 +355,57 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
$mform->setDefault('returnurl', 0);
|
||||
}
|
||||
|
||||
function set_data($question){
|
||||
public function set_data($question) {
|
||||
$formdata = array();
|
||||
$fromform = new stdClass();
|
||||
if (isset($question->options)){
|
||||
if (isset($question->options)) {
|
||||
$answers = $question->options->answers;
|
||||
if (count($answers)) {
|
||||
if ( optional_param('updateanswers', '', PARAM_RAW) != '' || optional_param('updatedatasets', '', PARAM_RAW) != ''){
|
||||
foreach ($answers as $key => $answer){
|
||||
$fromform->tolerance[$key]= $this->_form->getElementValue('tolerance['.$key.']');
|
||||
if (optional_param('updateanswers', '', PARAM_RAW) != '' ||
|
||||
optional_param('updatedatasets', '', PARAM_RAW) != '') {
|
||||
foreach ($answers as $key => $answer) {
|
||||
$fromform->tolerance[$key]= $this->_form->getElementValue(
|
||||
'tolerance['.$key.']');
|
||||
$answer->tolerance = $fromform->tolerance[$key];
|
||||
$fromform->tolerancetype[$key]= $this->_form->getElementValue('tolerancetype['.$key.']');
|
||||
if( is_array($fromform->tolerancetype[$key])) $fromform->tolerancetype[$key]= $fromform->tolerancetype[$key][0];
|
||||
$fromform->tolerancetype[$key]= $this->_form->getElementValue(
|
||||
'tolerancetype['.$key.']');
|
||||
if (is_array($fromform->tolerancetype[$key])) {
|
||||
$fromform->tolerancetype[$key]= $fromform->tolerancetype[$key][0];
|
||||
}
|
||||
$answer->tolerancetype = $fromform->tolerancetype[$key];
|
||||
$fromform->correctanswerlength[$key]= $this->_form->getElementValue('correctanswerlength['.$key.']');
|
||||
if( is_array($fromform->correctanswerlength[$key])) $fromform->correctanswerlength[$key]= $fromform->correctanswerlength[$key][0];
|
||||
$fromform->correctanswerlength[$key]= $this->_form->getElementValue(
|
||||
'correctanswerlength['.$key.']');
|
||||
if (is_array($fromform->correctanswerlength[$key])) {
|
||||
$fromform->correctanswerlength[$key] =
|
||||
$fromform->correctanswerlength[$key][0];
|
||||
}
|
||||
$answer->correctanswerlength = $fromform->correctanswerlength[$key];
|
||||
$fromform->correctanswerformat[$key]= $this->_form->getElementValue('correctanswerformat['.$key.']');
|
||||
if( is_array($fromform->correctanswerformat[$key])) $fromform->correctanswerformat[$key]= $fromform->correctanswerformat[$key][0];
|
||||
$fromform->correctanswerformat[$key] = $this->_form->getElementValue(
|
||||
'correctanswerformat['.$key.']');
|
||||
if (is_array($fromform->correctanswerformat[$key])) {
|
||||
$fromform->correctanswerformat[$key] =
|
||||
$fromform->correctanswerformat[$key][0];
|
||||
}
|
||||
$answer->correctanswerformat = $fromform->correctanswerformat[$key];
|
||||
}
|
||||
$this->qtypeobj->save_question_calculated($question,$fromform);
|
||||
}else {
|
||||
foreach ($answers as $key => $answer){
|
||||
$this->qtypeobj->save_question_calculated($question, $fromform);
|
||||
|
||||
$formdata['tolerance['.$key.']'] = $answer->tolerance;
|
||||
$formdata['tolerancetype['.$key.']'] = $answer->tolerancetype;
|
||||
$formdata['correctanswerlength['.$key.']'] = $answer->correctanswerlength;
|
||||
$formdata['correctanswerformat['.$key.']'] = $answer->correctanswerformat;
|
||||
}
|
||||
} else {
|
||||
foreach ($answers as $key => $answer) {
|
||||
$formdata['tolerance['.$key.']'] = $answer->tolerance;
|
||||
$formdata['tolerancetype['.$key.']'] = $answer->tolerancetype;
|
||||
$formdata['correctanswerlength['.$key.']'] = $answer->correctanswerlength;
|
||||
$formdata['correctanswerformat['.$key.']'] = $answer->correctanswerformat;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//fill out all data sets and also the fields for the next item to add.
|
||||
// echo "<p> qequation <pre>";print_r($question);echo "</pre></p>";
|
||||
// echo "<p> datasetdefs <pre>";print_r($this->datasetdefs);echo "</pre></p>";
|
||||
$j = $this->noofitems * count($this->datasetdefs);
|
||||
for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--){
|
||||
for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--) {
|
||||
$data = array();
|
||||
foreach ($this->datasetdefs as $defid => $datasetdef){
|
||||
if (isset($datasetdef->items[$itemnumber])){
|
||||
foreach ($this->datasetdefs as $defid => $datasetdef) {
|
||||
if (isset($datasetdef->items[$itemnumber])) {
|
||||
$formdata["number[$j]"] = $datasetdef->items[$itemnumber]->value;
|
||||
$formdata["definition[$j]"] = $defid;
|
||||
$formdata["itemid[$j]"] = $datasetdef->items[$itemnumber]->id;
|
||||
@@ -373,15 +413,16 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
}
|
||||
$j--;
|
||||
}
|
||||
$comment = $this->qtypeobj->comment_on_datasetitems($this->qtypeobj,$question->id,$question->questiontext,$answers, $data, $itemnumber);
|
||||
if ($comment->outsidelimit) {
|
||||
$this->outsidelimit=$comment->outsidelimit ;
|
||||
$comment = $this->qtypeobj->comment_on_datasetitems($this->qtypeobj, $question->id,
|
||||
$question->questiontext, $answers, $data, $itemnumber);
|
||||
if ($comment->outsidelimit) {
|
||||
$this->outsidelimit=$comment->outsidelimit;
|
||||
}
|
||||
$totalcomment='';
|
||||
foreach ($question->options->answers as $key => $answer) {
|
||||
$totalcomment .= $comment->stranswers[$key].'<br/>';
|
||||
}
|
||||
$formdata['answercomment['.$itemnumber.']'] = $totalcomment ;
|
||||
$formdata['answercomment['.$itemnumber.']'] = $totalcomment;
|
||||
}
|
||||
|
||||
$formdata['nextpageparam[forceregeneration]'] = $this->regenerate;
|
||||
@@ -392,15 +433,17 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
//dataset generation dafaults
|
||||
if ($this->qtypeobj->supports_dataset_item_generation()) {
|
||||
$itemnumber = $this->noofitems+1;
|
||||
foreach ($this->datasetdefs as $defid => $datasetdef){
|
||||
if( optional_param('updatedatasets', '', PARAM_RAW) == '' && optional_param('updateanswers', '', PARAM_RAW)== ''){
|
||||
$formdata["number[$j]"] = $this->qtypeobj->generate_dataset_item($datasetdef->options);
|
||||
}else {
|
||||
$formdata["number[$j]"] = $this->_form->getElementValue("number[$j]") ;
|
||||
}
|
||||
foreach ($this->datasetdefs as $defid => $datasetdef) {
|
||||
if (optional_param('updatedatasets', '', PARAM_RAW) == '' &&
|
||||
optional_param('updateanswers', '', PARAM_RAW)== '') {
|
||||
$formdata["number[$j]"] = $this->qtypeobj->generate_dataset_item(
|
||||
$datasetdef->options);
|
||||
} else {
|
||||
$formdata["number[$j]"] = $this->_form->getElementValue("number[$j]");
|
||||
}
|
||||
$formdata["definition[$j]"] = $defid;
|
||||
$formdata["itemid[$j]"] =
|
||||
isset($datasetdef->items[$itemnumber])?$datasetdef->items[$itemnumber]->id:0;
|
||||
$formdata["itemid[$j]"] = isset($datasetdef->items[$itemnumber]) ?
|
||||
$datasetdef->items[$itemnumber]->id : 0;
|
||||
$data[$datasetdef->name] = $formdata["number[$j]"];
|
||||
$j++;
|
||||
}
|
||||
@@ -408,11 +451,12 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
|
||||
//existing records override generated data depending on radio element
|
||||
$j = $this->noofitems * count($this->datasetdefs)+1;
|
||||
if (!$this->regenerate && (optional_param('updatedatasets', '', PARAM_RAW) == '' && optional_param('updateanswers', '', PARAM_RAW)== '')){
|
||||
if (!$this->regenerate && (optional_param('updatedatasets', '', PARAM_RAW) == '' &&
|
||||
optional_param('updateanswers', '', PARAM_RAW)== '')) {
|
||||
$idx = 1;
|
||||
$itemnumber = $this->noofitems+1;
|
||||
foreach ($this->datasetdefs as $defid => $datasetdef){
|
||||
if (isset($datasetdef->items[$itemnumber])){
|
||||
foreach ($this->datasetdefs as $defid => $datasetdef) {
|
||||
if (isset($datasetdef->items[$itemnumber])) {
|
||||
$formdata["number[$j]"] = $datasetdef->items[$itemnumber]->value;
|
||||
$formdata["definition[$j]"] = $defid;
|
||||
$formdata["itemid[$j]"] = $datasetdef->items[$itemnumber]->id;
|
||||
@@ -420,52 +464,55 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$comment = $this->qtypeobj->comment_on_datasetitems($this->qtypeobj,$question->id,$question->questiontext,$answers, $data, ($this->noofitems+1));
|
||||
if (isset($comment->outsidelimit)&&$comment->outsidelimit) {
|
||||
$this->outsidelimit=$comment->outsidelimit ;
|
||||
}
|
||||
$key1 = 1;
|
||||
foreach ($question->options->answers as $key => $answer) {
|
||||
$formdata['answercomment['.($this->noofitems+$key1).']'] = $comment->stranswers[$key];
|
||||
$key1++;
|
||||
}
|
||||
$comment = $this->qtypeobj->comment_on_datasetitems($this->qtypeobj, $question->id,
|
||||
$question->questiontext, $answers, $data, ($this->noofitems + 1));
|
||||
if (isset($comment->outsidelimit)&&$comment->outsidelimit) {
|
||||
$this->outsidelimit=$comment->outsidelimit;
|
||||
}
|
||||
$key1 = 1;
|
||||
foreach ($question->options->answers as $key => $answer) {
|
||||
$formdata['answercomment['.($this->noofitems+$key1).']'] = $comment->stranswers[$key];
|
||||
$key1++;
|
||||
}
|
||||
|
||||
if ($this->outsidelimit){
|
||||
$formdata['outsidelimit']= '<span class="error">'.get_string('oneanswertrueansweroutsidelimits', 'qtype_calculated').'</span>';
|
||||
if ($this->outsidelimit) {
|
||||
$formdata['outsidelimit']= '<span class="error">' .
|
||||
get_string('oneanswertrueansweroutsidelimits', 'qtype_calculated') . '</span>';
|
||||
}
|
||||
$formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $formdata);
|
||||
|
||||
parent::set_data((object)($formdata + (array)$question));
|
||||
}
|
||||
|
||||
function validation($data, $files) {
|
||||
public function validation($data, $files) {
|
||||
$errors = array();
|
||||
if (isset($data['savechanges']) && ($this->noofitems==0) ){
|
||||
if (isset($data['savechanges']) && ($this->noofitems==0) ) {
|
||||
$errors['warning'] = get_string('warning', 'mnet');
|
||||
}
|
||||
if ($this->outsidelimit){
|
||||
$errors['outsidelimits'] = get_string('oneanswertrueansweroutsidelimits','qtype_calculated');
|
||||
if ($this->outsidelimit) {
|
||||
$errors['outsidelimits'] =
|
||||
get_string('oneanswertrueansweroutsidelimits', 'qtype_calculated');
|
||||
}
|
||||
$numbers = $data['number'];
|
||||
foreach ($numbers as $key => $number){
|
||||
if(! is_numeric($number)){
|
||||
if (stristr($number,',')){
|
||||
$errors['number['.$key.']'] = get_string('The , cannot be used, use . as in 0.013 or 1.3e-2', 'qtype_calculated');
|
||||
}else {
|
||||
$errors['number['.$key.']'] = get_string('This is not a valid number', 'qtype_calculated');
|
||||
foreach ($numbers as $key => $number) {
|
||||
if (! is_numeric($number)) {
|
||||
if (stristr($number, ', ')) {
|
||||
$errors['number['.$key.']'] = get_string(
|
||||
'The , cannot be used, use . as in 0.013 or 1.3e-2', 'qtype_calculated');
|
||||
} else {
|
||||
$errors['number['.$key.']'] = get_string(
|
||||
'This is not a valid number', 'qtype_calculated');
|
||||
}
|
||||
}else if( stristr($number,'x')){
|
||||
$errors['number['.$key.']'] = get_string('Hexadecimal format (i.e. 0X12d) is not allowed', 'qtype_calculated');
|
||||
} else if( is_nan($number)){
|
||||
$errors['number['.$key.']'] = get_string('is a NAN number', 'qtype_calculated');
|
||||
} else if (stristr($number, 'x')) {
|
||||
$errors['number['.$key.']'] = get_string(
|
||||
'Hexadecimal format (i.e. 0X12d) is not allowed', 'qtype_calculated');
|
||||
} else if (is_nan($number)) {
|
||||
$errors['number['.$key.']'] = get_string(
|
||||
'is a NAN number', 'qtype_calculated');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -46,23 +46,22 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
|
||||
|
||||
if ($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
|
||||
|
||||
/// Define table question_calculated_options to be created
|
||||
// Define table question_calculated_options to be created
|
||||
$table = new xmldb_table('question_calculated_options');
|
||||
|
||||
/// Adding fields to table question_calculated_options
|
||||
$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');
|
||||
// Adding fields to table question_calculated_options
|
||||
$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');
|
||||
|
||||
/// Adding keys to table question_calculated_options
|
||||
// Adding keys to table question_calculated_options
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
|
||||
|
||||
/// Conditionally launch create table for question_calculated_options
|
||||
// Conditionally launch create table for question_calculated_options
|
||||
if (!$dbman->table_exists($table)) {
|
||||
// $dbman->create_table doesnt return a result, we just have to trust it
|
||||
$dbman->create_table($table);
|
||||
@@ -72,62 +71,59 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
|
||||
|
||||
if ( $oldversion < 2009092000) { //New version in version.php
|
||||
|
||||
/// Define field multichoice to be added to question_calculated_options
|
||||
///ALTER TABLE `moodle`.`mdl_question_calculated_options` DROP COLUMN `multichoice`;
|
||||
// $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
|
||||
// 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', 'synchronize');
|
||||
$field = new xmldb_field('single', XMLDB_TYPE_INTEGER, '4', null,
|
||||
XMLDB_NOTNULL, null, '0', 'synchronize');
|
||||
|
||||
/// Conditionally launch add field single
|
||||
// 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
|
||||
// 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');
|
||||
$field = new xmldb_field('shuffleanswers', XMLDB_TYPE_INTEGER, '4', null,
|
||||
XMLDB_NOTNULL, null, '0', 'single');
|
||||
|
||||
/// Conditionally launch add field shuffleanswers
|
||||
// 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
|
||||
// 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');
|
||||
$field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null,
|
||||
null, null, null, 'shuffleanswers');
|
||||
|
||||
/// Conditionally launch add field correctfeedback
|
||||
// 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
|
||||
// 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');
|
||||
$field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
|
||||
null, null, null, 'correctfeedback');
|
||||
|
||||
/// Conditionally launch add field partiallycorrectfeedback
|
||||
// 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
|
||||
// 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');
|
||||
$field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
|
||||
null, null, null, 'partiallycorrectfeedback');
|
||||
|
||||
/// Conditionally launch add field incorrectfeedback
|
||||
// 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
|
||||
// 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');
|
||||
$field = new xmldb_field('answernumbering', XMLDB_TYPE_CHAR, '10', null,
|
||||
XMLDB_NOTNULL, null, 'abc', 'incorrectfeedback');
|
||||
|
||||
/// Conditionally launch add field answernumbering
|
||||
// Conditionally launch add field answernumbering
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
@@ -136,16 +132,16 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
|
||||
|
||||
if ($oldversion < 2010020800) {
|
||||
|
||||
/// Define field multiplechoice to be dropped from question_calculated_options
|
||||
// Define field multiplechoice to be dropped from question_calculated_options
|
||||
$table = new xmldb_table('question_calculated_options');
|
||||
$field = new xmldb_field('multichoice');
|
||||
|
||||
/// Conditionally launch drop field multiplechoice
|
||||
// Conditionally launch drop field multiplechoice
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->drop_field($table, $field);
|
||||
}
|
||||
|
||||
/// calculated savepoint reached
|
||||
// calculated savepoint reached
|
||||
upgrade_plugin_savepoint(true, 2010020800, 'qtype', 'calculated');
|
||||
}
|
||||
|
||||
@@ -153,7 +149,8 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
|
||||
|
||||
// Define field correctfeedbackformat to be added to question_calculated_options
|
||||
$table = new xmldb_table('question_calculated_options');
|
||||
$field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'correctfeedback');
|
||||
$field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null,
|
||||
XMLDB_NOTNULL, null, '0', 'correctfeedback');
|
||||
|
||||
// Conditionally launch add field correctfeedbackformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
@@ -161,7 +158,8 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
|
||||
}
|
||||
|
||||
// Define field partiallycorrectfeedbackformat to be added to question_calculated_options
|
||||
$field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback');
|
||||
$field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null,
|
||||
XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback');
|
||||
|
||||
// Conditionally launch add field partiallycorrectfeedbackformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
@@ -169,7 +167,8 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
|
||||
}
|
||||
|
||||
// Define field incorrectfeedbackformat to be added to question_calculated_options
|
||||
$field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'incorrectfeedback');
|
||||
$field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null,
|
||||
XMLDB_NOTNULL, null, '0', 'incorrectfeedback');
|
||||
|
||||
// Conditionally launch add field incorrectfeedbackformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
@@ -185,12 +184,16 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
|
||||
FROM {question_calculated_options} qco
|
||||
JOIN {question} q ON qco.question = q.id');
|
||||
foreach ($rs as $record) {
|
||||
if ($CFG->texteditors !== 'textarea' && $record->oldquestiontextformat == FORMAT_MOODLE) {
|
||||
$record->correctfeedback = text_to_html($record->correctfeedback, false, false, true);
|
||||
if ($CFG->texteditors !== 'textarea' &&
|
||||
$record->oldquestiontextformat == FORMAT_MOODLE) {
|
||||
$record->correctfeedback = text_to_html(
|
||||
$record->correctfeedback, false, false, true);
|
||||
$record->correctfeedbackformat = FORMAT_HTML;
|
||||
$record->partiallycorrectfeedback = text_to_html($record->partiallycorrectfeedback, false, false, true);
|
||||
$record->partiallycorrectfeedback = text_to_html(
|
||||
$record->partiallycorrectfeedback, false, false, true);
|
||||
$record->partiallycorrectfeedbackformat = FORMAT_HTML;
|
||||
$record->incorrectfeedback = text_to_html($record->incorrectfeedback, false, false, true);
|
||||
$record->incorrectfeedback = text_to_html(
|
||||
$record->incorrectfeedback, false, false, true);
|
||||
$record->incorrectfeedbackformat = FORMAT_HTML;
|
||||
} else {
|
||||
$record->correctfeedbackformat = $record->oldquestiontextformat;
|
||||
|
||||
@@ -37,7 +37,7 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
/**
|
||||
* Handle to the question type for this question.
|
||||
*
|
||||
* @var question_calculated_qtype
|
||||
* @var qtype_calculated
|
||||
*/
|
||||
public $qtypeobj;
|
||||
public $questiondisplay;
|
||||
@@ -46,37 +46,40 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
public $initialname = '';
|
||||
public $reload = false;
|
||||
|
||||
function question_edit_calculated_form(&$submiturl, &$question, &$category, &$contexts, $formeditable = true){
|
||||
global $QTYPES, $SESSION, $CFG, $DB;
|
||||
public function __construct($submiturl, $question, $category, $contexts,
|
||||
$formeditable = true) {
|
||||
global $CFG, $DB;
|
||||
$this->question = $question;
|
||||
$this->qtypeobj =& $QTYPES[$this->question->qtype];
|
||||
if ( "1" == optional_param('reload','', PARAM_INT )) {
|
||||
$this->reload = true ;
|
||||
}else {
|
||||
$this->reload = false ;
|
||||
$this->qtypeobj = $QTYPES[$this->question->qtype];
|
||||
if ('1' == optional_param('reload', '', PARAM_INT)) {
|
||||
$this->reload = true;
|
||||
} else {
|
||||
$this->reload = false;
|
||||
}
|
||||
|
||||
if(!$this->reload ){ // use database data as this is first pass
|
||||
if(isset($this->question->id )){
|
||||
if (!$this->reload) { // use database data as this is first pass
|
||||
if (isset($this->question->id)) {
|
||||
// remove prefix #{..}# if exists
|
||||
$this->initialname = $question->name ;
|
||||
$this->initialname = $question->name;
|
||||
$regs= array();
|
||||
if(preg_match('~#\{([^[:space:]]*)#~',$question->name , $regs)){
|
||||
if (preg_match('~#\{([^[:space:]]*)#~', $question->name , $regs)) {
|
||||
$question->name = str_replace($regs[0], '', $question->name);
|
||||
};
|
||||
}
|
||||
}else {
|
||||
}
|
||||
parent::question_edit_form($submiturl, $question, $category, $contexts, $formeditable);
|
||||
parent::__construct($submiturl, $question, $category, $contexts, $formeditable);
|
||||
}
|
||||
|
||||
function get_per_answer_fields(&$mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption) {
|
||||
// $repeated = parent::get_per_answer_fields($mform, $label, $gradeoptions, $repeatedoptions, $answersoption);
|
||||
public 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', 'question'), array('size' => 50));
|
||||
$repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions);
|
||||
$repeated[] =& $mform->createElement('editor', 'feedback', get_string('feedback', 'question'), null, $this->editoroptions);
|
||||
$repeated[] = $mform->createElement('header', 'answerhdr', $label);
|
||||
$repeated[] = $mform->createElement('text', 'answer',
|
||||
get_string('answer', 'question'), array('size' => 50));
|
||||
$repeated[] = $mform->createElement('select', 'fraction',
|
||||
get_string('grade'), $gradeoptions);
|
||||
$repeated[] = $mform->createElement('editor', 'feedback',
|
||||
get_string('feedback', 'question'), null, $this->editoroptions);
|
||||
$repeatedoptions['answer']['type'] = PARAM_RAW;
|
||||
$repeatedoptions['fraction']['default'] = 0;
|
||||
$answersoption = 'answers';
|
||||
@@ -84,19 +87,26 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
$mform->setType('answer', PARAM_NOTAGS);
|
||||
|
||||
$addrepeated = array();
|
||||
$addrepeated[] =& $mform->createElement('text', 'tolerance', get_string('tolerance', 'qtype_calculated'));
|
||||
$addrepeated[] =& $mform->createElement('select', 'tolerancetype', get_string('tolerancetype', 'qtype_numerical'), $this->qtypeobj->tolerance_types());
|
||||
$addrepeated[] = $mform->createElement('text', 'tolerance',
|
||||
get_string('tolerance', 'qtype_calculated'));
|
||||
$addrepeated[] = $mform->createElement('select', 'tolerancetype',
|
||||
get_string('tolerancetype', 'qtype_numerical'),
|
||||
$this->qtypeobj->tolerance_types());
|
||||
$repeatedoptions['tolerance']['type'] = PARAM_NUMBER;
|
||||
$repeatedoptions['tolerance']['default'] = 0.01;
|
||||
|
||||
$addrepeated[] =& $mform->createElement('select', 'correctanswerlength', get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
|
||||
$addrepeated[] = $mform->createElement('select', 'correctanswerlength',
|
||||
get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
|
||||
$repeatedoptions['correctanswerlength']['default'] = 2;
|
||||
|
||||
$answerlengthformats = array('1' => get_string('decimalformat', 'qtype_numerical'), '2' => get_string('significantfiguresformat', 'quiz'));
|
||||
$addrepeated[] =& $mform->createElement('select', 'correctanswerformat', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
|
||||
$answerlengthformats = array(
|
||||
'1' => get_string('decimalformat', 'qtype_numerical'),
|
||||
'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', 'qtype_calculated').'=');
|
||||
|
||||
$repeated[1]->setLabel(get_string('correctanswerformula', 'qtype_calculated') . ' = ');
|
||||
return $repeated;
|
||||
}
|
||||
|
||||
@@ -106,40 +116,44 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
* @param MoodleQuickForm $mform the form being built.
|
||||
*/
|
||||
protected function definition_inner(&$mform) {
|
||||
global $QTYPES;
|
||||
$this->qtypeobj =& $QTYPES[$this->qtype()];
|
||||
$this->qtypeobj = $QTYPES[$this->qtype()];
|
||||
$label = get_string('sharedwildcards', 'qtype_calculated');
|
||||
$mform->addElement('hidden', 'initialcategory', 1);
|
||||
$mform->addElement('hidden', 'reload', 1);
|
||||
$mform->setType('initialcategory', PARAM_INT);
|
||||
$html2 = $this->qtypeobj->print_dataset_definitions_category($this->question);
|
||||
$mform->insertElementBefore($mform->createElement('static','listcategory',$label,$html2),'name');
|
||||
if(isset($this->question->id )){
|
||||
$mform->insertElementBefore($mform->createElement('static','initialname',get_string('questionstoredname','qtype_calculated'),$this->initialname),'name');
|
||||
$mform->insertElementBefore(
|
||||
$mform->createElement('static', 'listcategory', $label, $html2), 'name');
|
||||
if (isset($this->question->id)) {
|
||||
$mform->insertElementBefore($mform->createElement('static', 'initialname',
|
||||
get_string('questionstoredname', 'qtype_calculated'),
|
||||
$this->initialname), 'name');
|
||||
};
|
||||
$addfieldsname='updatecategory';
|
||||
$addstring=get_string("updatecategory", "qtype_calculated");
|
||||
$addfieldsname = 'updatecategory';
|
||||
$addstring = get_string('updatecategory', 'qtype_calculated');
|
||||
$mform->registerNoSubmitButton($addfieldsname);
|
||||
|
||||
$mform->insertElementBefore( $mform->createElement('submit', $addfieldsname, $addstring),'listcategory');
|
||||
$mform->insertElementBefore(
|
||||
$mform->createElement('submit', $addfieldsname, $addstring), 'listcategory');
|
||||
$mform->registerNoSubmitButton('createoptionbutton');
|
||||
|
||||
//editing as regular
|
||||
$mform->setType('single', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden','shuffleanswers', '1');
|
||||
$mform->addElement('hidden', 'shuffleanswers', '1');
|
||||
$mform->setType('shuffleanswers', PARAM_INT);
|
||||
$mform->addElement('hidden','answernumbering', 'abc');
|
||||
$mform->addElement('hidden', 'answernumbering', 'abc');
|
||||
$mform->setType('answernumbering', PARAM_SAFEDIR);
|
||||
|
||||
$creategrades = get_grade_options();
|
||||
|
||||
$this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'), $creategrades->gradeoptions, 1, 1);
|
||||
$this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'),
|
||||
$creategrades->gradeoptions, 1, 1);
|
||||
|
||||
$repeated = array();
|
||||
|
||||
$QTYPES['numerical']->add_units_options($mform,$this);
|
||||
$QTYPES['numerical']->add_units_elements($mform,$this);
|
||||
$QTYPES['numerical']->add_units_options($mform, $this);
|
||||
$QTYPES['numerical']->add_units_elements($mform, $this);
|
||||
|
||||
//hidden elements
|
||||
$mform->addElement('hidden', 'synchronize', '');
|
||||
@@ -148,15 +162,15 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
$mform->setType('wizard', PARAM_ALPHA);
|
||||
}
|
||||
|
||||
function data_preprocessing($question) {
|
||||
public function data_preprocessing($question) {
|
||||
global $QTYPES;
|
||||
|
||||
$default_values = array();
|
||||
if (isset($question->options)){
|
||||
if (isset($question->options)) {
|
||||
$answers = $question->options->answers;
|
||||
if (count($answers)) {
|
||||
$key = 0;
|
||||
foreach ($answers as $answer){
|
||||
foreach ($answers as $answer) {
|
||||
$draftid = file_get_submitted_draft_itemid('feedback['.$key.']');
|
||||
$default_values['answer['.$key.']'] = $answer->answer;
|
||||
$default_values['fraction['.$key.']'] = $answer->fraction;
|
||||
@@ -179,11 +193,11 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
$key++;
|
||||
}
|
||||
}
|
||||
$default_values['synchronize'] = $question->options->synchronize ;
|
||||
$default_values['synchronize'] = $question->options->synchronize;
|
||||
// set unit data, prepare files in instruction area
|
||||
$QTYPES['numerical']->set_numerical_unit_data($this, $question, $default_values);
|
||||
}
|
||||
if (isset($question->options->single)){
|
||||
if (isset($question->options->single)) {
|
||||
$default_values['single'] = $question->options->single;
|
||||
$default_values['answernumbering'] = $question->options->answernumbering;
|
||||
$default_values['shuffleanswers'] = $question->options->shuffleanswers;
|
||||
@@ -191,61 +205,52 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
}
|
||||
$default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
|
||||
$default_values['makecopy'] = get_string('makecopynextpage', 'qtype_calculated');
|
||||
$default_values['returnurl'] = '0' ;
|
||||
/* set the wild cards category display given that on loading the category element is
|
||||
unselected when processing this function but have a valid value when processing the
|
||||
update category button. The value can be obtain by
|
||||
$qu->category =$this->_form->_elements[$this->_form->_elementIndex['category']]->_values[0];
|
||||
but is coded using existing functions
|
||||
*/
|
||||
$default_values['returnurl'] = '0';
|
||||
|
||||
$qu = new stdClass();
|
||||
$el = new stdClass();
|
||||
/* no need to call elementExists() here */
|
||||
if ($this->_form->elementExists('category')){
|
||||
$el=$this->_form->getElement('category');
|
||||
if ($this->_form->elementExists('category')) {
|
||||
$el = $this->_form->getElement('category');
|
||||
} else {
|
||||
$el=$this->_form->getElement('categorymoveto');
|
||||
$el = $this->_form->getElement('categorymoveto');
|
||||
}
|
||||
if($value =$el->getSelected()) {
|
||||
$qu->category =$value[0];
|
||||
}else {
|
||||
$qu->category=$question->category;// on load $question->category is set by question.php
|
||||
if ($value = $el->getSelected()) {
|
||||
$qu->category = $value[0];
|
||||
} else {
|
||||
// on load $question->category is set by question.php
|
||||
$qu->category = $question->category;
|
||||
}
|
||||
$html2 = $this->qtypeobj->print_dataset_definitions_category($qu);
|
||||
$this->_form->_elements[$this->_form->_elementIndex['listcategory']]->_text = $html2 ;
|
||||
$this->_form->_elements[$this->_form->_elementIndex['listcategory']]->_text = $html2;
|
||||
$question = (object)((array)$question + $default_values);
|
||||
|
||||
return $question;
|
||||
}
|
||||
|
||||
function qtype() {
|
||||
public function qtype() {
|
||||
return 'calculated';
|
||||
}
|
||||
|
||||
function validation($data, $files) {
|
||||
global $QTYPES;
|
||||
// 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>";
|
||||
public function validation($data, $files) {
|
||||
|
||||
$errors = parent::validation($data, $files);
|
||||
//verifying for errors in {=...} in question text;
|
||||
// verifying for errors in {=...} in question text;
|
||||
$qtext = "";
|
||||
$qtextremaining = $data['questiontext']['text'];
|
||||
$possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']['text']);
|
||||
foreach ($possibledatasets as $name => $value) {
|
||||
$qtextremaining = str_replace('{'.$name.'}', '1', $qtextremaining);
|
||||
}
|
||||
// echo "numericalquestion qtextremaining <pre>";print_r($possibledatasets);
|
||||
while (preg_match('~\{=([^[:space:]}]*)}~', $qtextremaining, $regs1)) {
|
||||
$qtextsplits = explode($regs1[0], $qtextremaining, 2);
|
||||
$qtext =$qtext.$qtextsplits[0];
|
||||
$qtext = $qtext.$qtextsplits[0];
|
||||
$qtextremaining = $qtextsplits[1];
|
||||
if (!empty($regs1[1]) && $formulaerrors = qtype_calculated_find_formula_errors($regs1[1])) {
|
||||
if(!isset($errors['questiontext'])){
|
||||
$errors['questiontext'] = $formulaerrors.':'.$regs1[1] ;
|
||||
}else {
|
||||
if (!empty($regs1[1]) && $formulaerrors =
|
||||
qtype_calculated_find_formula_errors($regs1[1])) {
|
||||
if (!isset($errors['questiontext'])) {
|
||||
$errors['questiontext'] = $formulaerrors.':'.$regs1[1];
|
||||
} else {
|
||||
$errors['questiontext'] .= '<br/>'.$formulaerrors.':'.$regs1[1];
|
||||
}
|
||||
}
|
||||
@@ -255,33 +260,35 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
$maxgrade = false;
|
||||
$possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']['text']);
|
||||
$mandatorydatasets = array();
|
||||
foreach ($answers as $key => $answer){
|
||||
foreach ($answers as $key => $answer) {
|
||||
$mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
|
||||
}
|
||||
if ( count($mandatorydatasets )==0){
|
||||
// $errors['questiontext']=get_string('atleastonewildcard', 'qtype_datasetdependent');
|
||||
foreach ($answers as $key => $answer){
|
||||
$errors['answer['.$key.']'] = get_string('atleastonewildcard', 'qtype_datasetdependent');
|
||||
if (count($mandatorydatasets)== 0) {
|
||||
foreach ($answers as $key => $answer) {
|
||||
$errors['answer['.$key.']'] =
|
||||
get_string('atleastonewildcard', 'qtype_datasetdependent');
|
||||
}
|
||||
}
|
||||
// regular calculated
|
||||
foreach ($answers as $key => $answer){
|
||||
//check no of choices
|
||||
foreach ($answers as $key => $answer) {
|
||||
// check no of choices
|
||||
// the * for everykind of answer not actually implemented
|
||||
$trimmedanswer = trim($answer);
|
||||
if (($trimmedanswer!='')||$answercount==0){
|
||||
if ($trimmedanswer != '' || $answercount == 0) {
|
||||
$eqerror = qtype_calculated_find_formula_errors($trimmedanswer);
|
||||
if (FALSE !== $eqerror){
|
||||
if (false !== $eqerror) {
|
||||
$errors['answer['.$key.']'] = $eqerror;
|
||||
}
|
||||
}
|
||||
if ($trimmedanswer!=''){
|
||||
if ($trimmedanswer != '') {
|
||||
if ('2' == $data['correctanswerformat'][$key]
|
||||
&& '0' == $data['correctanswerlength'][$key]) {
|
||||
$errors['correctanswerlength['.$key.']'] = get_string('zerosignificantfiguresnotallowed', 'qtype_calculated');
|
||||
}
|
||||
if (!is_numeric($data['tolerance'][$key])){
|
||||
$errors['tolerance['.$key.']'] = get_string('mustbenumeric', 'qtype_calculated');
|
||||
&& '0' == $data['correctanswerlength'][$key]) {
|
||||
$errors['correctanswerlength['.$key.']'] =
|
||||
get_string('zerosignificantfiguresnotallowed', 'qtype_calculated');
|
||||
}
|
||||
if (!is_numeric($data['tolerance'][$key])) {
|
||||
$errors['tolerance['.$key.']'] =
|
||||
get_string('mustbenumeric', 'qtype_calculated');
|
||||
}
|
||||
if ($data['fraction'][$key] == 1) {
|
||||
$maxgrade = true;
|
||||
@@ -289,61 +296,16 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
|
||||
$answercount++;
|
||||
}
|
||||
//check grades
|
||||
|
||||
//TODO how should grade checking work here??
|
||||
/*if ($answer != '') {
|
||||
if ($data['fraction'][$key] > 0) {
|
||||
$totalfraction += $data['fraction'][$key];
|
||||
}
|
||||
if ($data['fraction'][$key] > $maxfraction) {
|
||||
$maxfraction = $data['fraction'][$key];
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//grade checking :
|
||||
/// Perform sanity checks on fractional grades
|
||||
/*if ( ) {
|
||||
if ($maxfraction != 1) {
|
||||
$maxfraction = $maxfraction * 100;
|
||||
$errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_multichoice', $maxfraction);
|
||||
}
|
||||
} else {
|
||||
$totalfraction = round($totalfraction,2);
|
||||
if ($totalfraction != 1) {
|
||||
$totalfraction = $totalfraction * 100;
|
||||
$errors['fraction[0]'] = get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction);
|
||||
}
|
||||
}
|
||||
$units = $data['unit'];
|
||||
if (count($units)) {
|
||||
foreach ($units as $key => $unit){
|
||||
if (is_numeric($unit)){
|
||||
$errors['unit['.$key.']'] = get_string('mustnotbenumeric', 'qtype_calculated');
|
||||
}
|
||||
$trimmedunit = trim($unit);
|
||||
$trimmedmultiplier = trim($data['multiplier'][$key]);
|
||||
if (!empty($trimmedunit)){
|
||||
if (empty($trimmedmultiplier)){
|
||||
$errors['multiplier['.$key.']'] = get_string('youmustenteramultiplierhere', 'qtype_calculated');
|
||||
}
|
||||
if (!is_numeric($trimmedmultiplier)){
|
||||
$errors['multiplier['.$key.']'] = get_string('mustbenumeric', 'qtype_calculated');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
$QTYPES['numerical']->validate_numerical_options($data, $errors) ;
|
||||
if ($answercount==0){
|
||||
$QTYPES['numerical']->validate_numerical_options($data, $errors);
|
||||
if ($answercount == 0) {
|
||||
$errors['answer[0]'] = get_string('atleastoneanswer', 'qtype_calculated');
|
||||
}
|
||||
if ($maxgrade == false) {
|
||||
$errors['fraction[0]'] = get_string('fractionsnomax', 'question');
|
||||
}
|
||||
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ $string['functiontakesoneortwoargs'] = 'The function {$a} must have either one o
|
||||
$string['functiontakestwoargs'] = 'The function {$a} must have exactly two arguments';
|
||||
$string['generatevalue'] = 'Generate a new value between';
|
||||
$string['getnextnow'] = 'Get new \'Item to Add\' now';
|
||||
$string['hexanotallowed'] = 'Dataset <strong>{$a->name}</strong> hexadecimal format value $a->value is not allowed' ;
|
||||
$string['hexanotallowed'] = 'Dataset <strong>{$a->name}</strong> hexadecimal format value $a->value is not allowed';
|
||||
$string['illegalformulasyntax'] = 'Illegal formula syntax starting with \'{$a}\'';
|
||||
$string['incorrectfeedback'] = 'For any incorrect response';
|
||||
$string['item(s)'] = 'item(s)';
|
||||
@@ -101,10 +101,10 @@ $string['newlocal3'] = 'a link from a new set of links that will only be used by
|
||||
$string['nextitemtoadd'] = 'Next \'Item to Add\'';
|
||||
$string['nextpage'] = 'Next page';
|
||||
$string['nocoherencequestionsdatyasetcategory'] = 'For question id {$a->qid}, the category id {$a->qcat} is not identical with the shared wild card {$a->name} category id {$a->sharedcat}. Edit the question.';
|
||||
$string['nocommaallowed'] = 'The , cannot be used, use . as in 0.013 or 1.3e-2' ;
|
||||
$string['nocommaallowed'] = 'The , cannot be used, use . as in 0.013 or 1.3e-2';
|
||||
$string['nodataset'] = 'nothing - it is not a wild card';
|
||||
$string['nosharedwildcard'] = 'No shared wild card in this category';
|
||||
$string['notvalidnumber'] = 'Wild card value is not a valid number ' ;
|
||||
$string['notvalidnumber'] = 'Wild card value is not a valid number ';
|
||||
$string['oneanswertrueansweroutsidelimits'] = 'At least one correct answer outside the true value limits.<br />Modify the answers tolerance settings available as Advanced parameters';
|
||||
$string['param'] = 'Param {<strong>{$a}</strong>}';
|
||||
$string['partiallycorrectfeedback'] = 'For any partially correct response';
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2009 Pierre Pichet
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class question_calculatedmulti_qtype extends question_calculated_qtype {
|
||||
class question_calculatedmulti_qtype extends qtype_calculated {
|
||||
|
||||
|
||||
// Used by the function custom_generator_tools:
|
||||
@@ -44,15 +44,10 @@ class question_calculatedmulti_qtype extends question_calculated_qtype {
|
||||
return 'calculatedmulti';
|
||||
}
|
||||
|
||||
function has_wildcards_in_responses($question, $subqid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function requires_qtypes() {
|
||||
return array('multichoice');
|
||||
}
|
||||
|
||||
|
||||
function save_question_options($question) {
|
||||
global $CFG, $DB, $QTYPES ;
|
||||
$context = $question->context;
|
||||
@@ -229,8 +224,8 @@ class question_calculatedmulti_qtype extends question_calculated_qtype {
|
||||
|
||||
// Choose a random dataset
|
||||
// maxnumber sould not be breater than 100
|
||||
if ($maxnumber > CALCULATEDQUESTIONMAXITEMNUMBER ){
|
||||
$maxnumber = CALCULATEDQUESTIONMAXITEMNUMBER ;
|
||||
if ($maxnumber > qtype_calculated::MAX_DATASET_ITEMS) {
|
||||
$maxnumber = qtype_calculated::MAX_DATASET_ITEMS;
|
||||
}
|
||||
if ( $synchronize_calculated === false ) {
|
||||
$state->options->datasetitem = rand(1, $maxnumber);
|
||||
|
||||
@@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2009 Pierre Pichet
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class question_calculatedsimple_qtype extends question_calculated_qtype {
|
||||
class question_calculatedsimple_qtype extends qtype_calculated {
|
||||
|
||||
// Used by the function custom_generator_tools:
|
||||
public $calcgenerateidhasbeenadded = false;
|
||||
|
||||
@@ -39,17 +39,6 @@ class embedded_cloze_qtype extends question_type {
|
||||
return 'multianswer';
|
||||
}
|
||||
|
||||
function has_wildcards_in_responses($question, $subqid) {
|
||||
global $QTYPES, $OUTPUT;
|
||||
foreach ($question->options->questions as $subq){
|
||||
if ($subq->id == $subqid){
|
||||
return $QTYPES[$subq->qtype]->has_wildcards_in_responses($subq, $subqid);
|
||||
}
|
||||
}
|
||||
echo $OUTPUT->notification('Could not find sub question!');
|
||||
return true;
|
||||
}
|
||||
|
||||
function requires_qtypes() {
|
||||
return array('shortanswer', 'numerical', 'multichoice');
|
||||
}
|
||||
|
||||
@@ -50,10 +50,6 @@ class qtype_numerical extends question_type {
|
||||
const UNITGRADEDOUTOFMARK = 1;
|
||||
const UNITGRADEDOUTOFMAX = 2;
|
||||
|
||||
public function has_wildcards_in_responses() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_question_options($question) {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
parent::get_question_options($question);
|
||||
|
||||
Reference in New Issue
Block a user