MDL-14591 many small fixes to portfolio
This commit is contained in:
@@ -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';
|
||||
|
||||
+55
-6
@@ -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 . '&callbackclass=' . $classname . '&callbackfile=' . $classfile;
|
||||
|
||||
if (is_object($callbackargs)) {
|
||||
$callbackargs = (array)$callbackargs;
|
||||
}
|
||||
if (!is_array($callbackargs) || empty($callbackargs)) {
|
||||
return $url;
|
||||
}
|
||||
foreach ($callbackargs as $key => $value) {
|
||||
$url .= '&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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+14
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user