Exemple #1
0
 function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination)
 {
     global $CFG;
     $updateqrec = false;
     /// Question image
     if (!empty($question->image)) {
         //support for older questions where we have a complete url in image field
         if (substr(strtolower($question->image), 0, 7) == 'http://') {
             $questionimage = preg_replace('!^' . question_file_links_base_url($fromcourseid) . preg_quote($url, '!') . '$!i', $destination, $question->image, 1);
         } else {
             $questionimage = preg_replace('!^' . preg_quote($url, '!') . '$!i', $destination, $question->image, 1);
         }
         if ($questionimage != $question->image) {
             $question->image = $questionimage;
             $updateqrec = true;
         }
     }
     /// Questiontext and general feedback.
     $question->questiontext = question_replace_file_links_in_html($question->questiontext, $fromcourseid, $tocourseid, $url, $destination, $updateqrec);
     $question->generalfeedback = question_replace_file_links_in_html($question->generalfeedback, $fromcourseid, $tocourseid, $url, $destination, $updateqrec);
     /// If anything has changed, update it in the database.
     if ($updateqrec) {
         if (!update_record('question', addslashes_recursive($question))) {
             error('Couldn\'t update question ' . $question->name);
         }
     }
     /// Answers, if this question uses them.
     if (isset($question->options->answers)) {
         //answers that do not need updating have been unset
         foreach ($question->options->answers as $answer) {
             $answerchanged = false;
             /// URLs in the answers themselves, if appropriate.
             if ($this->has_html_answers()) {
                 $answer->answer = question_replace_file_links_in_html($answer->answer, $fromcourseid, $tocourseid, $url, $destination, $answerchanged);
             }
             /// URLs in the answer feedback.
             $answer->feedback = question_replace_file_links_in_html($answer->feedback, $fromcourseid, $tocourseid, $url, $destination, $answerchanged);
             /// If anything has changed, update it in the database.
             if ($answerchanged) {
                 if (!update_record('question_answers', addslashes_recursive($answer))) {
                     error('Couldn\'t update question (' . $question->name . ') answer ' . $answer->id);
                 }
             }
         }
     }
 }
 function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination)
 {
     parent::replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination);
     // replace links in the question_match_sub table.
     // We need to use a separate object, because in load_question_options, $question->options->answers
     // is changed from a comma-separated list of ids to an array, so calling update_record on
     // $question->options stores 'Array' in that column, breaking the question.
     $optionschanged = false;
     $newoptions = new stdClass();
     $newoptions->id = $question->options->id;
     $newoptions->correctfeedback = question_replace_file_links_in_html($question->options->correctfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
     $newoptions->partiallycorrectfeedback = question_replace_file_links_in_html($question->options->partiallycorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
     $newoptions->incorrectfeedback = question_replace_file_links_in_html($question->options->incorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
     if ($optionschanged) {
         if (!update_record('question_multichoice', addslashes_recursive($newoptions))) {
             error('Couldn\'t update \'question_multichoice\' record ' . $newoptions->id);
         }
     }
     $answerchanged = false;
     foreach ($question->options->answers as $answer) {
         $answer->answer = question_replace_file_links_in_html($answer->answer, $fromcourseid, $tocourseid, $url, $destination, $answerchanged);
         if ($answerchanged) {
             if (!update_record('question_answers', addslashes_recursive($answer))) {
                 error('Couldn\'t update \'question_answers\' record ' . $answer->id);
             }
         }
     }
 }
Exemple #3
0
 function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination)
 {
     global $DB;
     parent::replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination);
     // replace links in the question_match_sub table.
     if (isset($question->options->subquestions)) {
         foreach ($question->options->subquestions as $subquestion) {
             $subquestionchanged = false;
             $subquestion->questiontext = question_replace_file_links_in_html($subquestion->questiontext, $fromcourseid, $tocourseid, $url, $destination, $subquestionchanged);
             if ($subquestionchanged) {
                 //need to update rec in db
                 $DB->update_record('question_match_sub', $subquestion);
             }
         }
     }
 }
 function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination)
 {
     parent::replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination);
     // replace links in the question_match_sub table.
     if (isset($question->options->subquestions)) {
         foreach ($question->options->subquestions as $subquestion) {
             $subquestionchanged = false;
             $subquestion->questiontext = question_replace_file_links_in_html($subquestion->questiontext, $fromcourseid, $tocourseid, $url, $destination, $subquestionchanged);
             if ($subquestionchanged) {
                 //need to update rec in db
                 if (!update_record('question_match_sub', addslashes_recursive($subquestion))) {
                     error('Couldn\'t update \'question_match_sub\' record ' . $subquestion->id);
                 }
             }
         }
     }
 }
 function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination)
 {
     parent::replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination);
     // replace links in the question_match_sub table.
     $optionschanged = false;
     $question->options->correctfeedback = question_replace_file_links_in_html($question->options->correctfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
     $question->options->partiallycorrectfeedback = question_replace_file_links_in_html($question->options->partiallycorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
     $question->options->incorrectfeedback = question_replace_file_links_in_html($question->options->incorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
     if ($optionschanged) {
         if (!update_record('question_multichoice', addslashes_recursive($question->options))) {
             error('Couldn\'t update \'question_multichoice\' record ' . $question->options->id);
         }
     }
     $answerchanged = false;
     foreach ($question->options->answers as $answer) {
         $answer->answer = question_replace_file_links_in_html($answer->answer, $fromcourseid, $tocourseid, $url, $destination, $answerchanged);
         if ($answerchanged) {
             if (!update_record('question_answers', addslashes_recursive($answer))) {
                 error('Couldn\'t update \'question_answers\' record ' . $answer->id);
             }
         }
     }
 }
 function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination)
 {
     global $CFG;
     parent::replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination);
     $optionschanged = false;
     if (!empty($question->options->backgroundmedia->media)) {
         //support for older questions where we have a complete url in image field
         if (substr(strtolower($question->options->backgroundmedia->media), 0, 7) == 'http://') {
             $questionbackground = preg_replace('!^' . question_file_links_base_url($fromcourseid) . preg_quote($url, '!') . '$!i', $destination, $question->options->backgroundmedia->media, 1);
         } else {
             $questionbackground = preg_replace('!^' . preg_quote($url, '!') . '$!i', $destination, $question->options->backgroundmedia->media, 1);
         }
         if ($questionbackground != $question->options->backgroundmedia->media) {
             $question->options->backgroundmedia->media = $questionbackground;
             $optionschanged = true;
         }
     }
     $question->options->feedbackok = question_replace_file_links_in_html($question->options->feedbackok, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
     $question->options->feedbackmissed = question_replace_file_links_in_html($question->options->feedbackmissed, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
     if ($optionschanged) {
         if (!update_record('question_dragdrop', addslashes_recursive($question->options))) {
             error('Couldn\'t update \'question_dragdrop\' record ' . $question->options->id);
         }
     }
     $mediachanged = false;
     foreach ($question->options->media as $media) {
         if (!empty($media->media)) {
             if (substr(strtolower($media->media), 0, 7) == 'http://') {
                 $medianame = preg_replace('!^' . question_file_links_base_url($fromcourseid) . preg_quote($url, '!') . '$!i', $destination, $media->media, 1);
             } else {
                 $medianame = preg_replace('!^' . preg_quote($url, '!') . '$!i', $destination, $media->media, 1);
             }
             if ($medianame != $media->media) {
                 $media->media = $medianame;
                 $mediachanged = true;
             }
         }
         $media->questiontext = question_replace_file_links_in_html($media->questiontext, $fromcourseid, $tocourseid, $url, $destination, $mediachanged);
         if ($mediachanged) {
             if (!update_record('question_dragdrop_media', addslashes_recursive($media))) {
                 error('Couldn\'t update \'question_dragdrop_media\' record ' . $media->id);
             }
         }
     }
 }