Skip to content

Commit

Permalink
MDL-12255 Putting back with all functions restored.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppichet committed Jan 15, 2010
1 parent f9b827d commit 347fb17
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions question/type/multianswer/edit_multianswer_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ class question_edit_multianswer_form extends question_edit_form {
var $savedquestiondisplay ;
var $used_in_quiz = false ;
var $qtype_change = false ;
var $negative_diff = false ;
var $negative_diff = 0 ;
var $nb_of_quiz = 0;
var $nb_of_attempts = 0;
public $confirm = 0 ;
public $reload = false ;

function question_edit_multianswer_form(&$submiturl, &$question, &$category, &$contexts, $formeditable = true){
global $QTYPES, $SESSION, $CFG, $DB;
/* $this->regenerate = true;
$this->regenerate = true;
if ( "1" == optional_param('reload','', PARAM_INT )) {
$this->reload = true ;
}else {
$this->reload = false ;
}
// $this->question = $question;
//$used_in_quiz =false;
echo "<p> question <pre>";print_r($question);echo "</pre></p>";
if(! empty($question->id)){
$this->used_in_quiz =false;
// echo "<p> question <pre>";print_r($question);echo "</pre></p>";
if(isset($question->id) && $question->id != 0 ){
$this->savedquestiondisplay =fullclone($question ) ;
if ($list = $DB->get_records('quiz_question_instances', array( 'question'=> $question->id))){
foreach($list as $key => $li){
Expand All @@ -52,7 +52,7 @@ function question_edit_multianswer_form(&$submiturl, &$question, &$category, &$c
}


*/



parent::question_edit_form($submiturl, $question, $category, $contexts, $formeditable);
Expand All @@ -61,14 +61,13 @@ function question_edit_multianswer_form(&$submiturl, &$question, &$category, &$c


function definition_inner(&$mform) {
// $mform->addElement('hidden', 'reload', 1);
// $mform->setType('reload', PARAM_INT);
$mform->addElement('hidden', 'reload', 1);
$mform->setType('reload', PARAM_INT);
$question_type_names = question_type_menu();
$mform->addRule('questiontext', null, 'required', null, 'client');

// Remove meaningless defaultgrade field.
$mform->removeElement('defaultgrade');
/* $this->confirm = optional_param('confirm','0', PARAM_RAW);
$this->confirm = optional_param('confirm','0', PARAM_RAW);

// display the questions from questiontext;
if ( "" != optional_param('questiontext','', PARAM_RAW)) {
Expand Down Expand Up @@ -187,9 +186,6 @@ function definition_inner(&$mform) {
}
if($this->type_change )
{
//$this->used_in_quiz
// $mform->addElement('header', 'additemhdr', "WARNING");
$mform->addElement('static', 'alert1', "<strong>"."Question type change "."</strong>","<strong>".get_string(' at least one question type has been changed. Did you add,delete or move a question ? Look ahead ','qtype_multianswer')."</strong>");//$countsubquestions."-".$countsavedsubquestions
}
echo '</div>';
Expand All @@ -209,7 +205,7 @@ function definition_inner(&$mform) {
}else {
$mform->addElement('hidden', 'confirm',0);
}
*/

}


Expand Down Expand Up @@ -264,7 +260,7 @@ function set_data($question) {
}
}
}
/*

// set default to $questiondisplay questions elements
if (isset($this->questiondisplay->options->questions)) {
$subquestions = fullclone($this->questiondisplay->options->questions) ;
Expand Down Expand Up @@ -347,17 +343,14 @@ function set_data($question) {
}
}
}
if (( $this->negative_diff || $this->used_in_quiz && ($this->negative_diff > 0 ||$this->negative_diff < 0 || $this->type_change ))&& $this->confirm == 0 ){
$this->_form->setElementError('confirm',"confirm then save");
}
$default_values['alertas']= "<strong>".get_string("
<ul>
<li>add or delete questions, </li>
<li>change the questions order in the text,</li>
<li>change their question type (numerical, shortanswer, multiple choice). </li></ul>
",'qtype_multianswer')."</strong>";
*/

if( $default_values != "") {
$question = (object)((array)$question + $default_values);
}
Expand All @@ -366,11 +359,14 @@ function set_data($question) {

function validation($data, $files) {
$errors = parent::validation($data, $files);
/* echo "<p> errors<pre>";print_r($errors);echo "</pre></p>";

$questiondisplay = qtype_multianswer_extract_question($data['questiontext']) ;


if (isset($this->questiondisplay->options->questions)) {

$subquestions = fullclone($this->questiondisplay->options->questions) ;
if (isset($questiondisplay->options->questions)) {

$subquestions = fullclone($questiondisplay->options->questions) ;
if (count($subquestions)) {
$sub =1;
foreach ($subquestions as $subquestion) {
Expand All @@ -379,10 +375,9 @@ function validation($data, $files) {
$maxgrade = false;
$maxfraction = -1;
if(isset($this->savedquestiondisplay->options->questions[$sub]->qtype) &&
$this->savedquestiondisplay->options->questions[$sub]->qtype != $this->questiondisplay->options->questions[$sub]->qtype ){
$this->savedquestiondisplay->options->questions[$sub]->qtype != $questiondisplay->options->questions[$sub]->qtype ){
$storemess = " STORED QTYPE ".$question_type_names[$this->savedquestiondisplay->options->questions[$sub]->qtype];
}
// $errors['subhdr'.$sub]=$storemess ;
foreach ( $subquestion->answer as $key=>$answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer !== '') {
Expand Down Expand Up @@ -414,9 +409,13 @@ function validation($data, $files) {
$errors['questiontext']=get_string('questionsmissing', 'qtype_multianswer');
}
}
// $question = qtype_multianswer_extract_question($data['questiontext']);
// if (isset $question->options->questions
if (( $this->negative_diff > 0 || $this->used_in_quiz && ($this->negative_diff > 0 ||$this->negative_diff < 0 || $this->type_change ))&& $this->confirm == 0 ){
$errors['confirm']="confirm then save".$this->negative_diff ;
}

echo "<p> errors<pre>";print_r($errors);echo "</pre></p>";
*/

return $errors;
}

Expand Down

0 comments on commit 347fb17

Please sign in to comment.