/** * Constructor. * * @param portfolio_exporter $exporter instance of portfolio_exporter (will handle null case) * @param string $errorcode language string key * @param string $module language string module (optional, defaults to moodle) * @param string $continue url to continue to (optional, defaults to wwwroot) * @param object $a language string data (optional, defaults to null) */ public function __construct($exporter, $errorcode, $module = null, $continue = null, $a = null) { global $CFG; // This static variable is necessary because sometimes the code below // which tries to obtain a continue link can cause one of these // exceptions to be thrown. This would create an infinite loop (until // PHP hits its stack limit). Using this static lets us make the // nested constructor finish immediately without attempting to call // methods that might fail. static $inconstructor = false; if (!$inconstructor && !empty($exporter) && $exporter instanceof portfolio_exporter) { $inconstructor = true; try { if (empty($continue)) { $caller = $exporter->get('caller'); if (!empty($caller) && $caller instanceof portfolio_caller_base) { $continue = $exporter->get('caller')->get_return_url(); } } // this was previously only called if we were in cron, // but I think if there's always an exception, we should clean up // rather than force the user to resolve the export later. $exporter->process_stage_cleanup(); } catch (Exception $e) { // Ooops, we had an exception trying to get caller // information. Ignore it. } $inconstructor = false; } parent::__construct($errorcode, $module, $continue, $a); }
$caller->set_formats_from_button($formats); } $caller->load_data(); // this must check capabilities and either throw an exception or return false. if (!$caller->check_permissions()) { throw new portfolio_caller_exception('nopermissions', 'portfolio', $caller->get_return_url()); } portfolio_export_pagesetup($PAGE, $caller); // this calls require_login($course) if it can.. // finally! set up the exporter object with the portfolio instance, and caller information elements $exporter = new portfolio_exporter($instance, $caller, $callbackcomponent); // set the export-specific variables, and save. $exporter->set('user', $USER); $exporter->save(); } if (!$exporter->get('instance')) { // we've just arrived but have no instance // in this case the exporter object and the caller object have been set up above // so just make a little form to select the portfolio plugin instance, // which is the last thing to do before starting the export. // // first check to make sure there is actually a point $options = portfolio_instance_select(portfolio_instances(), $exporter->get('caller')->supported_formats(), get_class($exporter->get('caller')), $exporter->get('caller')->get_mimetype(), 'instance', true, true); if (empty($options)) { throw new portfolio_export_exception($exporter, 'noavailableplugins', 'portfolio'); } else { if (count($options) == 1) { // no point displaying a form, just redirect. $optionskeys = array_keys($options); $instance = array_shift($optionskeys); redirect($CFG->wwwroot . '/portfolio/add.php?id= ' . $exporter->get('id') . '&instance=' . $instance . '&sesskey=' . sesskey());
} // set up the course so that build_navigation works nice $PAGE->set_course($course); // and now we know the course for sure, call require_login with it require_login($course); list($extranav, $cm) = $caller->get_navigation(); $extranav[] = array('type' => 'title', 'name' => get_string('exporting', 'portfolio')); $navigation = build_navigation($extranav, $cm); // finally! set up the exporter object with the portfolio instance, caller information, and navigation elements $exporter = new portfolio_exporter($instance, $caller, $callbackfile, $navigation); // set the export-specific variables, and save. $exporter->set('user', $USER); $exporter->set('sesskey', sesskey()); $exporter->save(); // and finally, put it in the session for waking up again later. $SESSION->portfolioexport = $exporter->get('id'); } if (!$exporter->get('instance')) { // we've just arrived but have no instance // in this case the exporter object and the caller object have been set up above // so just make a little form to select the portfolio plugin instance, // which is the last thing to do before starting the export. $mform = new portfolio_instance_select('', array('caller' => $exporter->get('caller'))); if ($mform->is_cancelled()) { $exporter->cancel_request(); } else { if ($fromform = $mform->get_data()) { redirect($CFG->wwwroot . '/portfolio/add.php?instance=' . $fromform->instance . '&id=' . $exporter->get('id')); exit; } else { $exporter->print_header('selectplugin');