Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

solving lost of dataitems MDL-10087

  • Loading branch information...
commit 9267fe2f4343d0e151715c2daacc5a0b5e26620f 1 parent 1c09e6f
pichetp authored
Showing with 22 additions and 18 deletions.
  1. +22 −18 question/type/datasetdependent/abstractqtype.php
View
40 question/type/datasetdependent/abstractqtype.php
@@ -1,7 +1,7 @@
<?php // $Id$
///////////////////////////////////////////////////////////////
-/// ABSTRACT SUPERCLASS FOR QUSTION TYPES THAT USE DATASETS ///
+/// ABSTRACT SUPERCLASS FOR QUESTION TYPES THAT USE DATASETS ///
///////////////////////////////////////////////////////////////
/**
* @package questionbank
@@ -207,7 +207,7 @@ function display_question_editing_page(&$mform, $question, $wizardnow){
* @param object $form
* @param int $questionfromid default = '0'
*/
- function preparedatasets($form , $questionfromid='0'){
+ function preparedatasets(&$form , $questionfromid='0'){
// the dataset names present in the edit_question_form and edit_calculated_form are retrieved
$possibledatasets = $this->find_dataset_names($form->questiontext);
$mandatorydatasets = array();
@@ -229,7 +229,7 @@ function preparedatasets($form , $questionfromid='0'){
list($options, $selected) =
$this->dataset_options($form, $datasetname);
$datasets[$datasetname]='';
- $form->dataset[$key]=$selected ;
+ $form->dataset[$key]=$selected ;
$key++;
}
}
@@ -269,7 +269,9 @@ function preparedatasets($form , $questionfromid='0'){
* @param int $course
* @param PARAM_ALPHA $wizardnow should be added as we are coming from question2.php
*/
- function save_question($question, $form, $course) {
+ function save_question($question, $form, $course, $wizardnow='') {
+ echo "<pre> wizarnow $wizardnow form enter";print_r($form);
+
$wizardnow = optional_param('wizardnow', '', PARAM_ALPHA);
$id = optional_param('id', 0, PARAM_INT); // question id
// in case 'question'
@@ -286,21 +288,21 @@ function save_question($question, $form, $course) {
case 'question': // coming from the first page, creating the second
if (empty($form->id)) { // for a new question $form->id is empty
$question = parent::save_question($question, $form, $course);
- //prepare the datasets using default $questionfromid
- $form->datasets = $this->preparedatasets($form);
- $form->id = $question->id;
- $this->save_dataset_definitions($form);
+ //prepare the datasets using default $questionfromid
+ $this->preparedatasets($form);
+ $form->id = $question->id;
+ $this->save_dataset_definitions($form);
} else if (!empty($form->makecopy)){
- $questionfromid = $form->id ;
- $question = parent::save_question($question, $form, $course);
+ $questionfromid = $form->id ;
+ $question = parent::save_question($question, $form, $course);
//prepare the datasets
- $form->datasets = $this->preparedatasets($form,$questionfromid);
+ $this->preparedatasets($form,$questionfromid);
$form->id = $question->id;
$this->save_as_new_dataset_definitions($form,$questionfromid );
} else {// editing a question
$question = parent::save_question($question, $form, $course);
- //prepare the datasets
- $form->datasets = $this->preparedatasets($form,$question->id);
+ //prepare the datasets
+ $this->preparedatasets($form,$question->id);
$form->id = $question->id;
$this->save_dataset_definitions($form);
}
@@ -362,14 +364,15 @@ function get_dataset_definitions($questionid, $newdatasets) {
function save_dataset_definitions($form) {
// Save datasets
- $datasetdefinitions = $this->get_dataset_definitions($form->id, $form->dataset);
- $tmpdatasets = array_flip($form->dataset);
- $defids = array_keys($datasetdefinitions);
- foreach ($defids as $defid) {
+ $datasetdefinitions = $this->get_dataset_definitions($form->id, $form->dataset);
+ $tmpdatasets = array_flip($form->dataset);
+ $defids = array_keys($datasetdefinitions);
+ foreach ($defids as $defid) {
$datasetdef = &$datasetdefinitions[$defid];
if (isset($datasetdef->id)) {
- // This dataset is not used any more, delete it
+
if (!isset($tmpdatasets[$defid])) {
+ // This dataset is not used any more, delete it
delete_records('question_datasets',
'question', $form->id,
'datasetdefinition', $datasetdef->id);
@@ -379,6 +382,7 @@ function save_dataset_definitions($form) {
delete_records('question_dataset_items',
'definition', $datasetdef->id);
}
+
}
// This has already been saved or just got deleted
unset($datasetdefinitions[$defid]);
Please sign in to comment.
Something went wrong with that request. Please try again.