]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14591 portfolio: small fixes and improvements.
authormjollnir_ <mjollnir_>
Mon, 4 Aug 2008 16:07:37 +0000 (16:07 +0000)
committermjollnir_ <mjollnir_>
Mon, 4 Aug 2008 16:07:37 +0000 (16:07 +0000)
lib/portfoliolib.php
portfolio/add.php

index b65596f34a5f03d8cce8e07ed469feca52763cfb..771af1d56562cbd6984dc5dd236c199974cfbbc8 100644 (file)
@@ -148,6 +148,12 @@ function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null,
         return;
     }
 
+    if (!empty($SESSION->portfoliointernal)) {
+        // something somewhere has detected a risk of this being called during inside the preparation
+        // eg forum_print_attachments
+        return;
+    }
+
     if (empty($callbackfile)) {
         $backtrace = debug_backtrace();
         if (!array_key_exists(0, $backtrace) || !array_key_exists('file', $backtrace[0]) || !is_readable($backtrace[0]['file'])) {
@@ -2010,7 +2016,7 @@ final class portfolio_exporter {
     * error handler - decides whether we're running interactively or not
     * and behaves accordingly
     */
-    public static function raise_error($string, $module, $continue=null) {
+    public static function raise_error($string, $module='moodle', $continue=null) {
         if (defined('FULLME') && FULLME == 'cron') {
             debugging(get_string($string, $module));
             return false;
@@ -2021,6 +2027,29 @@ final class portfolio_exporter {
     }
 }
 
+class portfolio_instance_select extends moodleform {
+
+    private $caller;
+
+    function definition() {
+        $this->caller = $this->_customdata['caller'];
+        $options = portfolio_instance_select(
+            portfolio_instances(),
+            $this->caller->supported_formats(),
+            get_class($this->caller),
+            'instance',
+            true,
+            true
+        );
+        if (empty($options)) {
+            portfolio_exporter::raise_error('noavailableplugins', 'portfolio');
+        }
+        $mform =& $this->_form;
+        $mform->addElement('select', 'instance', get_string('selectplugin', 'portfolio'), $options);
+        $this->add_action_buttons(true, get_string('next'));
+    }
+}
+
 /**
 * event handler for the portfolio_send event
 */
index 6aba09dbea48a3ad6053e80d945ba499462fc61a..91026ae1a36366db3a2018c6f9933620649835d8 100644 (file)
@@ -6,7 +6,7 @@ if (empty($CFG->portfolioenabled)) {
 }
 
 require_once($CFG->libdir . '/portfoliolib.php');
-
+require_once($CFG->libdir . '/formslib.php');
 $exporter = null;
 if (isset($SESSION->portfolio) && isset($SESSION->portfolio->exporter)) {
     $exporter = unserialize(serialize($SESSION->portfolio->exporter));
@@ -16,22 +16,23 @@ if (isset($SESSION->portfolio) && isset($SESSION->portfolio->exporter)) {
     require_once($CFG->dirroot . '/' . $exporter->callerfile);
     $exporter = unserialize(serialize($SESSION->portfolio->exporter));
     $SESSION->portfolio->exporter =& $exporter;
-    if (!$exporter->get('instance')) {
-        $instance = required_param('instance', PARAM_INT);
-        if (!$instance = portfolio_instance($instance)) {
-            $exporter->raise_error('invalidinstance', 'portfolio');
-        }
-        if ($broken = portfolio_instance_sanity_check($instance)) {
-            print_error(get_string($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin')));
-        }
-        $instance->set('user', $USER);
-        $exporter->set('instance', $instance);
-    }
-    if ($cancel = optional_param('cancel', 0, PARAM_INT)) {
+    if ($cancel = optional_param('cancel', 0, PARAM_RAW)) {
         $returnurl = $exporter->get('caller')->get_return_url();
         unset($SESSION->portfolio);
         redirect($returnurl);
     }
+    if (!$exporter->get('instance')) {
+        if ($instance = optional_param('instance', '', PARAM_INT)) {
+            if (!$instance = portfolio_instance($instance)) {
+                $exporter->raise_error('invalidinstance', 'portfolio');
+            }
+            if ($broken = portfolio_instance_sanity_check($instance)) {
+                print_error(get_string($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin')));
+            }
+            $instance->set('user', $USER);
+            $exporter->set('instance', $instance);
+        }
+    }
 } else {
     // we'e just posted here for the first time and have might the instance already
     if ($instance = optional_param('instance', 0, PARAM_INT)) {
@@ -108,21 +109,25 @@ if (!$exporter->get('instance')) {
     // add them as hidden fields in a new form
     // to select the instance and post back here again
     // for the next block to catch
-    $form = '<form action="' . $CFG->wwwroot . '/portfolio/add.php" method="post">' . "\n";
-
-    if (!$select = portfolio_instance_select(portfolio_instances(), $exporter->get('caller')->supported_formats(), get_class($exporter->get('caller')), 'instance', true)) {
-        print_error('noavailableplugins', 'portfolio');
+    $mform = new portfolio_instance_select('', array('caller' => $exporter->get('caller')));
+    if ($mform->is_cancelled()) {
+        $returnurl = $caller->get_return_url();
+        unset($SESSION->portfolio);
+        redirect($returnurl);
+        exit;
+    } else if ($fromform = $mform->get_data()){
+        redirect($CFG->wwwroot . '/portfolio/add.php?instance=' . $fromform->instance);
+        exit;
+    }
+    else {
+        $exporter->print_header();
+        print_heading(get_string('selectplugin', 'portfolio'));
+        print_simple_box_start();
+        $mform->display();
+        print_simple_box_end();
+        print_footer();
+        exit;
     }
-    $form .= $select;
-    $form .= '<input type="submit" value="' . get_string('select') . '" />';
-    $form .= '</form>' . "\n";
-    $exporter->print_header();
-    print_heading(get_string('selectplugin', 'portfolio'));
-    print_simple_box_start();
-    echo $form;
-    print_simple_box_end();
-    print_footer();
-    exit;
 }
 
 $exporter->process_stage($stage, $alreadystolen);