? MDL-24034.patch
? config.php
? test.php
? mod/NEWMODULE
Index: mod/assignment/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/lib.php,v
retrieving revision 1.501
diff -u -r1.501 lib.php
--- mod/assignment/lib.php	14 Oct 2010 21:40:04 -0000	1.501
+++ mod/assignment/lib.php	15 Oct 2010 12:10:54 -0000
@@ -1861,6 +1861,8 @@
 
         $submission = $this->get_submission($userid);
 
+        $viewingown = ($userid == $USER->id);
+
         if (($submission) && $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) {
             require_once($CFG->libdir.'/portfoliolib.php');
             require_once($CFG->dirroot . '/mod/assignment/locallib.php');
@@ -1871,7 +1873,7 @@
                 $mimetype = $file->get_mimetype();
                 $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
                 $output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>';
-                if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
+                if ($viewingown && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
                     $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
                     $button->set_format_by_file($file);
                     $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
@@ -1879,7 +1881,7 @@
                 $output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment));
                 $output .= '<br />';
             }
-            if (count($files) > 1  && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
+            if ($viewingown && count($files) > 2  && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
                 $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
                 $output .= '<br />'  . $button->to_html();
             }
Index: mod/assignment/renderer.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/renderer.php,v
retrieving revision 1.9
diff -u -r1.9 renderer.php
--- mod/assignment/renderer.php	20 Sep 2010 07:32:31 -0000	1.9
+++ mod/assignment/renderer.php	15 Oct 2010 12:10:55 -0000
@@ -93,7 +93,7 @@
         $fs = get_file_storage();
         $this->dir = $fs->get_area_tree($this->context->id, 'mod_assignment', $filearea, $itemid);
         $files = $fs->get_area_files($this->context->id, 'mod_assignment', $filearea, $itemid, "timemodified", false);
-        if (count($files) >= 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
+        if ($itemid == $USER->id && count($files) >= 2 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
             $button = new portfolio_add_button();
             $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
             $button->reset_formats();
@@ -102,13 +102,13 @@
         $this->preprocess($this->dir, $filearea);
     }
     public function preprocess($dir, $filearea) {
-        global $CFG;
+        global $CFG, $USER;
         foreach ($dir['subdirs'] as $subdir) {
             $this->preprocess($subdir, $filearea);
         }
         foreach ($dir['files'] as $file) {
             $button = new portfolio_add_button();
-            if (has_capability('mod/assignment:exportownsubmission', $this->context)) {
+            if ($USER->id == $file->get_userid() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
                 $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
                 $button->set_format_by_file($file);
                 $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
Index: mod/assignment/type/online/assignment.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/type/online/assignment.class.php,v
retrieving revision 1.110
diff -u -r1.110 assignment.class.php
--- mod/assignment/type/online/assignment.class.php	30 Sep 2010 06:30:34 -0000	1.110
+++ mod/assignment/type/online/assignment.class.php	15 Oct 2010 12:10:55 -0000
@@ -101,7 +101,7 @@
                 if ($submission && has_capability('mod/assignment:exportownsubmission', $this->context)) {
                     $text = file_rewrite_pluginfile_urls($submission->data1, 'pluginfile.php', $this->context->id, 'mod_assignment', $this->filearea, $submission->id);
                     echo format_text($text, $submission->data2);
-                    if ($CFG->enableportfolios) {
+                    if ($CFG->enableportfolios && $this->portfolio_exportable()) {
                         require_once($CFG->libdir . '/portfoliolib.php');
                         $button = new portfolio_add_button();
                         $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
