admin/repository MDL-15402 Checking in code from Mark Nelson @ Pukunui.com.au. Thanks, Mark and Shane! This patch updates the repository admin interface to look more like Filters management

This commit is contained in:
Martin Dougiamas 2010-04-30 08:03:32 +00:00
parent b8cea715b8
commit 7969834463
6 changed files with 202 additions and 174 deletions

View file

@ -4,26 +4,34 @@ require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->dirroot . '/repository/lib.php'); require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->libdir . '/adminlib.php');
$edit = optional_param('edit', 0, PARAM_FORMAT); $repository = optional_param('repos', '', PARAM_FORMAT);
$new = optional_param('new', '', PARAM_FORMAT); $action = optional_param('action', '', PARAM_ALPHA);
$hide = optional_param('hide', '', PARAM_FORMAT); $sure = optional_param('sure', '', PARAM_ALPHA);
$delete = optional_param('delete', 0, PARAM_FORMAT);
$sure = optional_param('sure', '', PARAM_ALPHA);
$move = optional_param('move', '', PARAM_ALPHANUM);
$type = optional_param('type', '', PARAM_ALPHANUM);
$display = true; // fall through to normal display $display = true; // fall through to normal display
$pagename = 'repositorycontroller'; $pagename = 'repositorycontroller';
if ($edit) { if ($action == 'edit') {
$pagename = 'repositorysettings' . $edit; $pagename = 'repositorysettings' . $repository;
} else if ($delete) { } else if ($action == 'delete') {
$pagename = 'repositorydelete'; $pagename = 'repositorydelete';
} else if ($new) { } else if (($action == 'newon') || ($action == 'newoff')) {
$pagename = 'repositorynew'; $pagename = 'repositorynew';
} }
// Need to remember this for form
$formaction = $action;
// Check what visibility to show the new repository
if ($action == 'newon') {
$action = 'new';
$visible = true;
} else if ($action == 'newoff') {
$action = 'new';
$visible = false;
}
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
admin_externalpage_setup($pagename); admin_externalpage_setup($pagename);
@ -34,26 +42,26 @@ $configstr = get_string('manage', 'repository');
$return = true; $return = true;
if (!empty($edit) || !empty($new)) { if (($action == 'edit') || ($action == 'new')) {
if (!empty($edit)) { if ($action == 'edit') {
$repositorytype = repository::get_type_by_typename($edit); $repositorytype = repository::get_type_by_typename($repository);
$classname = 'repository_' . $repositorytype->get_typename(); $classname = 'repository_' . $repositorytype->get_typename();
$configs = call_user_func(array($classname,'get_type_option_names')); $configs = call_user_func(array($classname,'get_type_option_names'));
$plugin = $repositorytype->get_typename(); $plugin = $repositorytype->get_typename();
} else { } else {
$repositorytype = null; $repositorytype = null;
$plugin = $new; $plugin = $repository;
$typeid = $new; $typeid = $repository;
} }
$PAGE->set_pagetype('admin-repository-' . $plugin); $PAGE->set_pagetype('admin-repository-' . $plugin);
// display the edit form for this instance // display the edit form for this instance
$mform = new repository_type_form('', array('plugin' => $plugin, 'instance' => $repositorytype)); $mform = new repository_type_form('', array('plugin' => $plugin, 'instance' => $repositorytype, 'action' => $formaction));
$fromform = $mform->get_data(); $fromform = $mform->get_data();
//detect if we create a new type without config (in this case if don't want to display a setting page during creation) //detect if we create a new type without config (in this case if don't want to display a setting page during creation)
$nosettings = false; $nosettings = false;
if (!empty($new)) { if ($action == 'new') {
$adminconfignames = repository::static_function($new, 'get_type_option_names'); $adminconfignames = repository::static_function($repository, 'get_type_option_names');
$nosettings = empty($adminconfignames); $nosettings = empty($adminconfignames);
} }
// end setup, begin output // end setup, begin output
@ -61,10 +69,8 @@ if (!empty($edit) || !empty($new)) {
if ($mform->is_cancelled()){ if ($mform->is_cancelled()){
redirect($baseurl); redirect($baseurl);
} else if (!empty($fromform) || $nosettings) { } else if (!empty($fromform) || $nosettings) {
if (!confirm_sesskey()) { require_sesskey();
print_error('confirmsesskeybad', '', $baseurl); if ($action == 'edit') {
}
if ($edit) {
$settings = array(); $settings = array();
foreach($configs as $config) { foreach($configs as $config) {
if (!empty($fromform->$config)) { if (!empty($fromform->$config)) {
@ -75,7 +81,7 @@ if (!empty($edit) || !empty($new)) {
$settings[$config] = ''; $settings[$config] = '';
} }
} }
$instanceoptionnames = repository::static_function($edit, 'get_instance_option_names'); $instanceoptionnames = repository::static_function($repository, 'get_instance_option_names');
if (!empty($instanceoptionnames)) { if (!empty($instanceoptionnames)) {
if (array_key_exists('enablecourseinstances', $fromform)) { if (array_key_exists('enablecourseinstances', $fromform)) {
$settings['enablecourseinstances'] = $fromform->enablecourseinstances; $settings['enablecourseinstances'] = $fromform->enablecourseinstances;
@ -92,21 +98,14 @@ if (!empty($edit) || !empty($new)) {
} }
$success = $repositorytype->update_options($settings); $success = $repositorytype->update_options($settings);
} else { } else {
$type = new repository_type($plugin, (array)$fromform); $type = new repository_type($plugin, (array)$fromform, $visible);
$type->create(); $type->create();
$success = true; $success = true;
$data = data_submitted(); $data = data_submitted();
} }
if ($success) { if ($success) {
$has_instance = repository::static_function($plugin, 'get_instance_option_names'); // configs saved
redirect($baseurl);
if (!empty($has_instance)) {
// no common setting for this type, so go to setup instances
redirect($sesskeyurl.'&edit='.$plugin);
} else {
// configs saved
redirect($baseurl);
}
} else { } else {
print_error('instancenotsaved', 'repository', $baseurl); print_error('instancenotsaved', 'repository', $baseurl);
} }
@ -115,9 +114,9 @@ if (!empty($edit) || !empty($new)) {
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('configplugin', 'repository_'.$plugin)); echo $OUTPUT->heading(get_string('configplugin', 'repository_'.$plugin));
$displaysettingform = true; $displaysettingform = true;
if ($edit) { if ($action == 'edit') {
$typeoptionnames = repository::static_function($edit, 'get_type_option_names'); $typeoptionnames = repository::static_function($repository, 'get_type_option_names');
$instanceoptionnames = repository::static_function($edit, 'get_instance_option_names'); $instanceoptionnames = repository::static_function($repository, 'get_instance_option_names');
if (empty($typeoptionnames) && empty($instanceoptionnames)) { if (empty($typeoptionnames) && empty($instanceoptionnames)) {
$displaysettingform = false; $displaysettingform = false;
} }
@ -129,29 +128,38 @@ if (!empty($edit) || !empty($new)) {
} }
$return = false; $return = false;
//display instances list and creation form // Display instances list and creation form
if ($edit){ if ($action == 'edit'){
$instanceoptionnames = repository::static_function($edit, 'get_instance_option_names'); $instanceoptionnames = repository::static_function($repository, 'get_instance_option_names');
if (!empty($instanceoptionnames)){ if (!empty($instanceoptionnames)) {
repository::display_instances_list(get_context_instance(CONTEXT_SYSTEM), $edit); repository::display_instances_list(get_context_instance(CONTEXT_SYSTEM), $repository);
} }
} }
} }
} else if (!empty($hide)) { } else if ($action == 'show') {
if (!confirm_sesskey()) { if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl); print_error('confirmsesskeybad', '', $baseurl);
} }
$repositorytype = repository::get_type_by_typename($hide); $repositorytype = repository::get_type_by_typename($repository);
if (empty($repositorytype)) { if (empty($repositorytype)) {
print_error('invalidplugin', 'repository', '', $hide); print_error('invalidplugin', 'repository', '', $repository);
} }
$repositorytype->switch_and_update_visibility(); $repositorytype->update_visibility(true);
$return = true; $return = true;
} else if (!empty($delete)) { } else if ($action == 'hide') {
$repositorytype = repository::get_type_by_typename($delete); if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
$repositorytype = repository::get_type_by_typename($repository);
if (empty($repositorytype)) {
print_error('invalidplugin', 'repository', '', $repository);
}
$repositorytype->update_visibility(false);
$return = true;
} else if ($action == 'delete') {
$repositorytype = repository::get_type_by_typename($repository);
if ($sure) { if ($sure) {
$PAGE->set_pagetype('admin-repository-' . $delete); $PAGE->set_pagetype('admin-repository-' . $repository);
if (!confirm_sesskey()) { if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl); print_error('confirmsesskeybad', '', $baseurl);
} }
@ -163,13 +171,15 @@ if (!empty($edit) || !empty($new)) {
exit; exit;
} else { } else {
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmremove', 'repository', $repositorytype->get_readablename()), $sesskeyurl . '&delete=' . $delete . '&sure=yes', $baseurl); echo $OUTPUT->confirm(get_string('confirmremove', 'repository', $repositorytype->get_readablename()), $sesskeyurl . '&action=delete&repos=' . $repository . '&sure=yes', $baseurl);
$return = false; $return = false;
} }
} } else if ($action == 'moveup') {
else if (!empty($move) && !empty($type)) { $repositorytype = repository::get_type_by_typename($repository);
$repositorytype = repository::get_type_by_typename($type); $repositorytype->move_order('up');
$repositorytype->move_order($move); } else if ($action == 'movedown') {
$repositorytype = repository::get_type_by_typename($repository);
$repositorytype->move_order('down');
} }
if (!empty($return)) { if (!empty($return)) {

View file

@ -28,7 +28,7 @@ admin_externalpage_setup($pagename);
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
$sesskeyurl = "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?sesskey=" . sesskey(); $sesskeyurl = "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?sesskey=" . sesskey();
$baseurl = "$CFG->wwwroot/$CFG->admin/repository.php?session=". sesskey() .'&edit='; $baseurl = "$CFG->wwwroot/$CFG->admin/repository.php?session=". sesskey() .'&action=edit&repos=';
if ($new) { if ($new) {
$baseurl .= $new; $baseurl .= $new;
} }
@ -53,7 +53,7 @@ if (!empty($edit) || !empty($new)) {
} }
// display the edit form for this instance // display the edit form for this instance
$mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid,'instance' => $instance, 'contextid' => $context->id)); $mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid, 'instance' => $instance, 'contextid' => $context->id));
// end setup, begin output // end setup, begin output
if ($mform->is_cancelled()){ if ($mform->is_cancelled()){
@ -98,7 +98,6 @@ if (!empty($edit) || !empty($new)) {
$instance->hide(); $instance->hide();
$return = true; $return = true;
} else if (!empty($delete)) { } else if (!empty($delete)) {
echo $OUTPUT->header();
$instance = repository::get_instance($delete); $instance = repository::get_instance($delete);
//if you try to delete an instance set as readonly, display an error message //if you try to delete an instance set as readonly, display an error message
if ($instance->readonly) { if ($instance->readonly) {
@ -110,7 +109,6 @@ if (!empty($edit) || !empty($new)) {
} }
if ($instance->delete()) { if ($instance->delete()) {
$deletedstr = get_string('instancedeleted', 'repository'); $deletedstr = get_string('instancedeleted', 'repository');
echo $OUTPUT->heading($deletedstr);
redirect($baseurl, $deletedstr, 3); redirect($baseurl, $deletedstr, 3);
} else { } else {
print_error('instancenotdeleted', 'repository', $baseurl); print_error('instancenotdeleted', 'repository', $baseurl);
@ -118,6 +116,7 @@ if (!empty($edit) || !empty($new)) {
exit; exit;
} }
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmdelete', 'repository', $instance->name), "$sesskeyurl&type=$type'&delete=$delete'&sure=yes", "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?session=". sesskey()); echo $OUTPUT->confirm(get_string('confirmdelete', 'repository', $instance->name), "$sesskeyurl&type=$type'&delete=$delete'&sure=yes", "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?session=". sesskey());
$return = false; $return = false;
} }

View file

@ -233,7 +233,7 @@ if ($hassiteconfig) {
$ADMIN->add('repositorysettings', $ADMIN->add('repositorysettings',
new admin_externalpage('repositorysettings'.$repositorytype->get_typename(), new admin_externalpage('repositorysettings'.$repositorytype->get_typename(),
$repositorytype->get_readablename(), $repositorytype->get_readablename(),
$url . '?edit=' . $repositorytype->get_typename()), $url . '?action=edit&repos=' . $repositorytype->get_typename()),
'moodle/site:config'); 'moodle/site:config');
} }
} }

