MDL-19822 Upgraded calls to helpbutton, print_simple_box* and notify

This commit is contained in:
nicolasconnault
2009-08-18 05:19:00 +00:00
parent de2bd9df22
commit fef8f84e4b
19 changed files with 71 additions and 68 deletions
+2 -2
View File
@@ -480,7 +480,7 @@
}
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();
@@ -501,7 +501,7 @@
$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;
+3 -3
View File
@@ -1140,7 +1140,7 @@ class question_bank_view {
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;
}
@@ -1910,12 +1910,12 @@ function print_qtype_to_add_option($qtype, $localizedname) {
* @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) {
+1 -1
View File
@@ -122,7 +122,7 @@
$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;
}
+11 -11
View File
@@ -216,30 +216,30 @@ class qformat_default {
* @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;
}
@@ -265,7 +265,7 @@ class qformat_default {
}
}
if (!$answersvalid) {
notify(get_string('matcherror', 'quiz'));
echo $OUTPUT->notification(get_string('matcherror', 'quiz'));
++$gradeerrors;
continue;
}
@@ -324,12 +324,12 @@ class qformat_default {
->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;
}
@@ -641,7 +641,7 @@ class qformat_default {
* @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())) {
@@ -657,7 +657,7 @@ class qformat_default {
$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)
+2 -2
View File
@@ -528,7 +528,7 @@ function repchar( $text, $format=0 ) {
}
function writequestion( $question ) {
global $QTYPES;
global $QTYPES, $OUTPUT;
// turns question into string
// question reflects database fields for general question and specific to type
@@ -648,7 +648,7 @@ function writequestion( $question ) {
}
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
+3 -3
View File
@@ -235,7 +235,7 @@ function handle_questions_media(&$questions, $path, $courseid) {
*/
function exportprocess() {
global $CFG;
global $CFG, $OUTPUT;
$courseid = $this->course->id;
// create a directory for the exports (if not already existing)
@@ -247,7 +247,7 @@ function handle_questions_media(&$questions, $path, $courseid) {
// 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
@@ -256,7 +256,7 @@ function handle_questions_media(&$questions, $path, $courseid) {
// 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);
+2 -1
View File
@@ -19,6 +19,7 @@ function repchar( $text ) {
}
function writequestion( $question ) {
global $OUTPUT;
// turns question into string
// question reflects database fields for general question and specific to type
@@ -108,7 +109,7 @@ function writequestion( $question ) {
$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";
+4 -3
View File
@@ -227,6 +227,7 @@ class qformat_xml extends qformat_default {
*/
function import_truefalse( $question ) {
// get common parts
global $OUTPUT;
$qo = $this->import_headers( $question );
// 'header' parts particular to true/false
@@ -263,7 +264,7 @@ class qformat_xml extends qformat_default {
$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;
}
@@ -772,7 +773,7 @@ class qformat_xml extends qformat_default {
* @return string xml segment
*/
function writequestion( $question ) {
global $CFG,$QTYPES;
global $CFG,$QTYPES, $OUTPUT;
// initial string;
$expout = "";
@@ -1013,7 +1014,7 @@ class qformat_xml extends qformat_default {
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;
}
+1 -1
View File
@@ -151,7 +151,7 @@
}
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;
}
+1 -1
View File
@@ -213,7 +213,7 @@ if ($mform->is_cancelled()){
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);
+5 -4
View File
@@ -28,7 +28,7 @@ class question_calculated_qtype extends default_questiontype {
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, " .
@@ -36,7 +36,7 @@ class question_calculated_qtype extends default_questiontype {
"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;
}
@@ -267,9 +267,10 @@ class question_calculated_qtype extends default_questiontype {
}
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;
@@ -834,7 +835,7 @@ class question_calculated_qtype extends default_questiontype {
. $form->calclength[$key+1];
break;
default:
notify("Unexpected distribution ".$form->calcdistribution[$key+1]);
echo $OUTPUT->notification("Unexpected distribution ".$form->calcdistribution[$key+1]);
}
}
}
+4 -4
View File
@@ -106,9 +106,9 @@ class question_match_qtype extends default_questiontype {
}
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;
}
@@ -135,11 +135,11 @@ class question_match_qtype extends default_questiontype {
}
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;
}
}
+8 -8
View File
@@ -24,13 +24,13 @@ class embedded_cloze_qtype extends default_questiontype {
}
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;
}
@@ -39,11 +39,11 @@ class embedded_cloze_qtype extends default_questiontype {
}
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 ;
}
@@ -65,7 +65,7 @@ class embedded_cloze_qtype extends default_questiontype {
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
@@ -76,7 +76,7 @@ class embedded_cloze_qtype extends default_questiontype {
}
}
if ($nbvaliquestion == 0 ) {
notify(get_string('noquestions','qtype_multianswer',$question->name));
echo $OUTPUT->notification(get_string('noquestions','qtype_multianswer',$question->name));
}
return true;
@@ -823,7 +823,7 @@ class embedded_cloze_qtype extends default_questiontype {
}
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;
@@ -842,7 +842,7 @@ class embedded_cloze_qtype extends default_questiontype {
$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') {
+3 -3
View File
@@ -19,17 +19,17 @@ class question_multichoice_qtype extends default_questiontype {
}
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;
}
+2 -2
View File
@@ -39,7 +39,7 @@ class question_numerical_qtype extends question_shortanswer_qtype {
// 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, " .
@@ -47,7 +47,7 @@ class question_numerical_qtype extends question_shortanswer_qtype {
"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);
+5 -5
View File
@@ -438,7 +438,7 @@ class default_questiontype {
* 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;
@@ -453,7 +453,7 @@ class default_questiontype {
$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;
}
@@ -467,7 +467,7 @@ class default_questiontype {
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;
}
@@ -1244,8 +1244,8 @@ class default_questiontype {
/* 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());
}
+3 -3
View File
@@ -230,7 +230,7 @@ class random_qtype extends default_questiontype {
/// 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.
@@ -241,12 +241,12 @@ class random_qtype extends default_questiontype {
}
// 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]))) {
+8 -8
View File
@@ -28,9 +28,9 @@ class question_randomsamatch_qtype extends question_match_qtype {
}
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;
}
@@ -80,7 +80,7 @@ class question_randomsamatch_qtype extends question_match_qtype {
// 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;
}
@@ -111,7 +111,7 @@ class question_randomsamatch_qtype extends question_match_qtype {
questions were deleted after this Random Short-Answer question was
created.";
}
notify($errorstr);
echo $OUTPUT->notification($errorstr);
$errorstr = '<span class="notifyproblem">' . $errorstr . '</span>';
}
@@ -171,7 +171,7 @@ class question_randomsamatch_qtype extends question_match_qtype {
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
@@ -191,12 +191,12 @@ class question_randomsamatch_qtype extends question_match_qtype {
$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;
}
@@ -217,7 +217,7 @@ class question_randomsamatch_qtype extends question_match_qtype {
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;
+3 -3
View File
@@ -82,16 +82,16 @@ class question_truefalse_qtype extends default_questiontype {
* 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;
}