$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';
$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';
$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) {
*
* @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.
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.
return;
}
$selectoutput .= "\n" . "</select>\n";
- return $selectoutput;
+ if (!empty($returnarray)) {
+ return $options;
+ }
+ if (!empty($return)) {
+ return $selectoutput;
+ }
+ echo $selectoutput;
}
/**
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
*
* @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};
}
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());
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;
+ }
}
/**
$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')));
}
} 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')));
}
$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)) {
// 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);
// 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;