function set_data($question) { if (!empty($question->options->trueanswer)) { $trueanswer = $question->options->answers[$question->options->trueanswer]; $draftid = file_get_submitted_draft_itemid('trueanswer'); $answerid = $question->options->trueanswer; $text = $trueanswer->feedback; $question->correctanswer = $trueanswer->fraction != 0; $question->feedbacktrue = array(); $question->feedbacktrue['text'] = $trueanswer->feedback; $question->feedbacktrue['format'] = $trueanswer->feedbackformat; $question->feedbacktrue['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answerid) ? (int) $answerid : null, $this->fileoptions, $text); $question->feedbacktrue['itemid'] = $draftid; } if (!empty($question->options->falseanswer)) { $falseanswer = $question->options->answers[$question->options->falseanswer]; $draftid = file_get_submitted_draft_itemid('falseanswer'); $answerid = $question->options->falseanswer; $text = $falseanswer->feedback; $question->feedbackfalse = array(); $question->feedbackfalse['text'] = $falseanswer->feedback; $question->feedbackfalse['format'] = $falseanswer->feedbackformat; $question->feedbackfalse['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answerid) ? (int) $answerid : null, $this->fileoptions, $text); $question->feedbackfalse['itemid'] = $draftid; } parent::set_data($question); }
function validation($data, $files) { $errors = parent::validation($data, $files); $answers = $data['subanswers']; $questions = $data['subquestions']; $questioncount = 0; $answercount = 0; foreach ($questions as $key => $question) { $trimmedquestion = trim($question); $trimmedanswer = trim($answers[$key]); if ($trimmedquestion != '') { $questioncount++; } if ($trimmedanswer != '' || $trimmedquestion != '') { $answercount++; } if ($trimmedquestion != '' && $trimmedanswer == '') { $errors['subanswers[' . $key . ']'] = get_string('nomatchinganswerforq', 'qtype_match', $trimmedquestion); } } $numberqanda = new stdClass(); $numberqanda->q = 2; $numberqanda->a = 3; if ($questioncount < 1) { $errors['subquestions[0]'] = get_string('notenoughqsandas', 'qtype_match', $numberqanda); } if ($questioncount < 2) { $errors['subquestions[1]'] = get_string('notenoughqsandas', 'qtype_match', $numberqanda); } if ($answercount < 3) { $errors['subanswers[2]'] = get_string('notenoughqsandas', 'qtype_match', $numberqanda); } return $errors; }
function validation($data, $files) { global $QTYPES; $errors = parent::validation($data, $files); // Check the answers. $answercount = 0; $maxgrade = false; $answers = $data['answer']; foreach ($answers as $key => $answer) { $trimmedanswer = trim($answer); if ($trimmedanswer != '') { $answercount++; if (!(is_numeric($trimmedanswer) || $trimmedanswer == '*')) { $errors["answer[{$key}]"] = get_string('answermustbenumberorstar', 'qtype_numerical'); } if ($data['fraction'][$key] == 1) { $maxgrade = true; } } else { if ($data['fraction'][$key] != 0 || !html_is_blank($data['feedback'][$key]['text'])) { $errors["answer[{$key}]"] = get_string('answermustbenumberorstar', 'qtype_numerical'); $answercount++; } } } if ($answercount == 0) { $errors['answer[0]'] = get_string('notenoughanswers', 'qtype_numerical'); } if ($maxgrade == false) { $errors['fraction[0]'] = get_string('fractionsnomax', 'question'); } $QTYPES['numerical']->validate_numerical_options($data, $errors); return $errors; }
public function validation($data, $files) { $errors = parent::validation($data, $files); $answers = $data['answer']; $answercount = 0; $maxgrade = false; foreach ($answers as $key => $answer) { $trimmedanswer = trim($answer); if ($trimmedanswer !== '') { $answercount++; if ($data['fraction'][$key] == 1) { $maxgrade = true; } } else { if ($data['fraction'][$key] != 0 || !html_is_blank($data['feedback'][$key]['text'])) { $errors["answer[{$key}]"] = get_string('answermustbegiven', 'qtype_shortanswer'); $answercount++; } } } if ($answercount == 0) { $errors['answer[0]'] = get_string('notenoughanswers', 'qtype_shortanswer', 1); } if ($maxgrade == false) { $errors['fraction[0]'] = get_string('fractionsnomax', 'question'); } return $errors; }
function set_data($question) { if (empty($question->name)) { $question->name = get_string("random", "quiz"); } parent::set_data($question); }
public function validation($data, $files) { global $DB; $errors = parent::validation($data, $files); if (isset($data->categorymoveto)) { list($category) = explode(',', $data['categorymoveto']); } else { list($category) = explode(',', $data['category']); } $saquestions = question_bank::get_qtype('randomsamatch')->get_sa_candidates($category); $numberavailable = count($saquestions); if ($saquestions === false) { $a = new stdClass(); $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category)); $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a); } else { if ($numberavailable < $data['choose']) { $a = new stdClass(); $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category)); $a->nosaquestions = $numberavailable; $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a); } } return $errors; }
protected function data_preprocessing($question) { $question = parent::data_preprocessing($question); if (empty($question->options)) { return $question; } $question->responseformat = $question->options->responseformat; $question->responsefieldlines = $question->options->responsefieldlines; $question->attachments = $question->options->attachments; $question->boardsize = $question->options->boardsize; //Set backimage details, and configure a draft area to accept any uploaded pictures //all this and this whole method does, is to load existing files into a filearea //so it is not called when creating a new question, only when editing an existing one //best to use file_get_submitted_draft_itemid - because copying questions gets weird otherwise //$draftitemid =$question->options->backimage; $draftitemid = file_get_submitted_draft_itemid('backimage'); file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_poodllrecording', 'backimage', !empty($question->id) ? (int) $question->id : null, array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1)); $question->backimage = $draftitemid; $draftid = file_get_submitted_draft_itemid('graderinfo'); $question->graderinfo = array(); $question->graderinfo['text'] = file_prepare_draft_area($draftid, $this->context->id, 'qtype_poodllrecording', 'graderinfo', !empty($question->id) ? (int) $question->id : null, $this->fileoptions, $question->options->graderinfo); $question->graderinfo['format'] = $question->options->graderinfoformat; $question->graderinfo['itemid'] = $draftid; return $question; }
protected function data_preprocessing($question) { $question = parent::data_preprocessing($question); if (empty($question->options)) { return $question; } $question->responseformat = $question->options->responseformat; $question->responsefieldlines = $question->options->responsefieldlines; $question->attachments = $question->options->attachments; $draftid = file_get_submitted_draft_itemid('graderinfo'); $question->graderinfo = array(); $question->graderinfo['text'] = file_prepare_draft_area( $draftid, // draftid $this->context->id, // context 'qtype_essay', // component 'graderinfo', // filarea !empty($question->id) ? (int) $question->id : null, // itemid $this->fileoptions, // options $question->options->graderinfo // text ); $question->graderinfo['format'] = $question->options->graderinfoformat; $question->graderinfo['itemid'] = $draftid; $question->responselimitpolicy = $question->options->responselimitpolicy; $question->wordlimit = $question->options->wordlimit; $question->charlimit = $question->options->charlimit; return $question; }
function validation($data) { $errors = parent::validation($data); $answers = $data['subanswers']; $questions = $data['subquestions']; $questioncount = 0; foreach ($questions as $key => $question) { $trimmedquestion = trim($question); $trimmedanswer = trim($answers[$key]); if (!empty($trimmedanswer) && !empty($trimmedquestion)) { $questioncount++; } if (!empty($trimmedquestion) && empty($trimmedanswer)) { $errors['subanswers[' . $key . ']'] = get_string('nomatchinganswerforq', 'qtype_match', $trimmedquestion); } } if ($questioncount == 0) { $errors['subquestions[0]'] = get_string('notenoughquestions', 'qtype_match', 3); $errors['subquestions[1]'] = get_string('notenoughquestions', 'qtype_match', 3); $errors['subquestions[2]'] = get_string('notenoughquestions', 'qtype_match', 3); } elseif ($questioncount == 1) { $errors['subquestions[1]'] = get_string('notenoughquestions', 'qtype_match', 3); $errors['subquestions[2]'] = get_string('notenoughquestions', 'qtype_match', 3); } elseif ($questioncount == 2) { $errors['subquestions[2]'] = get_string('notenoughquestions', 'qtype_match', 3); } return $errors; }
function validation($data, $files) { $errors = parent::validation($data, $files); $answers = $data['answer']; $answercount = 0; $totalfraction = 0; $maxfraction = -1; foreach ($answers as $key => $answer) { //check no of choices $trimmedanswer = trim($answer); if (!empty($trimmedanswer)) { $answercount++; } //check grades if ($answer != '') { if ($data['fraction'][$key] > 0) { $totalfraction += $data['fraction'][$key]; } if ($data['fraction'][$key] > $maxfraction) { $maxfraction = $data['fraction'][$key]; } } } if ($answercount == 0) { $errors['answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 1); } $totalfraction = round($totalfraction, 2); if ($totalfraction != 1) { $totalfraction = $totalfraction * 100; $errors['fraction[0]'] = get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction); } return $errors; }
function set_data($question) { if (!empty($question->options) && !empty($question->options->answers)) { $answer = reset($question->options->answers); $question->feedback = $answer->feedback; } $question->penalty = 0; parent::set_data($question); }
function set_data($question) { if (empty($question->name)) { $question->name = get_string("randomsamatch", "quiz"); } if (empty($question->questiontext)) { $question->questiontext = get_string("randomsamatchintro", "quiz"); } parent::set_data($question); }
function set_data($question) { if (!empty($question->options->trueanswer)) { $trueanswer = $question->options->answers[$question->options->trueanswer]; $question->correctanswer = $trueanswer->fraction != 0; $question->feedbacktrue = $trueanswer->feedback; $question->feedbackfalse = $question->options->answers[$question->options->falseanswer]->feedback; } parent::set_data($question); }
function validation($data, $files) { //TODO would be nice to parse the question text here and output some error //messages if there is a problem with the text. $errors = parent::validation($data, $files); //extra check to make sure there is something in the htmlarea besides a <br /> $questiontext = trim(strip_tags($data['questiontext'])); if ($questiontext == '') { $errors['questiontext'] = get_string('err_required', 'form'); } return $errors; }
function set_data($question) { if (!empty($question->options)) { $question->essay = $question->options->essay; $question->maxbytes = $question->options->maxbytes; if (!empty($question->options->answers)) { $answer = reset($question->options->answers); $question->feedback = $answer->feedback; } } $question->penalty = 0; parent::set_data($question); }
protected function data_preprocessing($question) { $question = parent::data_preprocessing($question); if (empty($question->options)) { return $question; } $question->responseformat = $question->options->responseformat; $question->responsefieldlines = $question->options->responsefieldlines; $question->attachments = $question->options->attachments; $draftid = file_get_submitted_draft_itemid('graderinfo'); $question->graderinfo = array(); $question->graderinfo['text'] = file_prepare_draft_area($draftid, $this->context->id, 'qtype_poodllrecording', 'graderinfo', !empty($question->id) ? (int) $question->id : null, $this->fileoptions, $question->options->graderinfo); $question->graderinfo['format'] = $question->options->graderinfoformat; $question->graderinfo['itemid'] = $draftid; return $question; }
public function validation($data, $files) { $errors = parent::validation($data, $files); $answers = $data['answer']; $answercount = 0; $totalfraction = 0; $maxfraction = -1; foreach ($answers as $key => $answer) { //check no of choices $trimmedanswer = trim($answer['text']); $fraction = (double) $data['fraction'][$key]; if ($trimmedanswer === '' && empty($fraction)) { continue; } if ($trimmedanswer === '') { $errors['fraction[' . $key . ']'] = get_string('errgradesetanswerblank', 'qtype_turmultiplechoice'); } $answercount++; //check grades if ($data['fraction'][$key] > 0) { $totalfraction += $data['fraction'][$key]; } if ($data['fraction'][$key] > $maxfraction) { $maxfraction = $data['fraction'][$key]; } } if ($answercount == 0) { $errors['answer[0]'] = get_string('notenoughanswers', 'qtype_turmultiplechoice', 2); $errors['answer[1]'] = get_string('notenoughanswers', 'qtype_turmultiplechoice', 2); } else { if ($answercount == 1) { $errors['answer[1]'] = get_string('notenoughanswers', 'qtype_turmultiplechoice', 2); } } /// Perform sanity checks on fractional grades if ($data['single']) { if ($maxfraction != 1) { $errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_turmultiplechoice', $maxfraction * 100); } } else { $totalfraction = round($totalfraction, 2); if ($totalfraction != 1) { $errors['fraction[0]'] = get_string('errfractionsaddwrong', 'qtype_turmultiplechoice', $totalfraction * 100); } } return $errors; }
function set_data($question) { if (isset($question->options)) { $answers = $question->options->answers; if (count($answers)) { $key = 0; foreach ($answers as $answer) { $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } } $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
public function data_preprocessing($question) { $question = parent::data_preprocessing($question); if (!empty($question->options->trueanswer)) { $trueanswer = $question->options->answers[$question->options->trueanswer]; $question->correctanswer = ($trueanswer->fraction != 0); $draftid = file_get_submitted_draft_itemid('trueanswer'); $answerid = $question->options->trueanswer; $question->feedbacktrue = array(); $question->feedbacktrue['format'] = $trueanswer->feedbackformat; $question->feedbacktrue['text'] = file_prepare_draft_area( $draftid, // draftid $this->context->id, // context 'question', // component 'answerfeedback', // filarea !empty($answerid) ? (int) $answerid : null, // itemid $this->fileoptions, // options $trueanswer->feedback // text ); $question->feedbacktrue['itemid'] = $draftid; } if (!empty($question->options->falseanswer)) { $falseanswer = $question->options->answers[$question->options->falseanswer]; $draftid = file_get_submitted_draft_itemid('falseanswer'); $answerid = $question->options->falseanswer; $question->feedbackfalse = array(); $question->feedbackfalse['format'] = $falseanswer->feedbackformat; $question->feedbackfalse['text'] = file_prepare_draft_area( $draftid, // draftid $this->context->id, // context 'question', // component 'answerfeedback', // filarea !empty($answerid) ? (int) $answerid : null, // itemid $this->fileoptions, // options $falseanswer->feedback // text ); $question->feedbackfalse['itemid'] = $draftid; } return $question; }
function set_data($question) { if (isset($question->options)) { $subquestions = $question->options->subquestions; if (count($subquestions)) { $key = 0; foreach ($subquestions as $subquestion) { $default_values['subanswers[' . $key . ']'] = $subquestion->answertext; $default_values['subquestions[' . $key . ']'] = $subquestion->questiontext; $key++; } } $default_values['shuffleanswers'] = $question->options->shuffleanswers; $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
function validation($data, $files) { global $QTYPES; $errors = parent::validation($data, $files); $saquestions = $QTYPES['randomsamatch']->get_sa_candidates($data['category']); $numberavailable = count($saquestions); if ($saquestions === false) { $a = new object(); $a->catname = get_field('question_categories', 'name', 'id', $data['category']); $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a); } elseif ($numberavailable < $data['choose']) { $a = new object(); $a->catname = get_field('question_categories', 'name', 'id', $data['category']); $a->nosaquestions = $numberavailable; $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a); } return $errors; }
public function validation($data, $files) { $errors = parent::validation($data, $files); // cleanup : $data['conditions'] = rtrim(str_replace("\r\n", "\n", $data['conditions']), "\n"); $data['feedbackperconditions'] = rtrim(str_replace("\r\n", "\n", $data['feedbackperconditions']), "\n"); $conditions = explode("\n", $data['conditions']); $feedbackperconditions = explode("\n", $data['feedbackperconditions']); if (count($feedbackperconditions) > count($conditions)) { $errors['conditions'] = get_string('badnumfeedbackperconditions', 'qtype_multinumerical'); $errors['feedbackperconditions'] = get_string('badnumfeedbackperconditions', 'qtype_multinumerical'); } foreach ($feedbackperconditions as $feedbackpercondition) { if (trim($feedbackpercondition) && strpos($feedbackpercondition, '|') === false) { $errors['feedbackperconditions'] = get_string('badfeedbackperconditionsyntax', 'qtype_multinumerical'); } } return $errors; }
public function validation($fromform, $files) { $errors = parent::validation($fromform, $files); // Don't allow both 'no inline response' and 'no attachments' to be selected, // as these options would result in there being no input requested from the user. if ($fromform['responseformat'] == 'noinline' && !$fromform['attachments']) { $errors['attachments'] = get_string('mustattach', 'qtype_essay'); } // If 'no inline response' is set, force the teacher to require attachments; // otherwise there will be nothing to grade. if ($fromform['responseformat'] == 'noinline' && !$fromform['attachmentsrequired']) { $errors['attachmentsrequired'] = get_string('mustrequire', 'qtype_essay'); } // Don't allow the teacher to require more attachments than they allow; as this would // create a condition that it's impossible for the student to meet. if ($fromform['attachments'] != -1 && $fromform['attachments'] < $fromform['attachmentsrequired']) { $errors['attachmentsrequired'] = get_string('mustrequirefewer', 'qtype_essay'); } return $errors; }
function set_data($question) { if (isset($question->options)) { $answers = $question->options->answers; if (count($answers)) { $key = 0; foreach ($answers as $answer) { $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } } $default_values['single'] = $question->options->single; $default_values['shuffleanswers'] = $question->options->shuffleanswers; $default_values['correctfeedback'] = $question->options->correctfeedback; $default_values['partiallycorrectfeedback'] = $question->options->partiallycorrectfeedback; $default_values['incorrectfeedback'] = $question->options->incorrectfeedback; $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
function validation($data) { $errors = parent::validation($data); $answers = $data['answer']; $answercount = 0; $maxgrade = false; foreach ($answers as $key => $answer) { $trimmedanswer = trim($answer); if ($trimmedanswer !== '') { $answercount++; if ($data['fraction'][$key] == 1) { $maxgrade = true; } } } if ($answercount == 0) { $errors['answer[0]'] = get_string('notenoughanswers', 'quiz', 1); } if ($maxgrade == false) { $errors['fraction[0]'] = get_string('fractionsnomax', 'question'); } return $errors; }
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 = ""; $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]; $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 { $errors['questiontext'] .= '<br/>' . $formulaerrors . ':' . $regs1[1]; } } } $answers = $data['answer']; $answercount = 0; $maxgrade = false; $possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']['text']); $mandatorydatasets = array(); 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 ($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++; } //check grades $totalfraction = 0; $maxfraction = 0; if ($answer != '') { if ($data['fraction'][$key] > 0) { $totalfraction += $data['fraction'][$key]; } if ($data['fraction'][$key] > $maxfraction) { $maxfraction = $data['fraction'][$key]; } } } if ($answercount == 0) { $errors['answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 2); $errors['answer[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2); } elseif ($answercount == 1) { $errors['answer[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2); } /// Perform sanity checks on fractional grades if ($data['single']) { if ($maxfraction > 0.999) { $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); } } if ($answercount == 0) { $errors['answer[0]'] = get_string('atleastoneanswer', 'qtype_calculated'); } if ($maxgrade == false) { $errors['fraction[0]'] = get_string('fractionsnomax', 'question'); } } return $errors; }
/** * This method should be overriden if you want to include a special heading or some other * html on a question editing page besides the question editing form. * * @param question_edit_form $mform a child of question_edit_form * @param object $question * @param string $wizardnow is '' for first page. */ function display_question_editing_page(&$mform, $question, $wizardnow) { list($heading, $langmodule) = $this->get_heading(empty($question->id)); print_heading_with_help($heading, $this->name(), $langmodule); $permissionstrs = array(); if (!empty($question->id)) { if ($question->formoptions->canedit) { $permissionstrs[] = get_string('permissionedit', 'question'); } if ($question->formoptions->canmove) { $permissionstrs[] = get_string('permissionmove', 'question'); } if ($question->formoptions->cansaveasnew) { $permissionstrs[] = get_string('permissionsaveasnew', 'question'); } } if (!$question->formoptions->movecontext && count($permissionstrs)) { print_heading(get_string('permissionto', 'question'), 'center', 3); $html = '<ul>'; foreach ($permissionstrs as $permissionstr) { $html .= '<li>' . $permissionstr . '</li>'; } $html .= '</ul>'; print_box($html, 'boxwidthnarrow boxaligncenter generalbox'); } $mform->display(); }
/** * This method should be overriden if you want to include a special heading or some other * html on a question editing page besides the question editing form. * * @param question_edit_form $mform a child of question_edit_form * @param object $question * @param string $wizardnow is '' for first page. */ public function display_question_editing_page($mform, $question, $wizardnow) { global $OUTPUT; $heading = $this->get_heading(empty($question->id)); echo $OUTPUT->heading_with_help($heading, 'pluginname', $this->plugin_name()); $permissionstrs = array(); if (!empty($question->id)) { if ($question->formoptions->canedit) { $permissionstrs[] = get_string('permissionedit', 'question'); } if ($question->formoptions->canmove) { $permissionstrs[] = get_string('permissionmove', 'question'); } if ($question->formoptions->cansaveasnew) { $permissionstrs[] = get_string('permissionsaveasnew', 'question'); } } if (count($permissionstrs)) { echo $OUTPUT->heading(get_string('permissionto', 'question'), 3); $html = '<ul>'; foreach ($permissionstrs as $permissionstr) { $html .= '<li>'.$permissionstr.'</li>'; } $html .= '</ul>'; echo $OUTPUT->box($html, 'boxwidthnarrow boxaligncenter generalbox'); } $mform->display(); }
function validation($data, $files) { $errors = parent::validation($data, $files); $questiondisplay = qtype_multianswer_extract_question($data['questiontext']); // echo "<p> questiondisplay ".$data['questiontext']['text']." <pre>";print_r($questiondisplay);echo "</pre></p>"; if (isset($questiondisplay->options->questions)) { $subquestions = fullclone($questiondisplay->options->questions); if (count($subquestions)) { $sub = 1; foreach ($subquestions as $subquestion) { $prefix = 'sub_' . $sub . '_'; $answercount = 0; $maxgrade = false; $maxfraction = -1; if (isset($this->savedquestiondisplay->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]; } foreach ($subquestion->answer as $key => $answer) { $trimmedanswer = trim($answer); if ($trimmedanswer !== '') { $answercount++; if ($subquestion->qtype == 'numerical' && !(is_numeric($trimmedanswer) || $trimmedanswer == '*')) { $errors[$prefix . 'answer[' . $key . ']'] = get_string('answermustbenumberorstar', 'qtype_numerical'); } if ($subquestion->fraction[$key] == 1) { $maxgrade = true; } if ($subquestion->fraction[$key] > $maxfraction) { $maxfraction = $subquestion->fraction[$key]; } } } if ($answercount == 0) { if ($subquestion->qtype == 'multichoice') { $errors[$prefix . 'answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 2); } else { $errors[$prefix . 'answer[0]'] = get_string('notenoughanswers', 'quiz', 1); } } if ($maxgrade == false) { $errors[$prefix . 'fraction[0]'] = get_string('fractionsnomax', 'question'); } $sub++; } } else { $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->qtype_change)) && $this->confirm == 0) { $errors['confirm'] = get_string('confirmsave', 'qtype_multianswer', $this->negative_diff); } return $errors; }
/** * This method should be overriden if you want to include a special heading or some other * html on a question editing page besides the question editing form. * * @param question_edit_form $mform a child of question_edit_form * @param object $question * @param string $wizardnow is '' for first page. */ public function display_question_editing_page($mform, $question, $wizardnow) { global $OUTPUT; $heading = $this->get_heading(empty($question->id)); if (get_string_manager()->string_exists('pluginname_help', $this->plugin_name())) { echo $OUTPUT->heading_with_help($heading, 'pluginname', $this->plugin_name()); } else { echo $OUTPUT->heading_with_help($heading, $this->name(), $this->plugin_name()); } //Who cares about that: // $permissionstrs = array(); // if (!empty($question->id)) { // if ($question->formoptions->canedit) { // $permissionstrs[] = get_string('permissionedit', 'question'); // } // if ($question->formoptions->canmove) { // $permissionstrs[] = get_string('permissionmove', 'question'); // } // if ($question->formoptions->cansaveasnew) { // $permissionstrs[] = get_string('permissionsaveasnew', 'question'); // } // } // if (!$question->formoptions->movecontext && count($permissionstrs)) { // echo $OUTPUT->heading(get_string('permissionto', 'question'), 3); // $html = '<ul>'; // foreach ($permissionstrs as $permissionstr) { // $html .= '<li>'.$permissionstr.'</li>'; // } // $html .= '</ul>'; // echo $OUTPUT->box($html, 'boxwidthnarrow boxaligncenter generalbox'); // } $mform->display(); }