Merge branch 'MDL-37030-master' of git://github.com/damyon/moodle
authorSam Hemelryk <sam@moodle.com>
Mon, 14 Jan 2013 21:37:54 +0000 (10:37 +1300)
committerSam Hemelryk <sam@moodle.com>
Mon, 14 Jan 2013 21:37:54 +0000 (10:37 +1300)
Conflicts:
mod/assign/locallib.php
mod/assign/submission/onlinetext/locallib.php

1  2 
mod/assign/assignmentplugin.php
mod/assign/feedback/file/importziplib.php
mod/assign/locallib.php
mod/assign/submission/file/locallib.php
mod/assign/submission/onlinetext/locallib.php

Simple merge
@@@ -1940,8 -1879,41 +1940,41 @@@ class assign 
          return $o;
      }
  
+     /**
+      * Rewrite plugin file urls so they resolve correctly in an exported zip.
+      *
+      * @param stdClass $user - The user record
+      * @param assign_plugin $plugin - The assignment plugin
+      */
+     public function download_rewrite_pluginfile_urls($text, $user, $plugin) {
+         $groupmode = groups_get_activity_groupmode($this->get_course_module());
+         $groupname = '';
+         if ($groupmode) {
+             $groupid = groups_get_activity_group($this->get_course_module(), true);
+             $groupname = groups_get_group_name($groupid).'-';
+         }
+         if ($this->is_blind_marking()) {
+             $prefix = $groupname . get_string('participant', 'assign');
+             $prefix = str_replace('_', ' ', $prefix);
+             $prefix = clean_filename($prefix . '_' . $this->get_uniqueid_for_user($user->id) . '_');
+         } else {
+             $prefix = $groupname . fullname($user);
+             $prefix = str_replace('_', ' ', $prefix);
+             $prefix = clean_filename($prefix . '_' . $this->get_uniqueid_for_user($user->id) . '_');
+         }
+         $subtype = $plugin->get_subtype();
+         $type = $plugin->get_type();
+         $prefix = $prefix . $subtype . '_' . $type . '_';
+         $result = str_replace('@@PLUGINFILE@@/', $prefix, $text);
+         return $result;
+     }
      /**
 -     * render the content in editor that is often used by plugin
 +     * Render the content in editor that is often used by plugin.
       *
       * @param string $filearea
       * @param int  $submissionid
@@@ -274,44 -252,21 +274,27 @@@ class assign_submission_onlinetext exte
      }
  
      /**
 -     * Produce a list of files suitable for export that represent this submission
 +     * Produce a list of files suitable for export that represent this submission.
       *
       * @param stdClass $submission - For this is the submission data
+      * @param stdClass $user - This is the user record for this submission
       * @return array - return an array of files indexed by filename
       */
-     public function get_files(stdClass $submission) {
+     public function get_files(stdClass $submission, stdClass $user) {
          global $DB;
 +
          $files = array();
          $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
 +
          if ($onlinetextsubmission) {
-             $user = $DB->get_record('user',
-                                     array('id'=>$submission->userid),
-                                     'id,username,firstname,lastname',
-                                      MUST_EXIST);
-             if (!$this->assignment->is_blind_marking()) {
-                 $filename = str_replace('_', '', fullname($user)) . '_' .
-                             $this->assignment->get_uniqueid_for_user($submission->userid) . '_' .
-                             $this->get_name() . '_';
-                 $prefix = clean_filename($filename);
-             } else {
-                 $filename = get_string('participant', 'assign') . '_' .
-                             $this->assignment->get_uniqueid_for_user($submission->userid) . '_' .
-                             $this->get_name() . '_';
-                 $prefix = clean_filename($filename);
-             }
-             $finaltext = str_replace('@@PLUGINFILE@@/', $prefix, $onlinetextsubmission->onlinetext);
+             $finaltext = $this->assignment->download_rewrite_pluginfile_urls($onlinetextsubmission->onlinetext, $user, $this);
 -            $submissioncontent = "<html><body>". format_text($finaltext, $onlinetextsubmission->onlineformat, array('context'=>$this->assignment->get_context())). "</body></html>";
 +            $formattedtext = format_text($finaltext,
 +                                         $onlinetextsubmission->onlineformat,
 +                                         array('context'=>$this->assignment->get_context()));
 +            $submissioncontent = '<html><body>'. $formattedtext . '</body></html>';
  
 -            $files[get_string('onlinetextfilename', 'assignsubmission_onlinetext')] = array($submissioncontent);
 +            $filename = get_string('onlinetextfilename', 'assignsubmission_onlinetext');
 +            $files[$filename] = array($submissioncontent);
  
              $fs = get_file_storage();