}
function question_insert_site_file_names($course, $backup_unique_code){
- global $QTYPES, $CFG, $DB;
+ global $QTYPES, $CFG, $DB, $OUTPUT;
$status = true;
$questionids = question_ids_by_backup ($backup_unique_code);
$urls = array();
$inserturl->path = $url;
$status = $status && $DB->insert_record('backup_files', $inserturl);
} else {
- notify(get_string('linkedfiledoesntexist', 'question', $url));
+ echo $OUTPUT->notification(get_string('linkedfiledoesntexist', 'question', $url));
}
}
return $status;
if (!$category = $DB->get_record('question_categories',
array('id' => $categoryid, 'contextid' => $contextid))) {
echo $OUTPUT->box_start('generalbox questionbank');
- notify('Category not found!');
+ echo $OUTPUT->notification('Category not found!');
echo $OUTPUT->box_end();
return false;
}
* @param boolean $disabled if true, the button will be disabled.
*/
function create_new_question_button($categoryid, $params, $caption, $tooltip = '', $disabled = false) {
- global $CFG, $PAGE;
+ global $CFG, $PAGE, $OUTPUT;
static $choiceformprinted = false;
$params['category'] = $categoryid;
print_single_button($CFG->wwwroot . '/question/addquestion.php', $params,
$caption,'get', '', false, $tooltip, $disabled);
- helpbutton('types', get_string('createnewquestion', 'question'), 'question');
+ echo $OUTPUT->help_icon(moodle_help_icon::make('types', get_string('createnewquestion', 'question'), 'question'));
$PAGE->requires->yui_lib('dragdrop');
$PAGE->requires->yui_lib('container');
if (!$choiceformprinted) {
$PAGE->requires->js_function_call('document.location.replace', array($efile))->after_delay(1);
}
- print_continue('edit.php?' . $thispageurl->get_query_string());
+ echo $OUTPUT->continue_button('edit.php?' . $thispageurl->get_query_string());
echo $OUTPUT->footer();
exit;
}
* @return boolean success
*/
function importprocess() {
- global $USER, $DB;
+ global $USER, $DB, $OUTPUT;
// reset the timer in case file upload was slow
@set_time_limit();
// STAGE 1: Parse the file
- notify( get_string('parsingquestions','quiz') );
+ echo $OUTPUT->notification( get_string('parsingquestions','quiz') );
if (! $lines = $this->readdata($this->filename)) {
- notify( get_string('cannotread','quiz') );
+ echo $OUTPUT->notification( get_string('cannotread','quiz') );
return false;
}
if (! $questions = $this->readquestions($lines)) { // Extract all the questions
- notify( get_string('noquestionsinfile','quiz') );
+ echo $OUTPUT->notification( get_string('noquestionsinfile','quiz') );
return false;
}
// STAGE 2: Write data to database
- notify( get_string('importingquestions','quiz',$this->count_questions($questions)) );
+ echo $OUTPUT->notification( get_string('importingquestions','quiz',$this->count_questions($questions)) );
// check for errors before we continue
if ($this->stoponerror and ($this->importerrors>0)) {
- notify( get_string('importparseerror','quiz') );
+ echo $OUTPUT->notification( get_string('importparseerror','quiz') );
return true;
}
}
}
if (!$answersvalid) {
- notify(get_string('matcherror', 'quiz'));
+ echo $OUTPUT->notification(get_string('matcherror', 'quiz'));
++$gradeerrors;
continue;
}
->save_question_options($question);
if (!empty($result->error)) {
- notify($result->error);
+ echo $OUTPUT->notification($result->error);
return false;
}
if (!empty($result->notice)) {
- notify($result->notice);
+ echo $OUTPUT->notification($result->notice);
return true;
}
* @return boolean success
*/
function exportprocess() {
- global $CFG;
+ global $CFG, $OUTPUT;
// create a directory for the exports (if not already existing)
if (! $export_dir = make_upload_directory($this->question_get_export_dir())) {
$questions = $this->questions;
}
- notify( get_string('exportingquestions','quiz') );
+ echo $OUTPUT->notification( get_string('exportingquestions','quiz') );
$count = 0;
// results are first written into string (and then to a file)
}
function writequestion( $question ) {
- global $QTYPES;
+ global $QTYPES, $OUTPUT;
// turns question into string
// question reflects database fields for general question and specific to type
}
else {
$expout .= "Question type $question->qtype is not supported\n";
- notify( get_string('nohandler', 'qformat_gift', $QTYPES[$question->qtype]->local_name()) );
+ echo $OUTPUT->notification( get_string('nohandler', 'qformat_gift', $QTYPES[$question->qtype]->local_name()) );
}
}
// add empty line to delimit questions
*/
function exportprocess() {
- global $CFG;
+ global $CFG, $OUTPUT;
$courseid = $this->course->id;
// create a directory for the exports (if not already existing)
// get the questions (from database) in this category
$questions = get_questions_category( $this->category );
- notify("Exporting ".count($questions)." questions.");
+ echo $OUTPUT->notification("Exporting ".count($questions)." questions.");
$count = 0;
// create the imsmanifest file
// copy files used by the main questions to the export directory
$result = $this->handle_questions_media($questions, $path, $courseid);
if ($result !== true) {
- notify(implode("<br />", $result));
+ echo $OUTPUT->notification(implode("<br />", $result));
}
$manifestquestions = $this->objects_to_array($questions);
}
function writequestion( $question ) {
+ global $OUTPUT;
// turns question into string
// question reflects database fields for general question and specific to type
$expout .= "<!-- CLOZE type is not supported -->\n";
break;
default:
- notify("No handler for qtype $question->qtype for GIFT export" );
+ echo $OUTPUT->notification("No handler for qtype $question->qtype for GIFT export" );
}
// close off div
$expout .= "</div>\n\n\n";
*/
function import_truefalse( $question ) {
// get common parts
+ global $OUTPUT;
$qo = $this->import_headers( $question );
// 'header' parts particular to true/false
$a = new stdClass;
$a->questiontext = $qo->questiontext;
$a->answer = get_string($qo->answer ? 'true' : 'false', 'quiz');
- notify(get_string('truefalseimporterror', 'quiz', $a));
+ echo $OUTPUT->notification(get_string('truefalseimporterror', 'quiz', $a));
}
return $qo;
}
* @return string xml segment
*/
function writequestion( $question ) {
- global $CFG,$QTYPES;
+ global $CFG,$QTYPES, $OUTPUT;
// initial string;
$expout = "";
default:
// try support by optional plugin
if (!$data = $this->try_exporting_using_qtypes( $question->qtype, $question )) {
- notify( get_string( 'unsupportedexport','qformat_xml',$QTYPES[$question->qtype]->local_name() ) );
+ echo $OUTPUT->notification( get_string( 'unsupportedexport','qformat_xml',$QTYPES[$question->qtype]->local_name() ) );
}
$expout .= $data;
}
}
echo "<hr />";
- print_continue("edit.php?".($thispageurl->get_query_string(array('category'=>"{$qformat->category->id},{$qformat->category->contextid}"))));
+ echo $OUTPUT->continue_button("edit.php?".($thispageurl->get_query_string(array('category'=>"{$qformat->category->id},{$qformat->category->contextid}"))));
echo $OUTPUT->footer();
exit;
}
if (($QTYPES[$question->qtype]->finished_edit_wizard($fromform)) || $movecontext){
if ($inpopup) {
- notify(get_string('changessaved'), '');
+ echo $OUTPUT->notification(get_string('changessaved'), '');
close_window(3);
} else {
$nexturl = new moodle_url($returnurl);
function get_question_options(&$question) {
// First get the datasets and default options
- global $CFG, $DB;
+ global $CFG, $DB, $OUTPUT;
if (!$question->options->answers = $DB->get_records_sql(
"SELECT a.*, c.tolerance, c.tolerancetype, c.correctanswerlength, c.correctanswerformat " .
"FROM {question_answers} a, " .
"WHERE a.question = ? " .
"AND a.id = c.answer ".
"ORDER BY a.id ASC", array($question->id))) {
- notify('Error: Missing question answer for calculated question ' . $question->id . '!');
+ echo $OUTPUT->notification('Error: Missing question answer for calculated question ' . $question->id . '!');
return false;
}
}
function restore_session_and_responses(&$question, &$state) {
+ global $OUTPUT;
if (!preg_match('~^dataset([0-9]+)[^-]*-(.*)$~',
$state->responses[''], $regs)) {
- notify ("Wrongly formatted raw response answer " .
+ echo $OUTPUT->notification("Wrongly formatted raw response answer " .
"{$state->responses['']}! Could not restore session for " .
" question #{$question->id}.");
$state->options->datasetitem = 1;
. $form->calclength[$key+1];
break;
default:
- notify("Unexpected distribution ".$form->calcdistribution[$key+1]);
+ echo $OUTPUT->notification("Unexpected distribution ".$form->calcdistribution[$key+1]);
}
}
}
}
function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) {
- global $DB;
+ global $DB, $OUTPUT;
if (!$state->options->subquestions = $DB->get_records('question_match_sub', array('question' => $question->id), 'id ASC')) {
- notify('Error: Missing subquestions!');
+ echo $OUTPUT->notification('Error: Missing subquestions!');
return false;
}
}
function restore_session_and_responses(&$question, &$state) {
- global $DB;
+ global $DB, $OUTPUT;
static $subquestions = array();
if (!isset($subquestions[$question->id])){
if (!$subquestions[$question->id] = $DB->get_records('question_match_sub', array('question' => $question->id), 'id ASC')) {
- notify('Error: Missing subquestions!');
+ echo $OUTPUT->notification('Error: Missing subquestions!');
return false;
}
}
}
function has_wildcards_in_responses($question, $subqid) {
- global $QTYPES;
+ global $QTYPES, $OUTPUT;
foreach ($question->options->questions as $subq){
if ($subq->id == $subqid){
return $QTYPES[$subq->qtype]->has_wildcards_in_responses($subq, $subqid);
}
}
- notify('Could not find sub question!');
+ echo $OUTPUT->notification('Could not find sub question!');
return true;
}
}
function get_question_options(&$question) {
- global $QTYPES, $DB;
+ global $QTYPES, $DB, $OUTPUT;
// Get relevant data indexed by positionkey from the multianswers table
if (!$sequence = $DB->get_field('question_multianswer', 'sequence', array('question' => $question->id))) {
- notify(get_string('noquestions','qtype_multianswer',$question->name));
+ echo $OUTPUT->notification(get_string('noquestions','qtype_multianswer',$question->name));
$question->options->questions['1']= '';
return true ;
}
if (isset($wrappedquestions) && is_array($wrappedquestions)){
foreach ($wrappedquestions as $wrapped) {
if (!$QTYPES[$wrapped->qtype]->get_question_options($wrapped)) {
- notify("Unable to get options for questiontype {$wrapped->qtype} (id={$wrapped->id})");
+ echo $OUTPUT->notification("Unable to get options for questiontype {$wrapped->qtype} (id={$wrapped->id})");
}else {
// for wrapped questions the maxgrade is always equal to the defaultgrade,
// there is no entry in the question_instances table for them
}
}
if ($nbvaliquestion == 0 ) {
- notify(get_string('noquestions','qtype_multianswer',$question->name));
+ echo $OUTPUT->notification(get_string('noquestions','qtype_multianswer',$question->name));
}
return true;
}
function restore_recode_answer($state, $restore) {
- global $DB;
+ global $DB, $OUTPUT;
//The answer is a comma separated list of hypen separated sequence number and answers. We may have to recode the answers
$answer_field = "";
$in_first = true;
$wrappedquestionid = $sequence[$seqnum-1];
// now we can find the question
if (!$wrappedquestion = $DB->get_record('question', array('id' => $wrappedquestionid))) {
- notify("Can't find the subquestion $wrappedquestionid that is used as part $seqnum in cloze question $state->question");
+ echo $OUTPUT->notification("Can't find the subquestion $wrappedquestionid that is used as part $seqnum in cloze question $state->question");
}
// For multichoice question we need to recode the answer
if ($answer and $wrappedquestion->qtype == 'multichoice') {
}
function get_question_options(&$question) {
- global $DB;
+ global $DB, $OUTPUT;
// Get additional information from database
// and attach it to the question object
if (!$question->options = $DB->get_record('question_multichoice', array('question' => $question->id))) {
- notify('Error: Missing question options for multichoice question'.$question->id.'!');
+ echo $OUTPUT->notification('Error: Missing question options for multichoice question'.$question->id.'!');
return false;
}
list ($usql, $params) = $DB->get_in_or_equal(explode(',', $question->options->answers));
if (!$question->options->answers = $DB->get_records_select('question_answers', "id $usql", $params, 'id')) {
- notify('Error: Missing question answers for multichoice question'.$question->id.'!');
+ echo $OUTPUT->notification('Error: Missing question answers for multichoice question'.$question->id.'!');
return false;
}
// Note: question_numerical is an extension of the answer table rather than
// the question table as is usually the case for qtype
// specific tables.
- global $CFG, $DB;
+ global $CFG, $DB, $OUTPUT;
if (!$question->options->answers = $DB->get_records_sql(
"SELECT a.*, n.tolerance " .
"FROM {question_answers} a, " .
"WHERE a.question = ? " .
" AND a.id = n.answer " .
"ORDER BY a.id ASC", array($question->id))) {
- notify('Error: Missing question answer for numerical question ' . $question->id . '!');
+ echo $OUTPUT->notification('Error: Missing question answer for numerical question ' . $question->id . '!');
return false;
}
$this->get_numerical_units($question);
* specific information (it is passed by reference).
*/
function get_question_options(&$question) {
- global $CFG, $DB;
+ global $CFG, $DB, $OUTPUT;
if (!isset($question->options)) {
$question->options = new object;
$question->options->$field = $extra_data->$field;
}
} else {
- notify("Failed to load question options from the table $question_extension_table for questionid " .
+ echo $OUTPUT->notification("Failed to load question options from the table $question_extension_table for questionid " .
$question->id);
return false;
}
FROM {question_answers} qa, {$answer_extension_table} qax
WHERE qa.questionid = ? AND qax.answerid = qa.id", array($question->id));
if (!$question->options->answers) {
- notify("Failed to load question answers from the table $answer_extension_table for questionid " .
+ echo $OUTPUT->notification("Failed to load question answers from the table $answer_extension_table for questionid " .
$question->id);
return false;
}
/* This default implementation prints an error and must be overridden
by all question type implementations, unless the default implementation
of print_question has been overridden. */
-
- notify('Error: Question formulation and input controls has not'
+ global $OUTPUT;
+ echo $OUTPUT->notification('Error: Question formulation and input controls has not'
.' been implemented for question type '.$this->name());
}
/// From version 1.5 and later the question type random works like all
/// the other question types in that it now only needs one response
/// record per question.
- global $QTYPES, $DB;
+ global $QTYPES, $DB, $OUTPUT;
if (!preg_match('~^random([0-9]+)-(.*)$~', $state->responses[''], $answerregs)) {
if (empty($state->responses[''])) {
// This is the case if there weren't enough questions available in the category.
}
// this must be an old-style state which stores only the id for the wrapped question
if (!$wrappedquestion = $DB->get_record('question', array('id' => $state->responses['']))) {
- notify("Can not find wrapped question {$state->responses['']}");
+ echo $OUTPUT->notification("Can not find wrapped question {$state->responses['']}");
}
// In the old model the actual response was stored in a separate entry in
// the state table and fortunately there was only a single state per question
if (!$state->responses[''] = $DB->get_field('question_states', 'answer', array('attempt' => $state->attempt, 'question' => $wrappedquestion->id))) {
- notify("Wrapped state missing");
+ echo $OUTPUT->notification("Wrapped state missing");
}
} else {
if (!$wrappedquestion = $DB->get_record('question', array('id' => $answerregs[1]))) {
}
function get_question_options(&$question) {
- global $DB;
+ global $DB, $OUTPUT;
if (!$question->options = $DB->get_record('question_randomsamatch', array('question' => $question->id))) {
- notify('Error: Missing question options for random short answer question '.$question->id.'!');
+ echo $OUTPUT->notification('Error: Missing question options for random short answer question '.$question->id.'!');
return false;
}
// 1. All questions that are explicitly assigned to the quiz
// 2. All random questions
// 3. All questions that are already chosen by an other random question
- global $QTYPES;
+ global $QTYPES, $OUTPUT;
if (!isset($cmoptions->questionsinuse)) {
$cmoptions->questionsinuse = $cmoptions->questions;
}
questions were deleted after this Random Short-Answer question was
created.";
}
- notify($errorstr);
+ echo $OUTPUT->notification($errorstr);
$errorstr = '<span class="notifyproblem">' . $errorstr . '</span>';
}
function restore_session_and_responses(&$question, &$state) {
global $DB;
- global $QTYPES;
+ global $QTYPES, $OUTPUT;
static $wrappedquestions = array();
if (empty($state->responses[''])) {
$question->questiontext = "Insufficient selection options are
$state->responses[$wqid] = $response[1];
if (!isset($wrappedquestions[$wqid])){
if (!$wrappedquestions[$wqid] = $DB->get_record('question', array('id' => $wqid))) {
- notify("Couldn't get question (id=$wqid)!");
+ echo $OUTPUT->notification("Couldn't get question (id=$wqid)!");
return false;
}
if (!$QTYPES[$wrappedquestions[$wqid]->qtype]
->get_question_options($wrappedquestions[$wqid])) {
- notify("Couldn't get question options (id=$response[0])!");
+ echo $OUTPUT->notification("Couldn't get question options (id=$response[0])!");
return false;
}
if (!$QTYPES[$wrappedquestion->qtype]
->restore_session_and_responses($wrappedquestion, $state)) {
- notify("Couldn't restore session of question (id=$response[0])!");
+ echo $OUTPUT->notification("Couldn't restore session of question (id=$response[0])!");
return false;
}
$wrappedquestion->name_prefix = $question->name_prefix;
* Loads the question type specific options for the question.
*/
function get_question_options(&$question) {
- global $DB;
+ global $DB, $OUTPUT;
// Get additional information from database
// and attach it to the question object
if (!$question->options = $DB->get_record('question_truefalse', array('question' => $question->id))) {
- notify('Error: Missing question options!');
+ echo $OUTPUT->notification('Error: Missing question options!');
return false;
}
// Load the answers
if (!$question->options->answers = $DB->get_records('question_answers', array('question' => $question->id), 'id ASC')) {
- notify('Error: Missing question answers for truefalse question ' . $question->id . '!');
+ echo $OUTPUT->notification('Error: Missing question answers for truefalse question ' . $question->id . '!');
return false;
}