diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php
index 9683ba61539b8..c981d098f70fc 100644
--- a/lib/portfoliolib.php
+++ b/lib/portfoliolib.php
@@ -255,7 +255,7 @@ public function render($format=null, $addstr=null) {
*
* @param int $format format to display the button or form or icon or link.
* See constants PORTFOLIO_ADD_XXX for more info.
- * optional, defaults to PORTFOLI_ADD_FULL_FORM
+ * optional, defaults to PORTFOLIO_ADD_FULL_FORM
* @param str $addstr string to use for the button or icon alt text or link text.
* this is whole string, not key. optional, defaults to 'Add to portfolio';
*/
diff --git a/mod/assignment/lang/en/assignment.php b/mod/assignment/lang/en/assignment.php
index e9a90317d7820..bef1da47f3c7f 100644
--- a/mod/assignment/lang/en/assignment.php
+++ b/mod/assignment/lang/en/assignment.php
@@ -125,9 +125,11 @@
a zipped web site, or anything you ask them to submit.
';
$string['hideintro'] = 'Hide description before available date';
$string['hideintro_help'] = 'If enabled, the assignment description is hidden before the "Available from" date. Only the assignment name is displayed.';
-$string['invalidassignment'] = 'incorrect assignment';
-$string['invalidid'] = 'assignment ID was incorrect';
-$string['invalidtype'] = 'Incorrect assignment type';
+$string['invalidassignment'] = 'Invalid assignment';
+$string['invalidfileandsubmissionid'] = 'Missing file or submission ID';
+$string['invalidid'] = 'Invalid assignment ID';
+$string['invalidsubmissionid'] = 'Invalid submission ID';
+$string['invalidtype'] = 'Invalid assignment type';
$string['invaliduserid'] = 'Invalid user ID';
$string['itemstocount'] = 'Count';
$string['lastgrade'] = 'Last grade';
diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php
index d247b31561cda..f698054aca09a 100644
--- a/mod/assignment/lib.php
+++ b/mod/assignment/lib.php
@@ -1918,7 +1918,7 @@ function print_user_files($userid=0, $return=false) {
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
$output .= ''.s($filename).'';
if ($CFG->enableportfolios && $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_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $submission->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
$button->set_format_by_file($file);
$output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
@@ -1926,8 +1926,8 @@ function print_user_files($userid=0, $return=false) {
$output .= '
';
}
if ($CFG->enableportfolios && count($files) > 1 && $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 .= '
' . $button->to_html();
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $submission->id), '/mod/assignment/locallib.php');
+ $output .= '
' . $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
}
}
diff --git a/mod/assignment/locallib.php b/mod/assignment/locallib.php
index d6701bb582e15..e2c3761aea255 100644
--- a/mod/assignment/locallib.php
+++ b/mod/assignment/locallib.php
@@ -38,6 +38,9 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
*/
private $assignmentfile;
+ /** @var int callback arg - the id of submission we export */
+ protected $submissionid;
+
/**
* callback arg for a single file export
*/
@@ -45,11 +48,19 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
public static function expected_callbackargs() {
return array(
- 'id' => true,
- 'fileid' => false,
+ 'id' => true,
+ 'submissionid' => false,
+ 'fileid' => false,
);
}
+ /**
+ * Load data needed for the portfolio export
+ *
+ * If the assignment type implements portfolio_load_data(), the processing is delegated
+ * to it. Otherwise, the caller must provide either fileid (to export single file) or
+ * submissionid (to export all data attached to the given submission) via callback arguments.
+ */
public function load_data() {
global $DB, $CFG;
@@ -75,9 +86,23 @@ public function load_data() {
return $this->assignment->portfolio_load_data($this);
}
- $submission = $DB->get_record('assignment_submissions', array('assignment'=>$assignment->id, 'userid'=>$this->user->id));
+ if (empty($this->fileid)) {
+ if (empty($this->submissionid)) {
+ throw new portfolio_caller_exception('invalidfileandsubmissionid', 'mod_assignment');
+ }
+
+ if (! $submission = $DB->get_record('assignment_submissions', array('assignment'=>$assignment->id, 'id'=>$this->submissionid))) {
+ throw new portfolio_caller_exception('invalidsubmissionid', 'mod_assignment');
+ }
+
+ $submissionid = $submission->id;
+
+ } else {
+ // once we know the file id, we do not need the submission
+ $submissionid = null;
+ }
- $this->set_file_and_format_data($this->fileid, $this->assignment->context->id, 'mod_assignment', 'submission', $submission->id, 'timemodified', false);
+ $this->set_file_and_format_data($this->fileid, $this->assignment->context->id, 'mod_assignment', 'submission', $submissionid, 'timemodified', false);
}
public function prepare_package() {
diff --git a/mod/assignment/renderer.php b/mod/assignment/renderer.php
index 89d9b75a2a0f7..77eaf61efd518 100644
--- a/mod/assignment/renderer.php
+++ b/mod/assignment/renderer.php
@@ -96,9 +96,9 @@ public function __construct($context, $itemid, $filearea='submission') {
$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)) {
$button = new portfolio_add_button();
- $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $itemid), '/mod/assignment/locallib.php');
$button->reset_formats();
- $this->portfolioform = $button->to_html();
+ $this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
}
}
$this->preprocess($this->dir, $filearea);