Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  
   3  require_once($CFG->libdir . '/portfoliolib.php');
   4  require_once($CFG->libdir . '/portfolio/plugin.php');
   5  
   6  class portfolio_plugin_download extends portfolio_plugin_pull_base {
   7  
   8      protected $exportconfig;
   9  
  10      public static function get_name() {
  11          return get_string('pluginname', 'portfolio_download');
  12      }
  13  
  14      public static function allows_multiple_instances() {
  15          return false;
  16      }
  17  
  18      public function expected_time($callertime) {
  19          return PORTFOLIO_TIME_LOW;
  20      }
  21  
  22      public function prepare_package() {
  23  
  24          $files = $this->exporter->get_tempfiles();
  25  
  26          if (count($files) == 1) {
  27              $this->set('file', array_shift($files));
  28          } else {
  29              $this->set('file', $this->exporter->zip_tempfiles());  // this will throw a file_exception which the exporter catches separately.
  30          }
  31      }
  32  
  33      public function steal_control($stage) {
  34          if ($stage == PORTFOLIO_STAGE_FINISHED) {
  35              global $CFG;
  36              return $CFG->wwwroot . '/portfolio/download/file.php?id=' . $this->get('exporter')->get('id');
  37          }
  38      }
  39  
  40      public function send_package() {}
  41  
  42      public function verify_file_request_params($params) {
  43          // for download plugin the only thing we need to verify is that
  44          // the logged in user is the same as the exporting user
  45          global $USER;
  46          if ($USER->id  != $this->user->id) {
  47              return false;
  48          }
  49          return true;
  50      }
  51  
  52      public function get_interactive_continue_url() {
  53          return false;
  54      }
  55  }
  56