* @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;
}
$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";
}
function name() {
return 'essay';
}
-
+
function is_manual_graded() {
return true;
}
$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 = '';
$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 {
$answer = format_text($value, FORMAT_MOODLE,
$safeformatoptions, $cmoptions->course);
}
-
+
include("$CFG->dirroot/question/type/essay/display.html");
if ($usehtmleditor) {
// All grading takes place in Manual Grading
clean_param($state->responses[''], PARAM_CLEANHTML);
-
+
$state->raw_grade = 0;
$state->penalty = 0;
/**
* 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.
}
// Restore method not needed.
-}
+}
//// END OF CLASS ////
//////////////////////////////////////////////////////////////////////////
// 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) {
$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();
// 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?
}
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();
}
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"';
$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)) {
"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);
}
return $responses;
}
-
+
/// BACKUP FUNCTIONS ////////////////////////////
/*
$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');
$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
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();
global $CFG;
$readonly = $options->readonly ? ' disabled="disabled"' : '';
-
+
$formatoptions = new stdClass;
$formatoptions->noclean = true;
$formatoptions->para = false;
$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];
$chosenanswer = $answers[$response];
$feedback = format_text($chosenanswer->feedback, true, $formatoptions, $cmoptions->course);
}
-
+
include("$CFG->dirroot/question/type/truefalse/display.html");
}
}
return $responses;
}
-
+
/// BACKUP FUNCTIONS ////////////////////////////
/*