View file

@ -49,8 +49,6 @@ $string['cannotdownload'] = 'Cannot download this file';
$string['cannotdownloaddir'] = 'Cannot download this folder'; $string['cannotdownloaddir'] = 'Cannot download this folder';
$string['cannotinitplugin'] = 'Call plugin_init failed'; $string['cannotinitplugin'] = 'Call plugin_init failed';
$string['cleancache'] = 'Clean my cache files'; $string['cleancache'] = 'Clean my cache files';
$string['clicktohide'] = 'Click here to hide';
$string['clicktoshow'] = 'Click here to show';
$string['close'] = 'Close'; $string['close'] = 'Close';
$string['configallowexternallinks'] = 'This option enables all users to choose whether or not external media is copied into Moodle or not. If this is off then media is always copied into Moodle (this is usually best for overall data integrity and security). If this is on then users can choose each time they add media to a text.'; $string['configallowexternallinks'] = 'This option enables all users to choose whether or not external media is copied into Moodle or not. If this is off then media is always copied into Moodle (this is usually best for overall data integrity and security). If this is on then users can choose each time they add media to a text.';
$string['configcacheexpire'] = 'The amount of time that file listings are cached locally (in seconds) when browsing external repositories.'; $string['configcacheexpire'] = 'The amount of time that file listings are cached locally (in seconds) when browsing external repositories.';
@ -68,6 +66,7 @@ $string['createxxinstance'] = 'Create "{$a}" instance';
$string['date'] = 'Date'; $string['date'] = 'Date';
$string['deleted'] = 'Repository deleted'; $string['deleted'] = 'Repository deleted';
$string['deleterepository'] = 'Delete this repository'; $string['deleterepository'] = 'Delete this repository';
$string['disabled'] = 'Disabled';
$string['download'] = 'Download'; $string['download'] = 'Download';
$string['downloadfolder'] = 'Download this folder'; $string['downloadfolder'] = 'Download this folder';
$string['downloadsucc'] = 'The file has been downloaded successfully'; $string['downloadsucc'] = 'The file has been downloaded successfully';
@ -86,7 +85,7 @@ $string['filename'] = 'Filename';
$string['filenotnull'] = 'You must select a file to upload.'; $string['filenotnull'] = 'You must select a file to upload.';
$string['filesaved'] = 'The file has been saved'; $string['filesaved'] = 'The file has been saved';
$string['getfile'] = 'Select this file'; $string['getfile'] = 'Select this file';
$string['hiddenshow'] = 'Hide/Show'; $string['hidden'] = 'Hidden';
$string['choosealink'] = 'Choose a link...'; $string['choosealink'] = 'Choose a link...';
$string['chooselicense'] = 'Choose license'; $string['chooselicense'] = 'Choose license';
$string['iconview'] = 'View as icons'; $string['iconview'] = 'View as icons';
@ -98,6 +97,7 @@ $string['instancesforothers'] = 'private instance(s)';
$string['invalidjson'] = 'Invalid JSON string'; $string['invalidjson'] = 'Invalid JSON string';
$string['invalidplugin'] = 'Invalid repository {$a} plug-in'; $string['invalidplugin'] = 'Invalid repository {$a} plug-in';
$string['invalidrepositoryid'] = 'Invalid repository ID'; $string['invalidrepositoryid'] = 'Invalid repository ID';
$string['isactive'] = 'Active?';
$string['keyword'] = 'Keyword'; $string['keyword'] = 'Keyword';
$string['linkexternal'] = 'Link external'; $string['linkexternal'] = 'Link external';
$string['listview'] = 'View as list'; $string['listview'] = 'View as list';
@ -114,8 +114,10 @@ $string['nopathselected'] = 'No destination path select yet (double click tree n
$string['nopermissiontoaccess'] = 'No permission to access this repository'; $string['nopermissiontoaccess'] = 'No permission to access this repository';
$string['noresult'] = 'No search result'; $string['noresult'] = 'No search result';
$string['notyourinstances'] = 'You can not view/edit repository instances of another user'; $string['notyourinstances'] = 'You can not view/edit repository instances of another user';
$string['off'] = 'Enabled but hidden';
$string['openpicker'] = 'Choose a file...'; $string['openpicker'] = 'Choose a file...';
$string['operation'] = 'Operation'; $string['operation'] = 'Operation';
$string['on'] = 'Enabled and visible';
$string['personalrepositories'] = 'Avaiable repository instances'; $string['personalrepositories'] = 'Avaiable repository instances';
$string['plugin'] = 'Repository plug-ins'; $string['plugin'] = 'Repository plug-ins';
$string['pluginerror'] = 'Errors in repository plugin.'; $string['pluginerror'] = 'Errors in repository plugin.';
@ -145,7 +147,6 @@ $string['sync'] = 'Sync';
$string['thumbview'] = 'View as icons'; $string['thumbview'] = 'View as icons';
$string['title'] = 'Choose a file...'; $string['title'] = 'Choose a file...';
$string['typenotvisible'] = 'Type not visible'; $string['typenotvisible'] = 'Type not visible';
$string['updown'] = 'Display order';
$string['upload'] = 'Upload this file'; $string['upload'] = 'Upload this file';
$string['uploading'] = 'Uploading...'; $string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully'; $string['uploadsucc'] = 'The file has been uploaded successfully';

