MDL-15777 more fixes for portfolio to use file api
[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
d96a1acc 8 protected $file;
67a87e7d 9 protected $exportconfig;
10
67a87e7d 11 public static function allows_multiple() {
12 return false;
13 }
14
15 public function expected_time($callertime) {
16 return PORTFOLIO_TIME_LOW;
17 }
18
d67bfc32 19 public function prepare_package() {
67a87e7d 20
d96a1acc 21 $files = $this->exporter->get_tempfiles();
22 $zipper = new zip_packer();
67a87e7d 23
d96a1acc 24 $filename = 'portfolio-export.zip';
25 if ($newfile = $zipper->archive_to_storage($files, SYSCONTEXTID, 'portfolio_exporter', $this->exporter->get('id'), '/final/', $filename, $this->user->id)) {
26 $this->set('file', $newfile);
27 return true;
28 }
29 return false;
67a87e7d 30 }
31
32 public function send_package() {
33 return true;
34 }
35
36 public function get_extra_finish_options() {
37 global $CFG;
d96a1acc 38 return array($CFG->wwwroot . '/portfolio/file.php?id=' . $this->exporter->get('id') => get_string('downloadfile', 'portfolio_download'));
67a87e7d 39 }
40
d96a1acc 41 public function verify_file_request_params($params) {
42 // for download plugin the only thing we need to verify is that
43 // the logged in user is the same as the exporting user
44 global $USER;
45 if ($USER->id != $this->user->id) {
46 return false;
47 }
48 return true;
67a87e7d 49 }
d67bfc32 50
d96a1acc 51 public function get_continue_url() {
52 return false;
d67bfc32 53 }
67a87e7d 54}
55
56?>