]> git.mjollnir.org Git - moodle.git/commitdiff
fix for MDL-11106 Images not showing up in shared categories
authorjamiesensei <jamiesensei>
Tue, 4 Sep 2007 11:55:10 +0000 (11:55 +0000)
committerjamiesensei <jamiesensei>
Tue, 4 Sep 2007 11:55:10 +0000 (11:55 +0000)
lib/questionlib.php
question/type/description/questiontype.php
question/type/essay/questiontype.php
question/type/match/questiontype.php
question/type/missingtype/questiontype.php
question/type/multianswer/questiontype.php
question/type/multichoice/questiontype.php
question/type/shortanswer/questiontype.php
question/type/truefalse/questiontype.php

index 68707d3da5d852f32818a8a111afc98917975008..9f76f8827d1a82fb9099572f0cc9966ff4a9578e 100644 (file)
@@ -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;
index f8042ecba324a63c27d69fce448c17999ddbc267..8fb0894ec07c39d8c173ad86377c6b87bf62d223 100644 (file)
@@ -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";
     }
index 7f22bf89ed37f8c04d670a66480260c1acdd4b1c..de2ac011550f7f0bd249980964d67b4f93651f45 100644 (file)
@@ -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 ////
 
 //////////////////////////////////////////////////////////////////////////
index 013215f3bb76976941b4da96fa0eaf15c327dcaf..f300c45658493058824246bfe610b1594622dd30 100644 (file)
@@ -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) {
index 9b9b8efc1b8e09fbb4cce0080e61a1ddd297bd82..1bbdcf6d41ae0a268d4eab82afb30b67ff0cec56 100644 (file)
@@ -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();
index 51697a18753b3de7a10f6d185fb88d0c4eb9feeb..fa6c8be0c87ac4bef254568ba9b3bc3f361cbe89 100644 (file)
@@ -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('<img class="qimage" src="' . $image . '" alt="" /><br />');
         }
-        
+
         $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 ////////////////////////////
 
     /*
index 744816c6a7ecf90d6791d04f62ca91d2293f2012..ddd3622b3863d61bbc1280aa56df10bc46b333a5 100644 (file)
@@ -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');
 
index a303eb3b81c5e26d5e4491ddbe87530c41d1807d..797b63b689076e94a2a9acb3e1cb225cdbcab739 100644 (file)
@@ -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
 
index b436f7d211b90222b2e386f2204315d7c33e308a..ed485029c36d55d565de708d80ebb00fa02cc78c 100644 (file)
@@ -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 ////////////////////////////
 
     /*