From a4763136395853dbcdb113a98a29f0bb2e001951 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Tue, 16 Sep 2008 10:41:17 +0000 Subject: [PATCH] MDL-16520 - make the already exporting portfolio error more user friendly --- lang/en_utf8/portfolio.php | 5 ++++- lib/portfoliolib.php | 40 +++++++++++++++++++++++++++++++++---- pix/t/portfoliono.gif | Bin 0 -> 618 bytes portfolio/already.php | 15 ++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 pix/t/portfoliono.gif create mode 100644 portfolio/already.php 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 0000000000000000000000000000000000000000..2159f815f6ff2029ca56d2f96d4d1c35da9767b0 GIT binary patch literal 618 zcmZ?wbhEHb6krfwI9ATUz#zoHD#ySk&%mL`z@fyzt;)co#=xV&zz0N{EFy+X5=#8i z(t*CwFYFTlYmDBn3a-yyV2KZ_wEEjO}2J2bO3 zwx~I_s3)noKe@PHV+w=DGzQIS44%Clp8cGumD4jTr}#|Z_MF0CI+r1AvP9?$B(9|Hlm!f3h%gG1N2Y0Am6eBLWNz?8h7Go0?l%n?)65 z)VsUoH8dHUnY9em^9yIBDqDDRH8ZIhs^=CI7Z>=eSk7x&V5FXwo{^cA<*v@t%%UbH z79SfG6_=Qt!{5xdM=T;xRyHU)A)Bw6Lrqd5OxD~?HYTM=pqW!mPFmK=$=OOasZ8jx zn!c=^i?NBTt!&^dbv7YSW`}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(); + +?> -- 2.39.5