From: mjollnir_ Date: Tue, 16 Sep 2008 10:41:17 +0000 (+0000) Subject: MDL-16520 - make the already exporting portfolio error more user friendly X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a4763136395853dbcdb113a98a29f0bb2e001951;p=moodle.git MDL-16520 - make the already exporting portfolio error more user friendly --- diff --git a/lang/en_utf8/portfolio.php b/lang/en_utf8/portfolio.php index d7935ffed9..f1e5adfa3e 100644 --- a/lang/en_utf8/portfolio.php +++ b/lang/en_utf8/portfolio.php @@ -1,10 +1,13 @@ finish\">complete that first, or cancel\">click here to cancel it.'; +$string['activeexport'] = 'Resolve active export'; +$string['alreadyexporting'] = 'You already have an active portfolio export in this session. Before continuing, you must either complete this export, or cancel it. Would you like to continue it? (No will cancel it)'; $string['availableformats'] = 'Available export formats'; $string['callercouldnotpackage'] = 'Failed to package up your data for export: original error was $a'; $string['cannotsetvisible'] = 'Cannot set this to visible - the plugin has been completely disabled because of a misconfiguration'; diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index b57c375d88..6b612ba85b 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -56,6 +56,7 @@ require_once($CFG->libdir . '/portfolio/caller.php'); // the base classes f */ class portfolio_add_button { + private $alreadyexporting; private $callbackclass; private $callbackargs; private $callbackfile; @@ -77,10 +78,8 @@ class portfolio_add_button { public function __construct($options=null) { global $SESSION, $CFG; if (isset($SESSION->portfolioexport)) { - $a = new StdClass; - $a->cancel = $CFG->wwwroot . '/portfolio/add.php?cancel=1'; - $a->finish = $CFG->wwwroot . '/portfolio/add.php?id=' . $SESSION->portfolioexport; - throw new portfolio_button_exception('alreadyexporting', 'portfolio', null, $a); + $this->alreadyexporting = true; + return; } $this->instances = portfolio_instances(); if (empty($options)) { @@ -108,6 +107,9 @@ class portfolio_add_button { * this path should be relative (ie, not include) dirroot, eg '/mod/forum/lib.php' */ public function set_callback_options($class, array $argarray, $file=null) { + if ($this->alreadyexporting) { + return; + } global $CFG; if (empty($file)) { $backtrace = debug_backtrace(); @@ -147,6 +149,9 @@ class portfolio_add_button { * {@see portfolio_format_from_file} for how to get the appropriate formats to pass here for uploaded files. */ public function set_formats($formats=null) { + if ($this->alreadyexporting) { + return; + } if (is_string($formats)) { $formats = array($formats); } @@ -183,6 +188,9 @@ class portfolio_add_button { * this is whole string, not key. optional, defaults to 'Add to portfolio'; */ public function to_html($format=null, $addstr=null) { + if ($this->alreadyexporting) { + return $this->already_exporting($format); + } global $CFG, $COURSE; if (!$this->is_renderable()) { return; @@ -314,6 +322,30 @@ class portfolio_add_button { public function get_callbackclass() { return $this->callbackclass; } + + private function already_exporting($format) { + global $CFG; + $url = $CFG->wwwroot . '/portfolio/already.php'; + $icon = $CFG->pixpath . '/t/portfoliono.gif'; + $alt = get_string('alreadyalt', 'portfolio'); + $text = get_string('alreadytext', 'portfolio'); + if (empty($format)) { + $format = PORTFOLIO_ADD_FULL_FORM; + } + switch ($format) { + case PORTFOLIO_ADD_FULL_FORM: + return '
' . "\n" + . '' . "\n" + . '
'; + case PORTFOLIO_ADD_ICON_FORM: + case PORTFOLIO_ADD_ICON_LINK: + return '' . $alt . ''; + case PORTFOLIO_ADD_TEXT_LINK: + return '' . $text . ''; + default: + debugging(get_string('invalidaddformat', 'portfolio', $format)); + } + } } /** diff --git a/pix/t/portfoliono.gif b/pix/t/portfoliono.gif new file mode 100644 index 0000000000..2159f815f6 Binary files /dev/null and b/pix/t/portfoliono.gif differ diff --git a/portfolio/already.php b/portfolio/already.php new file mode 100644 index 0000000000..4bbf4c4bd4 --- /dev/null +++ b/portfolio/already.php @@ -0,0 +1,15 @@ +enableportfolios)) { + print_error('disabled', 'portfolio'); +} + +$strheading = get_string('activeexport', 'portfolio'); +print_header($strheading, $strheading); + +notice_yesno(get_string('alreadyexporting', 'portfolio'), $CFG->wwwroot . '/portfolio/add.php', $CFG->wwwroot . '/portfolio/add.php?cancel=1'); + +print_footer(); + +?>