]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14591 many small fixes to portfolio
authormjollnir_ <mjollnir_>
Fri, 1 Aug 2008 12:23:32 +0000 (12:23 +0000)
committermjollnir_ <mjollnir_>
Fri, 1 Aug 2008 12:23:32 +0000 (12:23 +0000)
lang/en_utf8/portfolio.php
lib/portfoliolib.php
portfolio/add.php

index 18d61f753a7fc439fe041f47fb6149bceff3e77f..856d624be9f6619e5be2efb1d8e9a2c20b0224ff 100644 (file)
@@ -31,6 +31,7 @@ $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['invalidinstance'] = 'Could not find that portfolio instance';
 $string['manageportfolios'] = 'Manage portfolios';
 $string['manageyourportfolios'] = 'Manage your portfolios';
 $string['noavailableplugins'] = 'Sorry, but there are no available portfolios for you to export to';
@@ -41,6 +42,7 @@ $string['nonprimative'] = 'A non primative value was passed as a callback argume
 $string['notexportable'] = 'Sorry, but the type of content you are trying to export is not exportable';
 $string['nouploaddirectory'] = 'Could not create a temporary directory to package your data into';
 $string['portfolio'] = 'Portfolio';
+$string['portfolionotfile'] = 'Export to a portfolio rather than a file';
 $string['portfolios'] = 'Portfolios';
 $string['plugin'] = 'Portfolio Plugin';
 $string['plugincouldnotpackage'] = 'Failed to package up your data for export';
