From 7812e882b0ceed2277b6026034671b20b10c722e Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Tue, 19 Aug 2008 11:00:00 +0000 Subject: [PATCH] MDL-16124 - faux class structure for portfolio formats for better support for subtyping. --- lang/en_utf8/portfolio.php | 2 + lib/portfoliolib.php | 75 +++++++++++++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/lang/en_utf8/portfolio.php b/lang/en_utf8/portfolio.php index a7049b0cc8..b2b8553270 100644 --- a/lang/en_utf8/portfolio.php +++ b/lang/en_utf8/portfolio.php @@ -27,6 +27,8 @@ $string['failedtosendpackage'] = 'Failed to send your data to the selected portf $string['filedenied'] = 'Access denied to this file'; $string['filenotfound'] = 'File not found'; $string['format_file'] = 'File'; +$string['format_html'] = 'HTML'; +$string['format_image'] = 'Image'; $string['format_mbkp'] = 'Moodle Backup'; $string['hidden'] = 'Hidden'; $string['instancedeleted'] = 'Portfolio deleted successfully'; diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index 3da55544da..d722bb7dba 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -90,6 +90,17 @@ define('PORTFOLIO_FORMAT_FILE', 'file'); */ define('PORTFOLIO_FORMAT_MBKP', 'mbkp'); +/** +* html - subtype of file +*/ +define('PORTFOLIO_FORMAT_HTML', 'html'); + +/** +* image - subtype of file +*/ +define('PORTFOLIO_FORMAT_IMAGE', 'image'); + + // **** EXPORT TIME LEVELS **** // // these should correspond to a string @@ -375,12 +386,34 @@ function portfolio_instances($visibleonly=true, $useronly=true) { */ function portfolio_supported_formats() { return array( - PORTFOLIO_FORMAT_FILE, + PORTFOLIO_FORMAT_FILE => 'portfolio_format_file', /*PORTFOLIO_FORMAT_MBKP, */ // later /*PORTFOLIO_FORMAT_PIOP, */ // also later ); } +function portfolio_supported_formats_intersect($callerformats, $pluginformats) { + $allformats = portfolio_supported_formats(); + $intersection = array(); + foreach ($callerformats as $cf) { + if (!array_key_exists($cf, $allformats)) { + debugging(get_string('invalidformat', 'portfolio', $cf)); + continue; + } + foreach ($pluginformats as $p => $pf) { + if (!array_key_exists($pf, $allformats)) { + debugging(get_string('invalidformat', 'portfolio', $pf)); + unset($pluginformats[$p]); // to avoid the same warning over and over + continue; + } + if ($cf instanceof $pf) { + $intersection[] = $cf; + } + } + } + return $intersection; +} + /** * helper function to return an instance of a plugin (with config loaded) * @@ -1857,14 +1890,7 @@ final class portfolio_exporter { if ($this->caller->has_export_config()) { $callerobj = $this->caller; } - $formats = array_intersect($this->instance->supported_formats(), $this->caller->supported_formats()); - $allsupported = portfolio_supported_formats(); - foreach ($formats as $key => $format) { - if (!in_array($format, $allsupported)) { - debugging(get_string('invalidformat', 'portfolio', $format)); - unset($formats[$key]); - } - } + $formats = portfolio_supported_formats_intersect($this->caller->supported_formats(), $this->instance->supported_formats()); $expectedtime = $this->instance->expected_time($this->caller->expected_time()); if (count($formats) == 0) { // something went wrong, we should not have gotten this far. @@ -2308,5 +2334,36 @@ function portfolio_cron() { // @todo add hooks in the plugins } +/** +* this is just used to find an intersection of supported formats +* between the caller and portfolio plugins +* +* the most basic type - pretty much everything is a subtype +*/ +class portfolio_format_file {} + +/** +* this is just used to find an intersection of supported formats +* between the caller and portfolio plugins +* +* added for potential flickr plugin +*/ +class portfolio_format_image extends portfolio_format_file {} + +/** +* this is just used to find an intersection of supported formats +* between the caller and portfolio plugins +* +* in case we want to be really specific. +*/ +class portfolio_format_html extends portfolio_format_file {} + +/** +* this is just used to find an intersection of supported formats +* between the caller and portfolio plugins +* +* later.... a moodle plugin might support this. +*/ +class portfolio_format_mbkp extends portfolio_format_file {} ?> -- 2.39.5