View file

@ -1167,7 +1167,7 @@ class admin_settingpage implements part_of_admin_tree {
$data = $adminroot->errors[$fullname]->data; $data = $adminroot->errors[$fullname]->data;
} else { } else {
$data = $setting->get_setting(); $data = $setting->get_setting();
// do not use defaults if settings not available - upgrdesettings handles the defaults! // do not use defaults if settings not available - upgrade settings handles the defaults!
} }
$return .= $setting->output_html($data); $return .= $setting->output_html($data);
} }
@ -1478,7 +1478,7 @@ class admin_setting_heading extends admin_setting {
global $OUTPUT; global $OUTPUT;
$return = ''; $return = '';
if ($this->visiblename != '') { if ($this->visiblename != '') {
$return .= $OUTPUT->heading('<a name="'.$this->name.'">'.highlightfast($query, $this->visiblename).'</a>', 3, 'main', true); $return .= $OUTPUT->heading($this->visiblename, 3, 'main', true);
} }
if ($this->description != '') { if ($this->description != '') {
$return .= $OUTPUT->box(highlight($query, $this->description), 'generalbox formsettingheading'); $return .= $OUTPUT->box(highlight($query, $this->description), 'generalbox formsettingheading');
@ -6080,6 +6080,15 @@ class admin_setting_managerepository extends admin_setting {
return false; return false;
} }
/**
* Helper function that generates a moodle_url object
* relevant to the repository
*/
function repository_action_url($repository) {
return new moodle_url('/admin/repository.php', array('sesskey'=>sesskey(), 'repos'=>$repository));
}
/** /**
* Builds XHTML to display the control * Builds XHTML to display the control
* *
@ -6089,117 +6098,118 @@ class admin_setting_managerepository extends admin_setting {
*/ */
public function output_html($data, $query='') { public function output_html($data, $query='') {
global $CFG, $USER, $OUTPUT; global $CFG, $USER, $OUTPUT;
$output = $OUTPUT->box_start('generalbox');
$namestr = get_string('name'); $actionchoicesforexisting = array(
'show' => get_string('on', 'repository'),
'hide' => get_string('off', 'repository'),
'delete' => get_string('disabled', 'repository')
);
$actionchoicesfornew = array(
'newon' => get_string('on', 'repository'),
'newoff' => get_string('off', 'repository'),
'delete' => get_string('disabled', 'repository')
);
$return = '';
$return .= $OUTPUT->box_start('generalbox');
// Set strings that are used multiple times
$settingsstr = get_string('settings'); $settingsstr = get_string('settings');
$updownstr = get_string('updown', 'repository'); $disablestr = get_string('disable');
$hiddenstr = get_string('hiddenshow', 'repository');
$deletestr = get_string('delete'); // Table to list plug-ins
$plugins = get_plugin_list('repository');
$instances = repository::get_types();
$instancesnumber = count($instances);
$alreadyplugins = array();
$table = new html_table(); $table = new html_table();
$table->head = array($namestr, $updownstr, $hiddenstr, $deletestr, $settingsstr); $table->head = array(get_string('name'), get_string('isactive', 'repository'), get_string('order'), $settingsstr);
$table->align = array('left', 'center', 'center','center','center'); $table->align = array('left', 'center', 'center', 'center', 'center');
$table->data = array(); $table->data = array();
$updowncount=1;
foreach ($instances as $i) {
$settings = '';
//display edit link only if you can config the type or if it has multiple instances (e.g. has instance config)
$typeoptionnames = repository::static_function($i->get_typename(), 'get_type_option_names');
$instanceoptionnames = repository::static_function($i->get_typename(), 'get_instance_option_names');
if ( !empty($typeoptionnames) || !empty($instanceoptionnames)) { // Get list of used plug-ins
$instances = repository::get_types();
if (!empty($instances)) {
// Array to store plugins being used
$alreadyplugins = array();
$totalinstances = count($instances);
$updowncount = 1;
foreach ($instances as $i) {
$settings = '';
$typename = $i->get_typename();
// Display edit link only if you can config the type or if it has multiple instances (e.g. has instance config)
$typeoptionnames = repository::static_function($typename, 'get_type_option_names');
$instanceoptionnames = repository::static_function($typename, 'get_instance_option_names');
//calculate number of instances in order to display them for the Moodle administrator if (!empty($typeoptionnames) || !empty($instanceoptionnames)) {
if (!empty($instanceoptionnames)) { // Calculate number of instances in order to display them for the Moodle administrator
$params = array(); if (!empty($instanceoptionnames)) {
$params['context'] = array(get_system_context()); $params = array();
$params['onlyvisible'] = false; $params['context'] = array(get_system_context());
$params['type'] = $i->get_typename(); $params['onlyvisible'] = false;
$admininstancenumber = count(repository::static_function($i->get_typename(), $params['type'] = $typename;
'get_instances', $params)); $admininstancenumber = count(repository::static_function($typename, 'get_instances', $params));
$admininstancenumbertext = " <br/> ". $admininstancenumber . $admininstancenumbertext = " <br/> ". $admininstancenumber . " " . get_string('instancesforadmin', 'repository');
" " . get_string('instancesforadmin', 'repository'); $params['context'] = array();
$params['context'] = array(); $instancenumber = count(repository::static_function($typename, 'get_instances', $params)) - $admininstancenumber;
$instancenumber = count(repository::static_function($i->get_typename(), 'get_instances', $params)) - $admininstancenumber; $instancenumbertext = "<br/>" . $instancenumber . " " . get_string('instancesforothers', 'repository');
$instancenumbertext = "<br/>" . $instancenumber . } else {
" " . get_string('instancesforothers', 'repository'); $admininstancenumbertext = "";
$instancenumbertext = "";
}
$settings .= '<a href="' . $this->baseurl . '&amp;action=edit&amp;repos=' . $typename . '">' . $settingsstr .'</a>' . $admininstancenumbertext . $instancenumbertext . "\n";
}
// Get the current visibility
if ($i->get_visible()) {
$currentaction = 'show';
} else { } else {
$admininstancenumbertext = ""; $currentaction = 'hide';
$instancenumbertext = ""; }
$select = new single_select($this->repository_action_url($typename, 'repos'), 'action', $actionchoicesforexisting, $currentaction, null, 'applyto' . basename($typename));
// Display up/down link
$updown = '';
$spacer = $OUTPUT->spacer(array('height'=>15, 'width'=>15)); // should be done with CSS instead
if ($updowncount > 1) {
$updown .= "<a href=\"$this->baseurl&amp;action=moveup&amp;repos=".$typename."\">";
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/up') . "\" alt=\"up\" /></a>&nbsp;";
}
else {
$updown .= $spacer;
}
if ($updowncount < $totalinstances) {
$updown .= "<a href=\"$this->baseurl&amp;action=movedown&amp;repos=".$typename."\">";
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/down') . "\" alt=\"down\" /></a>";
}
else {
$updown .= $spacer;
} }
$settings .= '<a href="' . $this->baseurl . '&amp;edit=' . $i->get_typename() . '">' $updowncount++;
. $settingsstr .'</a>' . $admininstancenumbertext . $instancenumbertext . "\n";
}
$delete = '<a href="' . $this->baseurl . '&amp;delete=' . $i->get_typename() . '">'
. $deletestr . '</a>' . "\n";
$hidetitle = $i->get_visible() ? get_string('clicktohide', 'repository') : get_string('clicktoshow', 'repository'); $table->data[] = array($i->get_readablename(), $OUTPUT->render($select), $updown, $settings);
$hiddenshow = ' <a href="' . $this->baseurl . '&amp;hide=' . $i->get_typename() . '">'
.'<img src="' . $OUTPUT->pix_url('i/' . ($i->get_visible() ? 'hide' : 'show')) . '"'
.' alt="' . $hidetitle . '" '
.' title="' . $hidetitle . '" />'
.'</a>' . "\n";
// display up/down link if (!in_array($typename, $alreadyplugins)) {
$updown = ''; $alreadyplugins[] = $typename;
$spacer = $OUTPUT->spacer(array('height'=>15, 'width'=>15)); // should be done with CSS instead }
if ($updowncount > 1) {
$updown .= "<a href=\"$this->baseurl&amp;move=up&amp;type=".$i->get_typename()."\">";
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/up') . "\" alt=\"up\" /></a>&nbsp;";
}
else {
$updown .= $spacer;
}
if ($updowncount < count($instances)) {
$updown .= "<a href=\"$this->baseurl&amp;move=down&amp;type=".$i->get_typename()."\">";
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/down') . "\" alt=\"down\" /></a>";
}
else {
$updown .= $spacer;
}
$updowncount++;
$table->data[] = array($i->get_readablename(), $updown, $hiddenshow, $delete, $settings);
//display a grey row if the type is defined as not visible
if (!$i->get_visible()) {
$table->rowclasses[] = 'dimmed_text';
} else {
$table->rowclasses[] = '';
}
if (!in_array($i->get_typename(), $alreadyplugins)) {
$alreadyplugins[] = $i->get_typename();
} }
} }
$output .= html_writer::table($table);
$instancehtml = '<div><h3>'; // Get all the plugins that exist on disk
$instancehtml .= get_string('addplugin', 'repository'); $plugins = get_plugin_list('repository');
$instancehtml .= '</h3><ul>'; if (!empty($plugins)) {
$addable = 0; foreach ($plugins as $plugin => $dir) {
foreach ($plugins as $p=>$dir) { // Check that it has not already been listed
if (!in_array($p, $alreadyplugins)) { if (!in_array($plugin, $alreadyplugins)) {
$instancehtml .= '<li><a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/repository.php?sesskey=' $select = new single_select($this->repository_action_url($plugin, 'repos'), 'action', $actionchoicesfornew, 'delete', null, 'applyto' . basename($plugin));
.sesskey().'&amp;new='.$p.'">'.get_string('add', 'repository') $table->data[] = array(get_string('repositoryname', 'repository_'.$plugin), $OUTPUT->render($select), '', '');
.' "'.get_string('repositoryname', 'repository_'.$p).'" ' }
.'</a></li>';
$addable++;
} }
} }
$instancehtml .= '</ul>';
$instancehtml .= '</div>';
if ($addable) {
$output .= $instancehtml;
}
$output .= $OUTPUT->box_end(); $return .= html_writer::table($table);
return highlight($query, $output); $return .= $OUTPUT->box_end();
return highlight($query, $return);
} }
} }

