Skip to content

Commit

Permalink
MDL-16520 - make the already exporting portfolio error more user frie…
Browse files Browse the repository at this point in the history
…ndly
  • Loading branch information
mjollnir_ committed Sep 16, 2008
1 parent 74b40fa commit a476313
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lang/en_utf8/portfolio.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

$string['activeportfolios'] = 'Active portfolios';
$string['alreadyalt'] = 'Already exporting - please click here to resolve this transfer';
$string['alreadytext'] = 'Add to portfolio - needs attention';
$string['addnewportfolio'] = 'Add a new portfolio';
$string['addtoportfolio'] = 'Add to portfolio';
$string['addalltoportfolio'] = 'Add all to portfolio';
$string['alreadyexporting'] = 'You already have an active portfolio export in this session. Please <a href=\"$a->finish\">complete that first</a>, or <a href=\"$a->cancel\">click here</a> to cancel it.';
$string['activeexport'] = 'Resolve active export';
$string['alreadyexporting'] = 'You already have an active portfolio export in this session. Before continuing, you must either complete this export, or cancel it. Would you like to continue it? (No will cancel it)';
$string['availableformats'] = 'Available export formats';
$string['callercouldnotpackage'] = 'Failed to package up your data for export: original error was $a';
$string['cannotsetvisible'] = 'Cannot set this to visible - the plugin has been completely disabled because of a misconfiguration';
Expand Down
40 changes: 36 additions & 4 deletions lib/portfoliolib.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
*/
class portfolio_add_button {

private $alreadyexporting;
private $callbackclass;
private $callbackargs;
private $callbackfile;
Expand All @@ -77,10 +78,8 @@ class portfolio_add_button {
public function __construct($options=null) {
global $SESSION, $CFG;
if (isset($SESSION->portfolioexport)) {
$a = new StdClass;
$a->cancel = $CFG->wwwroot . '/portfolio/add.php?cancel=1';
$a->finish = $CFG->wwwroot . '/portfolio/add.php?id=' . $SESSION->portfolioexport;
throw new portfolio_button_exception('alreadyexporting', 'portfolio', null, $a);
$this->alreadyexporting = true;
return;
}
$this->instances = portfolio_instances();
if (empty($options)) {
Expand Down Expand Up @@ -108,6 +107,9 @@ public function __construct($options=null) {
* this path should be relative (ie, not include) dirroot, eg '/mod/forum/lib.php'
*/
public function set_callback_options($class, array $argarray, $file=null) {
if ($this->alreadyexporting) {
return;
}
global $CFG;
if (empty($file)) {
$backtrace = debug_backtrace();
Expand Down Expand Up @@ -147,6 +149,9 @@ public function set_callback_options($class, array $argarray, $file=null) {
* {@see portfolio_format_from_file} for how to get the appropriate formats to pass here for uploaded files.
*/
public function set_formats($formats=null) {
if ($this->alreadyexporting) {
return;
}
if (is_string($formats)) {
$formats = array($formats);
}
Expand Down Expand Up @@ -183,6 +188,9 @@ public function render($format=null, $addstr=null) {
* this is whole string, not key. optional, defaults to 'Add to portfolio';
*/
public function to_html($format=null, $addstr=null) {
if ($this->alreadyexporting) {
return $this->already_exporting($format);
}
global $CFG, $COURSE;
if (!$this->is_renderable()) {
return;
Expand Down Expand Up @@ -314,6 +322,30 @@ public function get_callbackfile() {
public function get_callbackclass() {
return $this->callbackclass;
}

private function already_exporting($format) {
global $CFG;
$url = $CFG->wwwroot . '/portfolio/already.php';
$icon = $CFG->pixpath . '/t/portfoliono.gif';
$alt = get_string('alreadyalt', 'portfolio');
$text = get_string('alreadytext', 'portfolio');
if (empty($format)) {
$format = PORTFOLIO_ADD_FULL_FORM;
}
switch ($format) {
case PORTFOLIO_ADD_FULL_FORM:
return '<form action="' . $url . '">' . "\n"
. '<input type="submit" value="' . $text . '" />' . "\n"
. ' </form>';
case PORTFOLIO_ADD_ICON_FORM:
case PORTFOLIO_ADD_ICON_LINK:
return '<a href="' . $url . '"><img src="' . $icon . '" alt="' . $alt . '" /></a>';
case PORTFOLIO_ADD_TEXT_LINK:
return '<a href="' . $url . '">' . $text . '</a>';
default:
debugging(get_string('invalidaddformat', 'portfolio', $format));
}
}
}

/**
Expand Down
Binary file added pix/t/portfoliono.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions portfolio/already.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
require_once(dirname(dirname(__FILE__)) . '/config.php');

if (empty($CFG->enableportfolios)) {
print_error('disabled', 'portfolio');
}

$strheading = get_string('activeexport', 'portfolio');
print_header($strheading, $strheading);

notice_yesno(get_string('alreadyexporting', 'portfolio'), $CFG->wwwroot . '/portfolio/add.php', $CFG->wwwroot . '/portfolio/add.php?cancel=1');

print_footer();

?>

0 comments on commit a476313

Please sign in to comment.