MDL-14591 - add get_base_file_url for pull portfolio plugins to use
[moodle.git] / portfolio / type / download / lib.php
CommitLineData
67a87e7d 1<?php
2
3require_once($CFG->libdir . '/portfoliolib.php');
d96a1acc 4require_once($CFG->libdir . '/packer/zip_packer.php');
67a87e7d 5
d96a1acc 6class portfolio_plugin_download extends portfolio_plugin_pull_base {
67a87e7d 7
67a87e7d 8 protected $exportconfig;
9
0f71f48b 10 public static function get_name() {
11 return get_string('pluginname', 'portfolio_download');
12 }
13
67a87e7d 14 public static function allows_multiple() {
15 return false;
16 }
17
18 public function expected_time($callertime) {
19 return PORTFOLIO_TIME_LOW;
20 }
21
d67bfc32 22 public function prepare_package() {
67a87e7d 23
d96a1acc 24 $files = $this->exporter->get_tempfiles();
25 $zipper = new zip_packer();
67a87e7d 26
d96a1acc 27 $filename = 'portfolio-export.zip';
0a154154 28 list ($contextid, $filearea, $itemid) = array_values($this->get('exporter')->get_base_filearea());
87fcac8d 29 if ($newfile = $zipper->archive_to_storage($files, $contextid, $filearea, $itemid, '/final/', $filename, $this->user->id)) {
d96a1acc 30 $this->set('file', $newfile);
31 return true;
32 }
33 return false;
67a87e7d 34 }
35
36 public function send_package() {
37 return true;
38 }
39
40 public function get_extra_finish_options() {
41 global $CFG;
d96a1acc 42 return array($CFG->wwwroot . '/portfolio/file.php?id=' . $this->exporter->get('id') => get_string('downloadfile', 'portfolio_download'));
67a87e7d 43 }
44
d96a1acc 45 public function verify_file_request_params($params) {
46 // for download plugin the only thing we need to verify is that
47 // the logged in user is the same as the exporting user
48 global $USER;
49 if ($USER->id != $this->user->id) {
50 return false;
51 }
52 return true;
67a87e7d 53 }
d67bfc32 54
d96a1acc 55 public function get_continue_url() {
56 return false;
d67bfc32 57 }
67a87e7d 58}
59
60?>