? config.php
? manageportfolio.patch
? nbproject
? patch.txt
Index: admin/portfolio.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/portfolio.php,v
retrieving revision 1.14
diff -u -r1.14 portfolio.php
--- admin/portfolio.php 31 Mar 2010 08:10:21 -0000 1.14
+++ admin/portfolio.php 21 Jun 2010 17:40:33 -0000
@@ -5,64 +5,82 @@
require_once($CFG->libdir . '/portfolio/forms.php');
require_once($CFG->libdir . '/adminlib.php');
-$edit = optional_param('edit', 0, PARAM_INT);
-$new = optional_param('new', '', PARAM_FORMAT);
-$hide = optional_param('hide', 0, PARAM_INT);
-$delete = optional_param('delete', 0, PARAM_INT);
-$sure = optional_param('sure', '', PARAM_ALPHA);
+$portfolio = optional_param('pf', '', PARAM_FORMAT);
+$action = optional_param('action', '', PARAM_ALPHA);
+$sure = optional_param('sure', '', PARAM_ALPHA);
$display = true; // fall through to normal display
$pagename = 'portfoliocontroller';
-if ($edit) {
- $pagename = 'portfoliosettings' . $edit;
-} else if ($delete) {
+if ($action == 'edit') {
+ $pagename = 'portfoliosettings' . $portfolio;
+} else if ($action == 'delete') {
$pagename = 'portfoliodelete';
-} else if ($new) {
+} else if (($action == 'newon') || ($action == 'newoff')) {
$pagename = 'portfolionew';
}
+
+// Need to remember this for form
+$formaction = $action;
+
+// Check what visibility to show the new repository
+if ($action == 'newon') {
+ $action = 'new';
+ $visible = 1;
+} else if ($action == 'newoff') {
+ $action = 'new';
+ $visible = 0;
+}
+
admin_externalpage_setup($pagename);
+require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
+
$baseurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageportfolios";
$sesskeyurl = "$CFG->wwwroot/$CFG->admin/portfolio.php?sesskey=" . sesskey();
$configstr = get_string('manageportfolios', 'portfolio');
$return = true; // direct back to the main page
-if (!empty($edit) || !empty($new)) {
- if (!empty($edit)) {
- $instance = portfolio_instance($edit);
+if (($action == 'edit') || ($action == 'new')) {
+ if (($action == 'edit')) {
+ $instance = portfolio_instance($portfolio);
$plugin = $instance->get('plugin');
+
+ // Since visible is being passed to form
+ // and used to set the value when a new
+ // instance is created - we must also
+ // place the currently visibility into the
+ // form as well
+ $visible = $instance->get('visible');
} else {
- $plugin = $new;
$instance = null;
+ $plugin = $portfolio;
}
$PAGE->set_pagetype('admin-portfolio-' . $plugin);
- // display the edit form for this instance
- $mform = new portfolio_admin_form('', array('plugin' => $plugin, 'instance' => $instance));
- // end setup, begin output
+ // Display the edit form for this instance
+ $mform = new portfolio_admin_form('', array('plugin' => $plugin, 'instance' => $instance, 'portfolio' => $portfolio, 'action' => $formaction, 'visible' => $visible));
+ // End setup, begin output
if ($mform->is_cancelled()){
redirect($baseurl);
exit;
- } else if ($fromform = $mform->get_data()){
- // unset whatever doesn't belong in fromform
- foreach (array('edit', 'new', 'plugin', 'sesskey', 'submitbutton') as $key) {
+ } else if (($fromform = $mform->get_data()) && (confirm_sesskey())) {
+ // Unset whatever doesn't belong in fromform
+ foreach (array('pf', 'action', 'plugin', 'sesskey', 'submitbutton') as $key) {
unset($fromform->{$key});
}
- //this branch is where you process validated data.
- if ($edit) {
+ // This branch is where you process validated data.
+ if ($action == 'edit') {
$instance->set_config($fromform);
$instance->save();
} else {
portfolio_static_function($plugin, 'create_instance', $plugin, $fromform->name, $fromform);
}
$savedstr = get_string('instancesaved', 'portfolio');
- echo $OUTPUT->header();
- echo $OUTPUT->heading($savedstr);
- redirect($baseurl, $savedstr, 3);
+ redirect($baseurl, $savedstr, 1);
exit;
} else {
echo $OUTPUT->header();
@@ -72,39 +90,44 @@
echo $OUTPUT->box_end();
$return = false;
}
-} else if (!empty($hide)) {
- if (!confirm_sesskey()) {
- print_error('confirmsesskeybad', '', $baseurl);
- }
- $instance = portfolio_instance($hide);
+} else if (($action == 'hide') || ($action == 'show')) {
+ require_sesskey();
+
+ $instance = portfolio_instance($portfolio);
$current = $instance->get('visible');
if (empty($current) && $instance->instance_sanity_check()) {
print_error('cannotsetvisible', 'portfolio', $baseurl);
}
- $instance->set('visible', !$instance->get('visible'));
+
+ if ($action == 'show') {
+ $visible = 1;
+ } else {
+ $visible = 0;
+ }
+
+ $instance->set('visible', $visible);
$instance->save();
$return = true;
-} else if (!empty($delete)) {
- echo $OUTPUT->header();
- $instance = portfolio_instance($delete);
+} else if ($action == 'delete') {
+ $instance = portfolio_instance($portfolio);
if ($sure) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
if ($instance->delete()) {
$deletedstr = get_string('instancedeleted', 'portfolio');
- echo $OUTPUT->heading($deletedstr);
- redirect($baseurl, $deletedstr, 3);
+ redirect($baseurl, $deletedstr, 1);
} else {
print_error('instancenotdeleted', 'portfolio', $baseurl);
}
exit;
+ } else {
+ echo $OUTPUT->header();
+ echo $OUTPUT->confirm(get_string('sure', 'portfolio', $instance->get('name')), $sesskeyurl . '&pf='.$portfolio.'&action=delete&sure=yes', $baseurl);
+ $return = false;
}
- echo $OUTPUT->confirm(get_string('sure', 'portfolio', $instance->get('name')), $sesskeyurl . '&delete=' . $delete . '&sure=yes', $baseurl);
- $return = false;
}
-
if (!empty($return)) {
// normal display. fall through to here (don't call exit) if you want this to run
redirect($baseurl);
Index: admin/settings/plugins.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/settings/plugins.php,v
retrieving revision 1.76
diff -u -r1.76 plugins.php
--- admin/settings/plugins.php 21 Jun 2010 15:30:55 -0000 1.76
+++ admin/settings/plugins.php 21 Jun 2010 17:40:34 -0000
@@ -266,12 +266,11 @@
new admin_externalpage(
'portfoliosettings' . $portfolio->get('id'),
$portfolio->get('name'),
- $url . '?edit=' . $portfolio->get('id'),
- 'moodle/site:config',
- !$portfolio->get('visible')
+ $url . '?action=edit&pf=' . $portfolio->get('id'),
+ 'moodle/site:config'
),
$portfolio->get('name'),
- $url . ' ?edit=' . $portfolio->get('id')
+ $url . '?action=edit&pf=' . $portfolio->get('id')
);
}
Index: lang/en/portfolio.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en/portfolio.php,v
retrieving revision 1.5
diff -u -r1.5 portfolio.php
--- lang/en/portfolio.php 21 May 2010 19:18:47 -0000 1.5
+++ lang/en/portfolio.php 21 Jun 2010 17:40:35 -0000
@@ -45,6 +45,7 @@
$string['deleteportfolio'] = 'Delete portfolio instance';
$string['destination'] = 'Destination';
$string['disabled'] = 'Sorry, but portfolio exports are not enabled in this site';
+$string['disabledinstance'] = 'Disabled';
$string['displayarea'] = 'Export area';
$string['displayexpiry'] = 'Transfer expiry time';
$string['displayinfo'] = 'Export info';
@@ -153,10 +154,13 @@
$string['notyetselected'] = 'Not yet selected';
$string['notyours'] = 'You are trying to resume a portfolio export that doesn\'t belong to you!';
$string['nouploaddirectory'] = 'Could not create a temporary directory to package your data into';
+$string['off'] = 'Enabled but hidden';
+$string['on'] = 'Enabled and visible';
$string['plugin'] = 'Portfolio plugin';
$string['plugincouldnotpackage'] = 'Failed to package up your data for export: original error was {$a}';
$string['pluginismisconfigured'] = 'Portfolio plugin is misconfigured, skipping. Error was: {$a}';
$string['portfolio'] = 'Portfolio';
+$string['portfoliomisconfigured'] = 'Misconfigured';
$string['portfolios'] = 'Portfolios';
$string['queuesummary'] = 'Currently queued transfers';
$string['returntowhereyouwere'] = 'Return to where you were';
Index: lib/adminlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/adminlib.php,v
retrieving revision 1.472
diff -u -r1.472 adminlib.php
--- lib/adminlib.php 21 Jun 2010 15:30:50 -0000 1.472
+++ lib/adminlib.php 21 Jun 2010 17:40:37 -0000
@@ -5488,6 +5488,15 @@
}
/**
+ * Helper function that generates a moodle_url object
+ * relevant to the portfolio
+ */
+
+ function portfolio_action_url($portfolio) {
+ return new moodle_url($this->baseurl, array('sesskey'=>sesskey(), 'pf'=>$portfolio));
+ }
+
+ /**
* Searches the portfolio types for the specified type(string)
*
* @param string $query The string to search for
@@ -5524,15 +5533,35 @@
public function output_html($data, $query='') {
global $CFG, $OUTPUT;
- $output = $OUTPUT->box_start('generalbox');
+ // Get strings that are used
+ $strshow = get_string('on', 'portfolio');
+ $strhide = get_string('off', 'portfolio');
+ $strdelete = get_string('disabledinstance', 'portfolio');
+ $strsettings = get_string('settings');
- $namestr = get_string('name');
- $pluginstr = get_string('plugin', 'portfolio');
+ $actionchoicesforexisting = array(
+ 'show' => $strshow,
+ 'hide' => $strhide,
+ 'delete' => $strdelete
+ );
+
+ $actionchoicesfornew = array(
+ 'newon' => $strshow,
+ 'newoff' => $strhide,
+ 'delete' => $strdelete
+ );
+
+ $actionchoicesforinsane = array(
+ 'hide' => $strhide,
+ 'delete' => $strdelete
+ );
+
+ $output = $OUTPUT->box_start('generalbox');
$plugins = get_plugin_list('portfolio');
$plugins = array_keys($plugins);
$instances = portfolio_instances(false, false);
- $alreadyplugins = array();
+ $usedplugins = array();
// to avoid notifications being sent out while admin is editing the page
define('ADMIN_EDITING_PORTFOLIO', true);
@@ -5544,44 +5573,47 @@
$output .= portfolio_report_insane($insaneinstances, $instances, true);
$table = new html_table();
- $table->head = array($namestr, $pluginstr, '');
+ $table->head = array(get_string('plugin', 'portfolio'), '', '');
$table->data = array();
foreach ($instances as $i) {
- $row = '';
- $row .= '
' . "\n";
- $row .= '
' . "\n";
+ $settings = '' . $strsettings .'';
+
+ // Check if the instance is misconfigured
if (array_key_exists($i->get('plugin'), $insane) || array_key_exists($i->get('id'), $insaneinstances)) {
- $row .= '
' . "\n";
+ $select = new single_select($this->portfolio_action_url($i->get('id'), 'pf'), 'action', $actionchoicesforinsane, 'hide', null, 'applyto' . $i->get('id'));
+ $table->data[] = array($i->get('name') . " (" . get_string('portfoliomisconfigured', 'portfolio') . ")", $OUTPUT->render($select), $settings);
} else {
- $row .= '
' . "\n";
+ if ($i->get('visible')) {
+ $currentaction = 'show';
+ } else {
+ $currentaction = 'hide';
+ }
+ $select = new single_select($this->portfolio_action_url($i->get('id'), 'pf'), 'action', $actionchoicesforexisting, $currentaction, null, 'applyto' . $i->get('id'));
+ $table->data[] = array($i->get('name'), $OUTPUT->render($select), $settings);
}
- $table->data[] = array($i->get('name'), $i->get_name() . ' (' . $i->get('plugin') . ')', $row);
- if (!in_array($i->get('plugin'), $alreadyplugins)) {
- $alreadyplugins[] = $i->get('plugin');
+ if (!in_array($i->get('plugin'), $usedplugins)) {
+ $usedplugins[] = $i->get('plugin');
}
}
- $output .= html_writer::table($table);
-
- $instancehtml = '
' . get_string('addnewportfolio', 'portfolio') . ':
';
- $addable = 0;
- foreach ($plugins as $p) {
- if (!portfolio_static_function($p, 'allows_multiple_instances') && in_array($p, $alreadyplugins)) {
- continue;
- }
- if (array_key_exists($p, $insane)) {
- continue;
+ if (!empty($plugins)) {
+ foreach ($plugins as $p) {
+ // Check if it can not have multiple instances and has already been used
+ if (!portfolio_static_function($p, 'allows_multiple_instances') && in_array($p, $usedplugins)) {
+ continue;
+ }
+ // Check if it is misconfigured
+ if (array_key_exists($p, $insane)) {
+ continue;
+ }
+ $select = new single_select($this->portfolio_action_url($p, 'pf'), 'action', $actionchoicesfornew, 'delete', null, 'applyto' . $p);
+ $table->data[] = array(portfolio_static_function($p, 'get_name'), $OUTPUT->render($select), '');
}
-
- $instancehtml .= '' . portfolio_static_function($p, 'get_name') . ' (' . s($p) . ')' . '
' . "\n";
- $addable++;
}
- if ($addable) {
- $output .= $instancehtml;
- }
+ $output .= html_writer::table($table);
+
$output .= $OUTPUT->box_end();
return highlight($query, $output);
@@ -6378,7 +6410,7 @@
*/
function repository_action_url($repository) {
- return new moodle_url('/admin/repository.php', array('sesskey'=>sesskey(), 'repos'=>$repository));
+ return new moodle_url($this->baseurl, array('sesskey'=>sesskey(), 'repos'=>$repository));
}
/**
@@ -6391,16 +6423,21 @@
public function output_html($data, $query='') {
global $CFG, $USER, $OUTPUT;
+ // Get strings that are used
+ $strshow = get_string('on', 'repository');
+ $strhide = get_string('off', 'repository');
+ $strdelete = get_string('disabled', 'repository');
+
$actionchoicesforexisting = array(
- 'show' => get_string('on', 'repository'),
- 'hide' => get_string('off', 'repository'),
- 'delete' => get_string('disabled', 'repository')
+ 'show' => $strshow,
+ 'hide' => $strhide,
+ 'delete' => $strdelete
);
$actionchoicesfornew = array(
- 'newon' => get_string('on', 'repository'),
- 'newoff' => get_string('off', 'repository'),
- 'delete' => get_string('disabled', 'repository')
+ 'newon' => $strshow,
+ 'newoff' => $strhide,
+ 'delete' => $strdelete
);
$return = '';
Index: lib/portfolio/forms.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/portfolio/forms.php,v
retrieving revision 1.8
diff -u -r1.8 forms.php
--- lib/portfolio/forms.php 23 Feb 2010 11:25:32 -0000 1.8
+++ lib/portfolio/forms.php 21 Jun 2010 17:40:38 -0000
@@ -125,6 +125,9 @@
protected $instance;
protected $plugin;
+ protected $portfolio;
+ protected $action;
+ protected $visible;
public function definition() {
global $CFG;
@@ -132,14 +135,19 @@
$this->instance = (isset($this->_customdata['instance'])
&& is_subclass_of($this->_customdata['instance'], 'portfolio_plugin_base'))
? $this->_customdata['instance'] : null;
+ $this->portfolio = $this->_customdata['portfolio'];
+ $this->action = $this->_customdata['action'];
+ $this->visible = $this->_customdata['visible'];
$mform =& $this->_form;
$strrequired = get_string('required');
- $mform->addElement('hidden', 'edit', ($this->instance) ? $this->instance->get('id') : 0);
- $mform->setType('edit', PARAM_INT);
- $mform->addElement('hidden', 'new', $this->plugin);
- $mform->setType('new', PARAM_INT);
+ $mform->addElement('hidden', 'pf', $this->portfolio);
+ $mform->setType('pf', PARAM_ALPHA);
+ $mform->addElement('hidden', 'action', $this->action);
+ $mform->setType('action', PARAM_ALPHA);
+ $mform->addElement('hidden', 'visible', $this->visible);
+ $mform->setType('visible', PARAM_INT);
$mform->addElement('hidden', 'plugin', $this->plugin);
$mform->setType('plugin', PARAM_SAFEDIR);
Index: lib/portfolio/plugin.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/portfolio/plugin.php,v
retrieving revision 1.22
diff -u -r1.22 plugin.php
--- lib/portfolio/plugin.php 2 May 2010 18:01:05 -0000 1.22
+++ lib/portfolio/plugin.php 21 Jun 2010 17:40:38 -0000
@@ -466,6 +466,7 @@
$classname = 'portfolio_plugin_' . $plugin;
$obj = new $classname($newid);
$obj->set_config($config);
+ $obj->save();
return $obj;
}