View file

@ -377,12 +377,17 @@ class repository_type {
} }
/** /**
* 1. Switch the visibility OFF if it's ON, and ON if it's OFF. * 1. Change visibility to the value chosen
*
* 2. Update the type * 2. Update the type
* @return boolean * @return boolean
*/ */
public function switch_and_update_visibility() { public function update_visibility($visible = null) {
$this->_visible = !$this->_visible; if (is_bool($visible)) {
$this->_visible = $visible;
} else {
$this->_visible = !$this->_visible;
}
return $this->update_visible(); return $this->update_visible();
} }
@ -1022,7 +1027,6 @@ abstract class repository {
$pluginstr = get_string('plugin', 'repository'); $pluginstr = get_string('plugin', 'repository');
$settingsstr = get_string('settings'); $settingsstr = get_string('settings');
$deletestr = get_string('delete'); $deletestr = get_string('delete');
$updown = get_string('updown', 'repository');
//retrieve list of instances. In administration context we want to display all //retrieve list of instances. In administration context we want to display all
//instances of a type, even if this type is not visible. In course/user context we //instances of a type, even if this type is not visible. In course/user context we
//want to display only visible instances, but for every type types. The repository::get_instances() //want to display only visible instances, but for every type types. The repository::get_instances()
@ -1037,7 +1041,7 @@ abstract class repository {
$alreadyplugins = array(); $alreadyplugins = array();
$table = new html_table(); $table = new html_table();
$table->head = array($namestr, $pluginstr, $deletestr, $settingsstr); $table->head = array($namestr, $pluginstr, $settingsstr, $deletestr);
$table->align = array('left', 'left', 'center','center'); $table->align = array('left', 'left', 'center','center');
$table->data = array(); $table->data = array();
@ -1065,7 +1069,7 @@ abstract class repository {
} }
$type = repository::get_type_by_id($i->options['typeid']); $type = repository::get_type_by_id($i->options['typeid']);
$table->data[] = array($i->name, $type->get_readablename(), $delete, $settings); $table->data[] = array($i->name, $type->get_readablename(), $settings, $delete);
//display a grey row if the type is defined as not visible //display a grey row if the type is defined as not visible
if (isset($type) && !$type->get_visible()) { if (isset($type) && !$type->get_visible()) {
@ -1689,6 +1693,7 @@ final class repository_instance_form extends moodleform {
final class repository_type_form extends moodleform { final class repository_type_form extends moodleform {
protected $instance; protected $instance;
protected $plugin; protected $plugin;
protected $action;
/** /**
* Definition of the moodleform * Definition of the moodleform
@ -1702,15 +1707,18 @@ final class repository_type_form extends moodleform {
&& is_a($this->_customdata['instance'], 'repository_type')) && is_a($this->_customdata['instance'], 'repository_type'))
? $this->_customdata['instance'] : null; ? $this->_customdata['instance'] : null;
$this->action = $this->_customdata['action'];
$mform =& $this->_form; $mform =& $this->_form;
$strrequired = get_string('required'); $strrequired = get_string('required');
$mform->addElement('hidden', 'edit', ($this->instance) ? $this->instance->get_typename() : 0); $mform->addElement('hidden', 'repos', ($this->instance) ? $this->instance->get_typename() : 0);
$mform->setType('edit', PARAM_INT); $mform->setType('repos', PARAM_INT);
$mform->addElement('hidden', 'new', $this->plugin); $mform->addElement('hidden', 'repos', $this->plugin);
$mform->setType('new', PARAM_FORMAT); $mform->setType('repos', PARAM_FORMAT);
$mform->addElement('hidden', 'plugin', $this->plugin); $mform->addElement('hidden', 'action', $this->action);
$mform->setType('plugin', PARAM_SAFEDIR); $mform->setType('action', PARAM_TEXT);
$mform->addElement('hidden', 'repos', $this->plugin);
$mform->setType('repos', PARAM_SAFEDIR);
// let the plugin add its specific fields // let the plugin add its specific fields
if (!$this->instance) { if (!$this->instance) {