/** * Rewakens the data from the database given the id. * Makes sure to load the required files with the class definitions * * @param int $id id of data * @return portfolio_exporter */ public static function rewaken_object($id) { global $DB, $CFG; require_once $CFG->libdir . '/filelib.php'; require_once $CFG->libdir . '/portfolio/exporter.php'; require_once $CFG->libdir . '/portfolio/caller.php'; require_once $CFG->libdir . '/portfolio/plugin.php'; if (!($data = $DB->get_record('portfolio_tempdata', array('id' => $id)))) { // maybe it's been finished already by a pull plugin // so look in the logs if ($log = $DB->get_record('portfolio_log', array('tempdataid' => $id))) { self::print_cleaned_export($log); } throw new portfolio_exception('invalidtempid', 'portfolio'); } $exporter = unserialize(base64_decode($data->data)); if ($exporter->instancefile) { require_once $CFG->dirroot . '/' . $exporter->instancefile; } if (!empty($exporter->callerfile)) { portfolio_include_callback_file($exporter->callerfile); } else { if (!empty($exporter->callercomponent)) { portfolio_include_callback_file($exporter->callercomponent); } else { return; // Should never get here! } } $exporter = unserialize(serialize($exporter)); if (!$exporter->get('id')) { // workaround for weird case // where the id doesn't get saved between a new insert // and the subsequent call that sets this field in the serialised data $exporter->set('id', $id); $exporter->save(); } return $exporter; }
/** * Function to set the callback options * * @param string $class Name of the class containing the callback functions * activity components should ALWAYS use their name_portfolio_caller * other locations must use something unique * @param array $argarray This can be an array or hash of arguments to pass * back to the callback functions (passed by reference) * these MUST be primatives to be added as hidden form fields. * and the values get cleaned to PARAM_ALPHAEXT or PARAM_FLOAT or PARAM_PATH * @param string $component This is the name of the component in Moodle, eg 'mod_forum' */ public function set_callback_options($class, array $argarray, $component) { global $CFG; // Require the base class first before any other files. require_once $CFG->libdir . '/portfolio/caller.php'; // Include any potential callback files and check for errors. portfolio_include_callback_file($component, $class); // This will throw exceptions but should not actually do anything other than verify callbackargs. $test = new $class($argarray); unset($test); $this->callbackcomponent = $component; $this->callbackclass = $class; $this->callbackargs = $argarray; }
// be as lenient as possible while still being secure // so only accept certain parameter types. $callbackargs = array(); foreach (array_keys(array_merge($_GET, $_POST)) as $key) { if (strpos($key, 'ca_') === 0) { if (!($value = optional_param($key, false, PARAM_ALPHAEXT))) { if (!($value = optional_param($key, false, PARAM_FLOAT))) { $value = optional_param($key, false, PARAM_PATH); } } // strip off ca_ for niceness $callbackargs[substr($key, 3)] = $value; } } // Ensure that we found a file we can use, if not throw an exception. portfolio_include_callback_file($callbackcomponent, $callbackclass); $caller = new $callbackclass($callbackargs); $caller->set('user', $USER); if ($formats = explode(',', $callerformats)) { $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.
echo $OUTPUT->heading(get_string('queuesummary', 'portfolio')); echo html_writer::table($table); $somethingprinted = true; } // Paging - get total count separately. $logcount = $DB->count_records('portfolio_log', array('userid' => $USER->id)); if ($logcount > 0) { $table = new html_table(); $table->head = array(get_string('plugin', 'portfolio'), get_string('displayarea', 'portfolio'), get_string('transfertime', 'portfolio')); $logs = $DB->get_records('portfolio_log', array('userid' => $USER->id), 'time DESC', '*', $page * $perpage, $perpage); foreach ($logs as $log) { if (!empty($log->caller_file)) { portfolio_include_callback_file($log->caller_file); } else { if (!empty($log->caller_component)) { portfolio_include_callback_file($log->caller_component); } else { // Errrmahgerrrd - this should never happen. Skipping. continue; } } $class = $log->caller_class; $pluginname = ''; try { $plugin = portfolio_instance($log->portfolio); $url = $plugin->resolve_static_continue_url($log->continueurl); if ($url) { $pluginname = '<a href="' . $url . '">' . $plugin->get('name') . '</a>'; } else { $pluginname = $plugin->get('name'); }
// be as lenient as possible while still being secure // so only accept certain parameter types. $callbackargs = array(); foreach (array_keys(array_merge($_GET, $_POST)) as $key) { if (strpos($key, 'ca_') === 0) { if (!($value = optional_param($key, false, PARAM_ALPHAEXT))) { if (!($value = optional_param($key, false, PARAM_NUMBER))) { $value = optional_param($key, false, PARAM_PATH); } } // strip off ca_ for niceness $callbackargs[substr($key, 3)] = $value; } } // Ensure that we found a file we can use, if not throw an exception. portfolio_include_callback_file($callbackfile, $callbackclass); $caller = new $callbackclass($callbackargs); $caller->set('user', $USER); if ($formats = explode(',', $callerformats)) { $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, $callbackfile); // set the export-specific variables, and save.