Skip to content

Commit

Permalink
MDL-15402 implementation of repositories administration. Administrato…
Browse files Browse the repository at this point in the history
…r can hide/show/sort/setup repositories. This code has been commited in order to be used by FilePicker.

Because it's doing the same thing than the filter manager, the code is similar. Some generic code need to be done (filter and repository code should use the same function, and the current generic filter lib should be refactor, at least their name). Optimization of original code should also be done if necessary.
  • Loading branch information
jerome committed Jul 31, 2008
1 parent ba44f12 commit c5d2d0d
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 30 deletions.
102 changes: 102 additions & 0 deletions admin/repositories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php // $Id$

require_once('../config.php');

$action = optional_param('action', '', PARAM_ACTION);
$repositorypath = optional_param('filterpath', '', PARAM_PATH);

require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));

$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=managereps";

if (!confirm_sesskey()) {
redirect($returnurl);
}

// get a list of installed repositories
$installedrepositories = array();
$repositorylocations = array('repository');
foreach ($repositorylocations as $repositorylocation) {
$plugins = get_list_of_plugins($repositorylocation);
foreach ($plugins as $plugin) {
$pluginpath = "$CFG->dirroot/$repositorylocation/$plugin/version.php";
if (is_readable($pluginpath)) {
$installedrepositories["$repositorylocation/$plugin"] = "$repositorylocation/$plugin";
}
}
}

// get all the currently selected repositories
if (!empty($CFG->textfilters)) {
$activerepositories = explode(',', $CFG->textfilters);
} else {
$activerepositories = array();
}

//======================
// Process Actions
//======================

switch ($action) {

case 'hide':
$key=array_search($repositorypath, $activerepositories);
// check repositorypath is valid
if ($key===false) {
break;
}
// just delete it
unset($activerepositories[$key]);
break;

case 'show':
// check repositorypath is valid
if (!array_key_exists($repositorypath, $installedrepositories)) {
print_error('filternotinstalled', 'error', $url, $repositorypath);
} elseif (array_search($repositorypath,$activerepositories)) {
// repositorypath is already active - doubleclick??
} else {
// add it to installed filters
$activerepositories[] = $repositorypath;
$activerepositories = array_unique($activerepositories);
}
break;

case 'down':
$key=array_search($repositorypath, $activerepositories);
// check repositorypath is valid
if ($key===false) {
print_error("filternotactive", 'error', $url, $repositorypath );
} elseif ($key>=(count($activerepositories)-1)) {
// cannot be moved any further down - doubleclick??
} else {
// swap with $key+1
$fsave = $activerepositories[$key];
$activerepositories[$key] = $activerepositories[$key+1];
$activerepositories[$key+1] = $fsave;
}
break;

case 'up':
$key=array_search($repositorypath, $activerepositories);
// check repositorypath is valid
if ($key===false) {
print_error("filternotactive", 'error', $url, $repositorypath );
} elseif ($key<1) {
//cannot be moved any further up - doubleclick??
} else {
// swap with $key-1
$fsave = $activerepositories[$key];
$activerepositories[$key] = $activerepositories[$key-1];
$activerepositories[$key-1] = $fsave;
}
break;
}

// save, reset cache and return
set_config('textfilters', implode(',', $activerepositories));
reset_text_filters_cache();
redirect($returnurl);

?>
53 changes: 53 additions & 0 deletions admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,59 @@
}
}

//"Repositories" menu (inside "Site Administration block" > "Modules menu")
$ADMIN->add('modules', new admin_category('repsettings', get_string('repositories')));

$temp = new admin_settingpage('managereps', get_string('repsettings', 'admin'));

if ($ADMIN->fulltree) {
$items = array();
$items[] = new admin_setting_managerepositories();
foreach ($items as $item) {
$temp->add($item);
}
}

$ADMIN->add('repsettings', $temp);

if (empty($CFG->textfilters)) {
$activerepositories = array();
} else {
$activerepositories = explode(',', $CFG->textfilters);
}

$replocations = array('repository');
foreach ($replocations as $replocation) {
$repositories = get_list_of_plugins($replocation);

$repbyname = array();

foreach ($repositories as $repository) {
$strrepname = get_string('repositoryname', "repository_$repository",null,"$CFG->dirroot/$replocation/$plugin/lang/");

if ($strrepname == '[[repositoryname]]') {
$textlib = textlib_get_instance();
$strrepname = $textlib->strtotitle($repository);
}
$repbyname[$strrepname] = "$replocation/$repository";
}
ksort($repbyname);

foreach ($repbyname as $strrepname=>$repositoryfull) {
if (file_exists("$CFG->dirroot/$repositoryfull/pluginsettings.php")) {

$settings = new admin_settingpage('version'.str_replace('/', '', $repositoryfull), $strrepname, 'moodle/site:config', !in_array($repositoryfull, $activerepositories));

if ($ADMIN->fulltree) {
include("$CFG->dirroot/$repositoryfull/pluginsettings.php");
}
$ADMIN->add('repsettings', $settings);

}
}
}
//end of admin repositories menu

$ADMIN->add('modules', new admin_category('filtersettings', get_string('managefilters')));
// "filtersettings" settingpage
$temp = new admin_settingpage('managefilters', get_string('filtersettings', 'admin'));
Expand Down
2 changes: 2 additions & 0 deletions lang/en_utf8/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@
$string['releasenoteslink'] = 'For information about this version of Moodle, please see the online <a target=\"_blank\" href=\"$a\">Release Notes</a>';
$string['remotelangnotavailable'] = 'Because Moodle can not connect to download.moodle.org, we are unable to do language pack installation automatically. Please download the appropriate zip file(s) from the list below, copy them to your $a directory and unzip them manually.';
$string['renameerrors'] = 'Rename errors';
$string['repsettings'] = 'Manage Repositories';
$string['repsettingsgeneral'] = 'General repositories settings';
$string['requiredtemplate'] = 'Required. You may use template syntax here (%%l = lastname, %%f = firstname, %%u = username). See help for details and examples.';
$string['restrictbydefault'] = 'Restrict modules by default';
$string['restrictmodulesfor'] = 'Restrict modules for';
Expand Down
2 changes: 2 additions & 0 deletions lang/en_utf8/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,8 @@
$string['renamefileto'] = 'Rename <b>$a</b> to';
$string['report'] = 'Report';
$string['reports'] = 'Reports';
$string['repositories'] = 'Repositories';
$string['repositoriesmanage'] = 'Manage Repositories';
$string['requestcourse'] = 'Request a course';
$string['requestedby'] = 'Requested by';
$string['requestreason'] = 'Reason for course request';
Expand Down
2 changes: 2 additions & 0 deletions lang/en_utf8/repositories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php //$Id$
$string['activaterep'] = 'Active repositories';
Loading

0 comments on commit c5d2d0d

Please sign in to comment.