From: Penny Leach Date: Sat, 12 Dec 2009 11:27:07 +0000 (+0000) Subject: portfolio MDL-21079 be more selective about including libraries. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=24ba58ee9a592043f682c42de388f657b327e2b1;p=moodle.git portfolio MDL-21079 be more selective about including libraries. this involves moving all formslib includes to where they're actually needed. it also moves the portfolio stuff from assignment,data,chat,forum and glossary into a locallib.php which involved creating it for many of those modules. --- diff --git a/admin/portfolio.php b/admin/portfolio.php index 23cc2a7d19..ea47d5038b 100644 --- a/admin/portfolio.php +++ b/admin/portfolio.php @@ -2,6 +2,7 @@ require_once(dirname(dirname(__FILE__)) . '/config.php'); require_once($CFG->libdir . '/portfoliolib.php'); +require_once($CFG->libdir . '/portfolio/forms.php'); require_once($CFG->libdir . '/adminlib.php'); $edit = optional_param('edit', 0, PARAM_INT); diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 5f2c29a769..880fa2e912 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -3152,12 +3152,15 @@ class settings_navigation extends navigation_node { } // Portfolio - if (empty($userindexpage) && $currentuser && !empty($CFG->enableportfolios) && has_capability('moodle/portfolio:export', $systemcontext) && portfolio_instances(true, false)) { - $portfoliokey = $usersetting->add(get_string('portfolios', 'portfolio'), null, self::TYPE_SETTING); - $url = new moodle_url($CFG->wwwroot .'/user/portfolio.php'); - $usersetting->get($portfoliokey)->add(get_string('configure', 'portfolio'), $url, self::TYPE_SETTING); - $url = new moodle_url($CFG->wwwroot .'/user/portfoliologs.php'); - $usersetting->get($portfoliokey)->add(get_string('logs', 'portfolio'), $url, self::TYPE_SETTING); + if (empty($userindexpage) && $currentuser && !empty($CFG->enableportfolios) && has_capability('moodle/portfolio:export', $systemcontext)) { + require_once($CFG->libdir . '/portfoliolib.php'); + if (portfolio_instances(true, false)) { + $portfoliokey = $usersetting->add(get_string('portfolios', 'portfolio'), null, self::TYPE_SETTING); + $url = new moodle_url($CFG->wwwroot .'/user/portfolio.php'); + $usersetting->get($portfoliokey)->add(get_string('configure', 'portfolio'), $url, self::TYPE_SETTING); + $url = new moodle_url($CFG->wwwroot .'/user/portfoliologs.php'); + $usersetting->get($portfoliokey)->add(get_string('logs', 'portfolio'), $url, self::TYPE_SETTING); + } } // Repository diff --git a/lib/portfolio/exporter.php b/lib/portfolio/exporter.php index 4934324e11..99c6b7c230 100644 --- a/lib/portfolio/exporter.php +++ b/lib/portfolio/exporter.php @@ -281,7 +281,7 @@ class portfolio_exporter { * @return boolean whether or not to process the next stage. this is important as the control function is called recursively. */ public function process_stage_config() { - global $OUTPUT; + global $OUTPUT, $CFG; $pluginobj = $callerobj = null; if ($this->instance->has_export_config()) { $pluginobj = $this->instance; @@ -306,6 +306,7 @@ class portfolio_exporter { 'formats' => $formats, 'expectedtime' => $expectedtime, ); + require_once($CFG->libdir . '/portfolio/forms.php'); $mform = new portfolio_export_form('', $customdata); if ($mform->is_cancelled()){ $this->cancel_request(); @@ -659,6 +660,9 @@ class 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 @@ -713,7 +717,7 @@ class portfolio_exporter { throw new portfolio_exception('notyours', 'portfolio'); } if (!$readonly && $this->get('instance') && !$this->get('instance')->allows_multiple_exports() - && ($already = portfolio_exporter::existing_exports($this->get('user')->id, $this->get('instance')->get('plugin'))) + && ($already = portfolio_existing_exports($this->get('user')->id, $this->get('instance')->get('plugin'))) && array_shift(array_keys($already)) != $this->get('id') ) { $a = (object)array( @@ -848,40 +852,6 @@ class portfolio_exporter { exit; } - /** - * return a list of current exports for the given user - * this will not go through and call rewaken_object, because it's heavy - * it's really just used to figure out what exports are currently happening. - * this is useful for plugins that don't support multiple exports per session - * - * @param int $userid the user to check for - * @param string $type (optional) the portfolio plugin to filter by - * - * @return array - */ - public static function existing_exports($userid, $type=null) { - global $DB; - $sql = 'SELECT t.*,t.instance,i.plugin,i.name FROM {portfolio_tempdata} t JOIN {portfolio_instance} i ON t.instance = i.id WHERE t.userid = ? '; - $values = array($userid); - if ($type) { - $sql .= ' AND i.plugin = ?'; - $values[] = $type; - } - return $DB->get_records_sql($sql, $values); - } - - /** - * Return an array of existing exports by type for a given user. - * This is much more lightweight than {@see existing_exports} because it only returns the types, rather than the whole serialised data - * so can be used for checking availability of multiple plugins at the same time. - */ - public static function existing_exports_by_plugin($userid) { - global $DB; - $sql = 'SELECT t.id,i.plugin FROM {portfolio_tempdata} t JOIN {portfolio_instance} i ON t.instance = i.id WHERE t.userid = ? '; - $values = array($userid); - return $DB->get_records_sql_menu($sql, $values); - } - public static function print_cleaned_export($log, $instance=null) { global $CFG, $OUTPUT, $PAGE; if (empty($instance) || !$instance instanceof portfolio_plugin) { diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index 352bc72e14..44f961678c 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -29,14 +29,25 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** require all the sublibraries first. */ -require_once($CFG->libdir . '/portfolio/constants.php'); // all the constants for time, export format etc. +// require some of the sublibraries first. +// this is not an exhaustive list, the others are pulled in as they're needed +// so we don't have to always include everything unnecessarily for performance + +// very lightweight list of constants. always needed and no further dependencies +require_once($CFG->libdir . '/portfolio/constants.php'); +// a couple of exception deinitions. always needed and no further dependencies require_once($CFG->libdir . '/portfolio/exceptions.php'); // exception classes used by portfolio code -require_once($CFG->libdir . '/portfolio/formats.php'); // the export format hierarchy -require_once($CFG->libdir . '/portfolio/forms.php'); // the form classes that subclass moodleform -require_once($CFG->libdir . '/portfolio/exporter.php'); // the exporter class -require_once($CFG->libdir . '/portfolio/plugin.php'); // the base classes for plugins -require_once($CFG->libdir . '/portfolio/caller.php'); // the base classes for calling code +// The base class for the caller classes. We always need this because we're either drawing a button, +// in which case the button needs to know the calling class definition, which requires the base class, +// or we're exporting, in which case we need the caller class anyway. +require_once($CFG->libdir . '/portfolio/caller.php'); + +// the other dependencies are included on demand: +// libdir/portfolio/formats.php - the classes for the export formats +// libdir/portfolio/forms.php - all portfolio form classes (requires formslib) +// libdir/portfolio/plugin.php - the base class for the export plugins +// libdir/portfolio/exporter.php - the exporter class + /** * use this to add a portfolio button or icon or form to a page @@ -127,6 +138,7 @@ class portfolio_add_button { throw new portfolio_button_exception('nocallbackfile', 'portfolio', $file); } $this->callbackfile = $file; + require_once($CFG->libdir . '/portfolio/caller.php'); // require the base class first require_once($CFG->dirroot . $file); if (!class_exists($class)) { throw new portfolio_button_exception('nocallbackclass', 'portfolio', $class); @@ -263,7 +275,7 @@ class portfolio_add_button { debugging(get_string('instancemisconfigured', 'portfolio', get_string($error[$instance->get('id')], 'portfolio_' . $instance->get('plugin')))); return; } - if (!$instance->allows_multiple_exports() && $already = portfolio_exporter::existing_exports($USER->id, $instance->get('plugin'))) { + if (!$instance->allows_multiple_exports() && $already = portfolio_existing_exports($USER->id, $instance->get('plugin'))) { debugging(get_string('singleinstancenomultiallowed', 'portfolio')); return; } @@ -390,7 +402,7 @@ function portfolio_instance_select($instances, $callerformats, $callbackclass, $ $count = 0; $selectoutput = "\n" . '