]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16520 - make the already exporting portfolio error more user friendly
authormjollnir_ <mjollnir_>
Tue, 16 Sep 2008 10:41:17 +0000 (10:41 +0000)
committermjollnir_ <mjollnir_>
Tue, 16 Sep 2008 10:41:17 +0000 (10:41 +0000)
lang/en_utf8/portfolio.php
lib/portfoliolib.php
pix/t/portfoliono.gif [new file with mode: 0644]
portfolio/already.php [new file with mode: 0644]

index d7935ffed9eb99913aeeefc6803873997399539b..f1e5adfa3eaad1205ac3ea2e634c3163aebdd32e 100644 (file)
@@ -1,10 +1,13 @@
 <?php
 
 $string['activeportfolios'] = 'Active portfolios';
+$string['alreadyalt'] = 'Already exporting - please click here to resolve this transfer';
+$string['alreadytext'] = 'Add to portfolio - needs attention';
 $string['addnewportfolio'] = 'Add a new portfolio';
 $string['addtoportfolio'] = 'Add to portfolio';
 $string['addalltoportfolio'] = 'Add all to portfolio';
-$string['alreadyexporting'] = 'You already have an active portfolio export in this session. Please <a href=\"$a->finish\">complete that first</a>, or <a href=\"$a->cancel\">click here</a> 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';
index b57c375d8863ffe32df2e1808dc9cd0749db00ce..6b612ba85bffd4fd516c7c151a67598afe5b5fd9 100644 (file)
@@ -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 '<form action="' . $url . '">' . "\n"
+                    . '<input type="submit" value="' . $text . '" />' . "\n"
+                    . ' </form>';
+            case PORTFOLIO_ADD_ICON_FORM:
+            case PORTFOLIO_ADD_ICON_LINK:
+                return '<a href="' . $url . '"><img src="' . $icon . '" alt="' . $alt . '" /></a>';
+            case PORTFOLIO_ADD_TEXT_LINK:
+                return '<a href="' . $url . '">' . $text . '</a>';
+            default:
+                debugging(get_string('invalidaddformat', 'portfolio', $format));
+        }
+    }
 }
 
 /**
diff --git a/pix/t/portfoliono.gif b/pix/t/portfoliono.gif
new file mode 100644 (file)
index 0000000..2159f81
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 (file)
index 0000000..4bbf4c4
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+require_once(dirname(dirname(__FILE__)) . '/config.php');
+
+if (empty($CFG->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();
+
+?>