From: mjollnir_ Date: Fri, 25 Jul 2008 15:17:23 +0000 (+0000) Subject: MDL-15830 & MDL-15832: added a new intermediate abstract caller class for modules... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5071079cb2d546d9079bec7f91189373501fec11;p=moodle.git MDL-15830 & MDL-15832: added a new intermediate abstract caller class for modules & removed PORTFOLIO_FORMAT_HTML --- diff --git a/lang/en_utf8/portfolio.php b/lang/en_utf8/portfolio.php index 64a38d735f..f4210cba63 100644 --- a/lang/en_utf8/portfolio.php +++ b/lang/en_utf8/portfolio.php @@ -17,7 +17,6 @@ $string['err_uniquename'] = 'Portfolio name must be unique (per plugin)'; $string['exporting'] = 'Exporting to portfolio'; $string['exportcomplete'] = 'Portfolio export complete!'; $string['failedtosendpackage'] = 'Failed to send your data to the selected portfolio system!'; -$string['format_html'] = 'HTML'; $string['format_file'] = 'File'; $string['format_mbkp'] = 'Moodle Backup'; $string['hidden'] = 'Hidden'; @@ -26,6 +25,7 @@ $string['instanceismisconfigured'] = 'Portfolio instance is misconfigured, skipp $string['instancenotsaved'] = 'Failed to save portfolio'; $string['instancenotdelete'] = 'Failed to delete portfolio'; $string['instancesaved'] = 'Portfolio saved successfully'; +$string['invalidformat'] = 'Something is exporting an invalid format, $a'; $string['manageportfolios'] = 'Manage portfolios'; $string['manageyourportfolios'] = 'Manage your portfolios'; $string['noavailableplugins'] = 'Sorry, but there are no available portfolios for you to export to'; diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index 3187319af6..1e99a1c02c 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -76,13 +76,6 @@ define('PORTFOLIO_STAGE_FINISHED', 7); // in the portfolio module, called format_{$value} // **** **** // -/** -* html - this is the second most basic fallback -* after {@link PORTFOLIO_FORMAT_FILE} -* for export. This should always be supported -* in remote systems -*/ -define('PORTFOLIO_FORMAT_HTML', 'html'); /** * file - the most basic fallback format. @@ -305,8 +298,8 @@ function portfolio_instances($visibleonly=true, $useronly=true) { function portfolio_supported_formats() { return array( PORTFOLIO_FORMAT_FILE, - PORTFOLIO_FORMAT_HTML, - PORTFOLIO_FORMAT_MBKP, + /*PORTFOLIO_FORMAT_MBKP, */ // later + /*PORTFOLIO_FORMAT_PIOP, */ // also later ); } @@ -719,6 +712,21 @@ abstract class portfolio_caller_base { public abstract function check_permissions(); } +abstract class portfolio_module_caller_base extends portfolio_caller_base { + + protected $cm; + + public function get_navigation() { + $extranav = array('name' => $this->cm->name, 'link' => $this->get_return_url()); + return array($extranav, $this->cm); + } + + public function get_return_url() { + global $CFG; + return $CFG->wwwroot . '/mod/' . $this->cm->modname . '/view.php?id=' . $this->cm->id; + } +} + /** * the base class for portfolio plguins * all plugins must subclass this. @@ -1673,6 +1681,13 @@ final class portfolio_exporter { $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]); + } + } $expectedtime = $this->instance->expected_time($this->caller->expected_time()); if (count($formats) == 0) { // something went wrong, we should not have gotten this far. diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index b0efd129fe..accfbd55c3 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -3115,7 +3115,7 @@ function assignment_get_extra_capabilities() { } require_once($CFG->libdir . '/portfoliolib.php'); -class assignment_portfolio_caller extends portfolio_caller_base { +class assignment_portfolio_caller extends portfolio_module_caller_base { private $assignment; private $assignmentfile; @@ -3125,7 +3125,7 @@ class assignment_portfolio_caller extends portfolio_caller_base { public function __construct($callbackargs) { global $DB, $CFG; - if (! $cm = get_coursemodule_from_id('assignment', $callbackargs['assignmentid'])) { + if (! $this->cm = get_coursemodule_from_id('assignment', $callbackargs['assignmentid'])) { print_error('invalidcoursemodule'); } @@ -3163,22 +3163,9 @@ class assignment_portfolio_caller extends portfolio_caller_base { } public static function supported_formats() { - // try and cheat - if (isset($this) && $this->assignment->assignment->assignmenttype == 'online') { - return array(PORTFOLIO_FORMAT_HTML); - } return array(PORTFOLIO_FORMAT_FILE); } - public function get_return_url() { - global $CFG; - return $CFG->wwwroot . '/mod/assignment/view.php?id=' . $this->assignment->cm->id; - } - - public function get_navigation() { - $extranav = array('name' => $this->assignment->cm->name, 'link' => $this->get_return_url()); - return array($extranav, $this->assignment->cm); - } public function expected_time() { return PORTFOLIO_TIME_MODERATE; // @TODO check uploaded file size diff --git a/mod/assignment/type/online/assignment.class.php b/mod/assignment/type/online/assignment.class.php index b5316370ac..bf06d21591 100644 --- a/mod/assignment/type/online/assignment.class.php +++ b/mod/assignment/type/online/assignment.class.php @@ -107,7 +107,7 @@ class assignment_online extends assignment_base { 'userid' => $USER->id, 'assignmentid' => $this->cm->id, ); - portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php')); + portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php'); } else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604 echo '
'. get_string('guestnosubmit', 'assignment').'
'; } else if ($this->isopen()){ //fix for #4206 diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 47b0732e2d..bf750673e7 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -6897,9 +6897,8 @@ function forum_get_extra_capabilities() { } require_once($CFG->libdir . '/portfoliolib.php'); -class forum_portfolio_caller extends portfolio_caller_base { +class forum_portfolio_caller extends portfolio_module_caller_base { - private $cm; private $post; private $forum; private $discussion; @@ -6960,8 +6959,6 @@ class forum_portfolio_caller extends portfolio_caller_base { } static function supported_formats() { - // we always have to support the possibility here that we have attachments - // and HTML is a subset of FILE anyway. return array(PORTFOLIO_FORMAT_FILE); } @@ -6975,10 +6972,6 @@ class forum_portfolio_caller extends portfolio_caller_base { return true; } - function get_navigation() { - $extranav = array('name' => $this->cm->name, 'link' => $this->get_return_url()); - return array($extranav, $this->cm); - } } ?> diff --git a/portfolio/type/boxnet/lib.php b/portfolio/type/boxnet/lib.php index e8c2a48db5..0b0a2fb5dd 100644 --- a/portfolio/type/boxnet/lib.php +++ b/portfolio/type/boxnet/lib.php @@ -11,7 +11,7 @@ class portfolio_plugin_boxnet extends portfolio_plugin_base { private $folders; public static function supported_formats() { - return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_HTML); + return array(PORTFOLIO_FORMAT_FILE); } public function prepare_package($tempdir) { diff --git a/portfolio/type/download/lib.php b/portfolio/type/download/lib.php index 7031857427..7775d75a64 100644 --- a/portfolio/type/download/lib.php +++ b/portfolio/type/download/lib.php @@ -8,7 +8,7 @@ class portfolio_plugin_download extends portfolio_plugin_base { protected $exportconfig; public static function supported_formats() { - return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_HTML); + return array(PORTFOLIO_FORMAT_FILE); // @todo more later, like moodle backup for example }