Skip to content

Commit

Permalink
MDL-14591 many small fixes to portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
mjollnir_ committed Aug 1, 2008
1 parent 3aabd3f commit 9eb0a77
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lang/en_utf8/portfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
$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';
Expand All @@ -41,6 +42,7 @@
$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';
Expand Down
61 changes: 55 additions & 6 deletions lib/portfoliolib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand All @@ -246,15 +252,22 @@ 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.
debugging(get_string('nocommonformats', 'portfolio', $callbackclass));
return;
}
$selectoutput .= "\n" . "</select>\n";
return $selectoutput;
if (!empty($returnarray)) {
return $options;
}
if (!empty($return)) {
return $selectoutput;
}
echo $selectoutput;
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -596,7 +633,7 @@ public abstract function get_sha1();
*
* @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};
}
Expand Down Expand Up @@ -735,6 +772,7 @@ public abstract static function display_name();
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());
Expand All @@ -745,6 +783,17 @@ public function 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;
}
}

/**
Expand Down
20 changes: 14 additions & 6 deletions portfolio/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
$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')));
}
Expand All @@ -33,7 +35,9 @@
} 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')));
}
Expand All @@ -46,7 +50,7 @@
$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)) {
Expand All @@ -65,14 +69,18 @@

// 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);
Expand Down Expand Up @@ -102,7 +110,7 @@
// 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;
Expand Down

0 comments on commit 9eb0a77

Please sign in to comment.