From: Penny Leach Date: Fri, 18 Dec 2009 14:38:22 +0000 (+0000) Subject: portfolio/assignment MDL-21035 added updated & published fields to leap2a. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=df3466045c34db4107da3f1e21a1f3acebbf97be;p=moodle.git portfolio/assignment MDL-21035 added updated & published fields to leap2a. also fixed files support in online type --- diff --git a/mod/assignment/locallib.php b/mod/assignment/locallib.php index ec4f0135e6..7cb118ba9e 100644 --- a/mod/assignment/locallib.php +++ b/mod/assignment/locallib.php @@ -70,13 +70,16 @@ class assignment_portfolio_caller extends portfolio_module_caller_base { throw new portfolio_caller_exception('notexportable', 'portfolio', $this->get_return_url()); } + if (is_callable(array($this->assignment, 'portfolio_load_data'))) { + return $this->assignment->portfolio_load_data($this); + } $this->set_file_and_format_data($this->fileid, $this->assignment->context->id, 'assignment_submission', $this->user->id, 'timemodified', false); } public function prepare_package() { - global $CFG; + global $CFG, $DB; if (is_callable(array($this->assignment, 'portfolio_prepare_package'))) { - return $this->assignment->portfolio_prepare_package($this->exporter, $this->user->id); + return $this->assignment->portfolio_prepare_package($this->exporter, $this->user); } if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) { $leapwriter = $this->exporter->get('format')->leap2a_writer(); @@ -93,6 +96,9 @@ class assignment_portfolio_caller extends portfolio_module_caller_base { $id = $baseid . $file->get_id(); $entry = new portfolio_format_leap2a_entry($id, $file->get_filename(), 'resource', $file); $entry->add_category('offline', 'resource_type'); + $entry->published = $file->get_timecreated(); + $entry->updated = $file->get_timemodified(); + $entry->author = $this->user; $leapwriter->add_entry($entry); $this->exporter->copy_existing_file($file); } @@ -104,7 +110,7 @@ class assignment_portfolio_caller extends portfolio_module_caller_base { public function get_sha1() { global $CFG; if (is_callable(array($this->assignment, 'portfolio_get_sha1'))) { - return $this->assignment->portfolio_get_sha1($this->user->id); + return $this->assignment->portfolio_get_sha1($this); } return $this->get_sha1_file(); } diff --git a/mod/assignment/type/online/assignment.class.php b/mod/assignment/type/online/assignment.class.php index dc8b94327e..9a219fb145 100644 --- a/mod/assignment/type/online/assignment.class.php +++ b/mod/assignment/type/online/assignment.class.php @@ -110,7 +110,12 @@ class assignment_online extends assignment_base { echo format_text($text, $submission->data2); $button = new portfolio_add_button(); $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php'); - $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); //TODO this might have files? + $fs = get_file_storage(); + if ($files = $fs->get_area_files($this->context->id, 'assignment_online_submission', $submission->id, "timemodified", false)) { + $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); + } else { + $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); + } $button->render(); } else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604 echo '
'. get_string('guestnosubmit', 'assignment').'
'; @@ -279,25 +284,52 @@ class assignment_online extends assignment_base { return true; } - function portfolio_get_sha1($userid=0) { - $submission = $this->get_submission($userid); - return sha1(format_text($submission->data1, $submission->data2)); + function portfolio_load_data($caller) { + $submission = $this->get_submission(); + $fs = get_file_storage(); + if ($files = $fs->get_area_files($this->context->id, 'assignment_online_submission', $submission->id, "timemodified", false)) { + $caller->set('multifiles', $files); + } + } + + function portfolio_get_sha1($caller) { + $submission = $this->get_submission(); + $textsha1 = sha1(format_text($submission->data1, $submission->data2)); + $filesha1 = ''; + try { + $filesha1 = $caller->get_sha1_file(); + } catch (portfolio_caller_exception $e) {} // no files + return sha1($textsha1 . $filesha1); } - function portfolio_prepare_package($exporter, $userid=0) { - $submission = $this->get_submission($userid); + function portfolio_prepare_package($exporter, $user) { + $submission = $this->get_submission($user->id); $html = format_text($submission->data1, $submission->data2); - if ($exporter->get('formatclass') == PORTFOLIO_FORMAT_PLAINHTML) { - return $exporter->write_new_file($html, 'assignment.html', false); + $html = portfolio_rewrite_pluginfile_urls($html, $this->context->id, 'assignment_online_submission', $submission->id, $exporter->get('format')); + if (in_array($exporter->get('formatclass'), array(PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_RICHHTML))) { + if ($files = $exporter->get('caller')->get('multifiles')) { + foreach ($files as $f) { + $exporter->copy_existing_file($file); + } + } + return $exporter->write_new_file($html, 'assignment.html', !empty($files)); } else if ($exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) { $leapwriter = $exporter->get('format')->leap2a_writer(); - $entry = new portfolio_format_leap2a_entry('assignmentonline' . $this->assignment->id, $this->assignment->name, 'resource', $html); // TODO entry? + $entry = new portfolio_format_leap2a_entry('assignmentonline' . $this->assignment->id, $this->assignment->name, 'resource', $html); $entry->add_category('web', 'resource_type'); + $entry->published = $submission->timecreated; + $entry->updated = $submission->timemodified; + $entry->author = $user; $leapwriter->add_entry($entry); - return $exporter->write_new_file($leapwriter->to_xml(), $exporter->get('format')->manifest_name(), true); - //TODO attached files?! + if ($files = $exporter->get('caller')->get('multifiles')) { + foreach ($files as $f) { + $exporter->copy_existing_file($f); + $entry->add_attachment($f); + } + } + $exporter->write_new_file($leapwriter->to_xml(), $exporter->get('format')->manifest_name(), true); } else { - die('wtf ;' . $exporter->get('formatclass')); + debugging('invalid format class: ' . $exporter->get('formatclass')); } }