MDL-22813 Thanks to Mark Nelson from Pukunui Technologies, Portfolio management now looks like Repository.
This commit is contained in:
+61
-38
@@ -5,64 +5,82 @@ require_once($CFG->libdir . '/portfoliolib.php');
|
||||
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 @@ if (!empty($edit) || !empty($new)) {
|
||||
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);
|
||||
|
||||
@@ -266,12 +266,11 @@ if ($hassiteconfig) {
|
||||
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')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ $string['continuetoportfolio'] = 'Continue to your portfolio';
|
||||
$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['notimplemented'] = 'Sorry, but you are trying to export content in some
|
||||
$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';
|
||||
|
||||
+75
-38
@@ -5487,6 +5487,15 @@ class admin_setting_manageportfolio extends admin_setting {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*
|
||||
@@ -5524,15 +5533,35 @@ class admin_setting_manageportfolio extends admin_setting {
|
||||
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 @@ class admin_setting_manageportfolio extends admin_setting {
|
||||
$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 .= '<a href="' . $this->baseurl . '&edit=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" alt="' . get_string('edit') . '" /></a>' . "\n";
|
||||
$row .= '<a href="' . $this->baseurl . '&delete=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/delete') . '" alt="' . get_string('delete') . '" /></a>' . "\n";
|
||||
$settings = '<a href="' . $this->baseurl . '&action=edit&pf=' . $i->get('id') . '">' . $strsettings .'</a>';
|
||||
|
||||
// Check if the instance is misconfigured
|
||||
if (array_key_exists($i->get('plugin'), $insane) || array_key_exists($i->get('id'), $insaneinstances)) {
|
||||
$row .= '<img src="' . $OUTPUT->pix_url('t/show') . '" alt="' . get_string('hidden', 'portfolio') . '" />' . "\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') . " <strong>(" . get_string('portfoliomisconfigured', 'portfolio') . ")</strong>", $OUTPUT->render($select), $settings);
|
||||
} else {
|
||||
$row .= ' <a href="' . $this->baseurl . '&hide=' . $i->get('id') . '"><img src="' .
|
||||
$OUTPUT->pix_url('t/' . ($i->get('visible') ? 'hide' : 'show')) . '" alt="' . get_string($i->get('visible') ? 'hide' : 'show') . '" /></a>' . "\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');
|
||||
}
|
||||
}
|
||||
|
||||
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), '');
|
||||
}
|
||||
}
|
||||
|
||||
$output .= html_writer::table($table);
|
||||
|
||||
$instancehtml = '<br /><br />' . get_string('addnewportfolio', 'portfolio') . ': <br /><br />';
|
||||
$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;
|
||||
}
|
||||
|
||||
$instancehtml .= '<a href="' . $this->baseurl . '&new=' . $p . '">' . portfolio_static_function($p, 'get_name') . ' (' . s($p) . ')' . '</a><br />' . "\n";
|
||||
$addable++;
|
||||
}
|
||||
|
||||
if ($addable) {
|
||||
$output .= $instancehtml;
|
||||
}
|
||||
$output .= $OUTPUT->box_end();
|
||||
|
||||
return highlight($query, $output);
|
||||
@@ -6378,7 +6410,7 @@ class admin_setting_managerepository extends admin_setting {
|
||||
*/
|
||||
|
||||
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 @@ class admin_setting_managerepository extends admin_setting {
|
||||
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 = '';
|
||||
|
||||
+12
-4
@@ -125,6 +125,9 @@ final class portfolio_admin_form extends moodleform {
|
||||
|
||||
protected $instance;
|
||||
protected $plugin;
|
||||
protected $portfolio;
|
||||
protected $action;
|
||||
protected $visible;
|
||||
|
||||
public function definition() {
|
||||
global $CFG;
|
||||
@@ -132,14 +135,19 @@ final class portfolio_admin_form extends moodleform {
|
||||
$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);
|
||||
|
||||
|
||||
@@ -466,6 +466,7 @@ abstract class portfolio_plugin_base {
|
||||
$classname = 'portfolio_plugin_' . $plugin;
|
||||
$obj = new $classname($newid);
|
||||
$obj->set_config($config);
|
||||
$obj->save();
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user