index 96b2e9cf1c324cb3e6d6831973514350eef8178a..69819c12a8e2305f7d976c3421cf9f587a6a8ed3 100644 (file)
@@ -200,7 +200,7 @@ function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null,
         $output .= "\n" . '<input type="hidden" name="instance" value="' . $instance->get('id') . '" />';
     }
     else {
-        $selectoutput = portfolio_instance_select($instances, $callersupports, $callbackclass);
+        $selectoutput = portfolio_instance_select($instances, $callersupports, $callbackclass, true);
     }
 
     if ($fullform) {
@@ -231,10 +231,16 @@ function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null,
 *
 * @return string the html, from <select> to </select> inclusive.
 */
-function portfolio_instance_select($instances, $callerformats, $callbackclass) {
+function portfolio_instance_select($instances, $callerformats, $callbackclass, $selectname='instance', $return=false, $returnarray=false) {
+    global $CFG;
+
+    if (empty($CFG->portfolioenabled)) {
+        return;
+    }
+
     $insane = portfolio_instance_sanity_check();
     $count = 0;
-    $selectoutput = "\n" . '<select name="instance">' . "\n";
+    $selectoutput = "\n" . '<select name="' . $selectname . '">' . "\n";
     foreach ($instances as $instance) {
         if (count(array_intersect($callerformats,  $instance->supported_formats())) == 0) {
             // bail. no common formats.
@@ -246,7 +252,8 @@ function portfolio_instance_select($instances, $callerformats, $callbackclass) {
             continue;
         }
         $count++;
-        $selectoutput .= "\n" . '<option value="' . $instance->get('id') . '">' . $instance->get('name') . '</a>' . "\n";
+        $selectoutput .= "\n" . '<option value="' . $instance->get('id') . '">' . $instance->get('name') . '</option>' . "\n";
+        $options[$instance->get('id')] = $instance->get('name');
     }
     if (empty($count)) {
         // bail. no common formats.
@@ -254,7 +261,13 @@ function portfolio_instance_select($instances, $callerformats, $callbackclass) {
         return;
     }
     $selectoutput .= "\n" . "</select>\n";
-    return $selectoutput;
+    if (!empty($returnarray)) {
+        return $options;
+    }
+    if (!empty($return)) {
+        return $selectoutput;
+    }
+    echo $selectoutput;
 }
 
 /**
@@ -503,6 +516,30 @@ function temp_portfolio_cleanup($unique) {
     return remove_dir($workdir);
 }
 
+/**
+* fake the url to portfolio/add.php from data from somewhere else
+* you should use portfolio_add_button instead 99% of the time
+*
+* @param int $instanceid instanceid (optional, will force a new screen if not specified)
+* @param string $classname callback classname
+* @param string $classfile file containing the callback class definition
+* @param array $callbackargs arguments to pass to the callback class
+*/
+function portfolio_fake_add_url($instanceid, $classname, $classfile, $callbackargs) {
+    global $CFG;
+    $url = $CFG->wwwroot . '/portfolio/add.php?instance=' . $instanceid . '&amp;callbackclass=' . $classname . '&amp;callbackfile=' . $classfile;
+
+    if (is_object($callbackargs)) {
+        $callbackargs = (array)$callbackargs;
+    }
+    if (!is_array($callbackargs) || empty($callbackargs)) {
+        return $url;
+    }
+    foreach ($callbackargs as $key => $value) {
+        $url .= '&amp;ca_' . $key . '=' . urlencode($value);
+    }
+    return $url;
+}
 
 /**
 * base class for the caller
@@ -596,7 +633,7 @@ abstract class portfolio_caller_base {
     *
     * @todo  determine what to return in the error case
     */
-    public final function get($field) {
+    public function get($field) {
         if (property_exists($this, $field)) {
             return $this->{$field};
         }
@@ -735,6 +772,7 @@ abstract class portfolio_caller_base {
 abstract class portfolio_module_caller_base extends portfolio_caller_base {
 
     protected $cm;
+    protected $course;
 
     public function get_navigation() {
         $extranav = array('name' => $this->cm->name, 'link' => $this->get_return_url());
@@ -745,6 +783,17 @@ abstract class portfolio_module_caller_base extends portfolio_caller_base {
         global $CFG;
         return $CFG->wwwroot . '/mod/' . $this->cm->modname . '/view.php?id=' . $this->cm->id;
     }
+
+    public function get($key) {
+        if ($key != 'course') {
+            return parent::get($key);
+        }
+        global $DB;
+        if (empty($this->course)) {
+            $this->course = $DB->get_record('course', array('id' => $this->cm->course));
+        }
+        return $this->course;
+    }
 }
 
 /**
index 3f73727806e3e514883c7ff670ab639f75379579..60a160f9f2109c202c68cd745412de6463883427 100644 (file)
@@ -18,7 +18,9 @@ if (isset($SESSION->portfolio) && isset($SESSION->portfolio->exporter)) {
     $SESSION->portfolio->exporter =& $exporter;
     if (!$exporter->get('instance')) {
         $instance = required_param('instance', PARAM_INT);
-        $instance = portfolio_instance($instance);
+        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')));
         }
@@ -33,7 +35,9 @@ if (isset($SESSION->portfolio) && isset($SESSION->portfolio->exporter)) {
 } else {
     // we'e just posted here for the first time and have might the instance already
     if ($instance = optional_param('instance', 0, PARAM_INT)) {
-        $instance = portfolio_instance($instance);
+        if (!$instance = portfolio_instance($instance)) {
+            portfolio_exporter::raise_error('invalidinstance', 'portfolio');
+        }
         if ($broken = portfolio_instance_sanity_check($instance)) {
             print_error(get_string($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin')));
         }
@@ -46,7 +50,7 @@ if (isset($SESSION->portfolio) && isset($SESSION->portfolio->exporter)) {
     $callbackclass = required_param('callbackclass', PARAM_ALPHAEXT);
 
     $callbackargs = array();
-    foreach (array_keys($_POST) as $key) {
+    foreach (array_keys(array_merge($_GET, $_POST)) as $key) {
         if (strpos($key, 'ca_') === 0) {
             if (!$value =  optional_param($key, false, PARAM_ALPHAEXT)) {
                 if (!$value = optional_param($key, false, PARAM_NUMBER)) {
@@ -65,14 +69,18 @@ if (isset($SESSION->portfolio) && isset($SESSION->portfolio->exporter)) {
 
     // for build navigation
     if (!$course = $caller->get('course')) {
+        echo 1;
         $course = optional_param('course', 0, PARAM_INT);
     }
 
-    if (!empty($course)) {
-        $COURSE = $DB->get_record('course', array('id' => $course), 'id,shortname,fullname');
+    if (!empty($course) && is_numeric($course)) {
+        echo 2;
+        $course = $DB->get_record('course', array('id' => $course), 'id,shortname,fullname');
         // this is yuk but used in build_navigation
     }
 
+    $COURSE = $course;
+
     list($extranav, $cm) = $caller->get_navigation();
     $extranav[] = array('type' => 'title', 'name' => get_string('exporting', 'portfolio'));
     $navigation = build_navigation($extranav, $cm);
@@ -102,7 +110,7 @@ if (!$exporter->get('instance')) {
     // 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')))) {
+    if (!$select = portfolio_instance_select(portfolio_instances(), $exporter->get('caller')->supported_formats(), get_class($exporter->get('caller')), true)) {
         print_error('noavailableplugins', 'portfolio');
     }
     $form .= $select;