From: jamiesensei Date: Tue, 4 Sep 2007 11:55:10 +0000 (+0000) Subject: fix for MDL-11106 Images not showing up in shared categories X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9fc3100f2721ba57bc9c7afaddea120d460153c3;p=moodle.git fix for MDL-11106 Images not showing up in shared categories --- diff --git a/lib/questionlib.php b/lib/questionlib.php index 68707d3da5..9f76f8827d 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1295,21 +1295,26 @@ function print_question_icon($question, $return = false) { * @return string The html image tag or the empy string if there is no image. * @param object $question The question object */ -function get_question_image($question, $courseid) { +function get_question_image($question) { global $CFG; $img = ''; + if (!$category = get_record('question_categories', 'id', $question->category)){ + error('invalid category id '.$question->category); + } + $coursefilesdir = get_filesdir_from_context(get_context_instance_by_id($category->contextid)); + if ($question->image) { if (substr(strtolower($question->image), 0, 7) == 'http://') { $img .= $question->image; } else if ($CFG->slasharguments) { // Use this method if possible for better caching - $img .= "$CFG->wwwroot/file.php/$courseid/$question->image"; + $img .= "$CFG->wwwroot/file.php/$coursefilesdir/$question->image"; } else { - $img .= "$CFG->wwwroot/file.php?file=/$courseid/$question->image"; + $img .= "$CFG->wwwroot/file.php?file=/$coursefilesdir/$question->image"; } } return $img; diff --git a/question/type/description/questiontype.php b/question/type/description/questiontype.php index f8042ecba3..8fb0894ec0 100644 --- a/question/type/description/questiontype.php +++ b/question/type/description/questiontype.php @@ -62,7 +62,7 @@ class description_qtype extends default_questiontype { } $questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions); - $image = get_question_image($question, $cmoptions->course); + $image = get_question_image($question); include "$CFG->dirroot/question/type/description/question.html"; } diff --git a/question/type/essay/questiontype.php b/question/type/essay/questiontype.php index 7f22bf89ed..de2ac01155 100644 --- a/question/type/essay/questiontype.php +++ b/question/type/essay/questiontype.php @@ -14,7 +14,7 @@ class question_essay_qtype extends default_questiontype { function name() { return 'essay'; } - + function is_manual_graded() { return true; } @@ -55,23 +55,23 @@ class question_essay_qtype extends default_questiontype { $answers = &$question->options->answers; $readonly = empty($options->readonly) ? '' : 'disabled="disabled"'; - + // Only use the rich text editor for the first essay question on a page. $usehtmleditor = can_use_html_editor() && !$htmleditorused; - + $formatoptions = new stdClass; $formatoptions->noclean = true; $formatoptions->para = false; - + $inputname = $question->name_prefix; $stranswer = get_string("answer", "quiz").': '; - + /// set question text and media $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course); - - $image = get_question_image($question, $cmoptions->course); + + $image = get_question_image($question); // feedback handling $feedback = ''; @@ -80,16 +80,16 @@ class question_essay_qtype extends default_questiontype { $feedback = format_text($answer->feedback, '', $formatoptions, $cmoptions->course); } } - + // get response value if (isset($state->responses[''])) { - $value = stripslashes_safe($state->responses['']); + $value = stripslashes_safe($state->responses['']); } else { $value = ""; } // answer - if (empty($options->readonly)) { + if (empty($options->readonly)) { // the student needs to type in their answer so print out a text editor $answer = print_textarea($usehtmleditor, 18, 80, 630, 400, $inputname, $value, $cmoptions->course, true); } else { @@ -99,7 +99,7 @@ class question_essay_qtype extends default_questiontype { $answer = format_text($value, FORMAT_MOODLE, $safeformatoptions, $cmoptions->course); } - + include("$CFG->dirroot/question/type/essay/display.html"); if ($usehtmleditor) { @@ -112,7 +112,7 @@ class question_essay_qtype extends default_questiontype { // All grading takes place in Manual Grading clean_param($state->responses[''], PARAM_CLEANHTML); - + $state->raw_grade = 0; $state->penalty = 0; @@ -121,8 +121,8 @@ class question_essay_qtype extends default_questiontype { /** * Backup the extra information specific to an essay question - over and above - * what is in the mdl_question table. - * + * what is in the mdl_question table. + * * @param file $bf The backup file to write to. * @param object $preferences the blackup options controlling this backup. * @param $questionid the id of the question being backed up. @@ -133,7 +133,7 @@ class question_essay_qtype extends default_questiontype { } // Restore method not needed. -} +} //// END OF CLASS //// ////////////////////////////////////////////////////////////////////////// diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php index 013215f3bb..f300c45658 100644 --- a/question/type/match/questiontype.php +++ b/question/type/match/questiontype.php @@ -268,7 +268,7 @@ class question_match_qtype extends default_questiontype { // Print formulation $questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions); - $image = get_question_image($question, $cmoptions->course); + $image = get_question_image($question); // Print the input controls foreach ($subquestions as $key => $subquestion) { diff --git a/question/type/missingtype/questiontype.php b/question/type/missingtype/questiontype.php index 9b9b8efc1b..1bbdcf6d41 100644 --- a/question/type/missingtype/questiontype.php +++ b/question/type/missingtype/questiontype.php @@ -42,7 +42,7 @@ class question_missingtype_qtype extends default_questiontype { $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course); - $image = get_question_image($question, $cmoptions->course); + $image = get_question_image($question); // Print each answer in a separate row if there are any $anss = array(); diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php index 51697a1875..fa6c8be0c8 100644 --- a/question/type/multianswer/questiontype.php +++ b/question/type/multianswer/questiontype.php @@ -45,7 +45,7 @@ class embedded_cloze_qtype extends default_questiontype { // for wrapped questions the maxgrade is always equal to the defaultgrade, // there is no entry in the question_instances table for them $wrapped->maxgrade = $wrapped->defaultgrade; - + $question->options->questions[$sequence[$wrapped->id]] = clone($wrapped); // ??? Why do we need a clone here? } @@ -55,14 +55,14 @@ class embedded_cloze_qtype extends default_questiontype { function save_question_options($question) { global $QTYPES; $result = new stdClass; - + // This function needs to be able to handle the case where the existing set of wrapped // questions does not match the new set of wrapped questions so that some need to be // created, some modified and some deleted // Unfortunately the code currently simply overwrites existing ones in sequence. This - // will make re-marking after a re-ordering of wrapped questions impossible and + // will make re-marking after a re-ordering of wrapped questions impossible and // will also create difficulties if questiontype specific tables reference the id. - + // First we get all the existing wrapped questions if (!$oldwrappedids = get_field('question_multianswer', 'sequence', 'question', $question->id)) { $oldwrappedids = array(); @@ -191,7 +191,7 @@ class embedded_cloze_qtype extends default_questiontype { } function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { - + global $QTYPES, $CFG, $USER; $readonly = empty($options->readonly) ? '' : 'readonly="readonly"'; $disabled = empty($options->readonly) ? '' : 'disabled="disabled"'; @@ -199,7 +199,7 @@ class embedded_cloze_qtype extends default_questiontype { $formatoptions->noclean = true; $formatoptions->para = false; $nameprefix = $question->name_prefix; - + // adding an icon with alt to warn user this is a fill in the gap question // MDL-7497 if (!empty($USER->screenreader)) { @@ -207,10 +207,10 @@ class embedded_cloze_qtype extends default_questiontype { "class=\"icon\" alt=\"".get_string('clozeaid','qtype_multichoice')."\" /> "; } // For this question type, we better print the image on top: - if ($image = get_question_image($question, $cmoptions->course)) { + if ($image = get_question_image($question)) { echo('
'); } - + $qtextremaining = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course); @@ -381,7 +381,7 @@ class embedded_cloze_qtype extends default_questiontype { } return $responses; } - + /// BACKUP FUNCTIONS //////////////////////////// /* diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index 744816c6a7..ddd3622b38 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -271,7 +271,7 @@ class question_multichoice_qtype extends default_questiontype { $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course); - $image = get_question_image($question, $cmoptions->course); + $image = get_question_image($question); $answerprompt = ($question->options->single) ? get_string('singleanswer', 'quiz') : get_string('multipleanswers', 'quiz'); diff --git a/question/type/shortanswer/questiontype.php b/question/type/shortanswer/questiontype.php index a303eb3b81..797b63b689 100644 --- a/question/type/shortanswer/questiontype.php +++ b/question/type/shortanswer/questiontype.php @@ -138,7 +138,7 @@ class question_shortanswer_qtype extends default_questiontype { $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course); - $image = get_question_image($question, $cmoptions->course); + $image = get_question_image($question); /// Print input controls diff --git a/question/type/truefalse/questiontype.php b/question/type/truefalse/questiontype.php index b436f7d211..ed485029c3 100644 --- a/question/type/truefalse/questiontype.php +++ b/question/type/truefalse/questiontype.php @@ -17,7 +17,7 @@ class question_truefalse_qtype extends default_questiontype { function save_question_options($question) { $result = new stdClass; - + // fetch old answer ids so that we can reuse them if (!$oldanswers = get_records("question_answers", "question", $question->id, "id ASC")) { $oldanswers = array(); @@ -143,7 +143,7 @@ class question_truefalse_qtype extends default_questiontype { global $CFG; $readonly = $options->readonly ? ' disabled="disabled"' : ''; - + $formatoptions = new stdClass; $formatoptions->noclean = true; $formatoptions->para = false; @@ -152,7 +152,7 @@ class question_truefalse_qtype extends default_questiontype { $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course); - $image = get_question_image($question, $cmoptions->course); + $image = get_question_image($question); $answers = &$question->options->answers; $trueanswer = &$answers[$question->options->trueanswer]; @@ -206,7 +206,7 @@ class question_truefalse_qtype extends default_questiontype { $chosenanswer = $answers[$response]; $feedback = format_text($chosenanswer->feedback, true, $formatoptions, $cmoptions->course); } - + include("$CFG->dirroot/question/type/truefalse/display.html"); } @@ -242,7 +242,7 @@ class question_truefalse_qtype extends default_questiontype { } return $responses; } - + /// BACKUP FUNCTIONS //////////////////////////// /*