Skip to content

Commit

Permalink
MDL-39376 enrol: Optimized setting for ldap and database
Browse files Browse the repository at this point in the history
  • Loading branch information
Darko Miletic authored and Frederic Massart committed Nov 10, 2014
1 parent 803ddf9 commit eb963e4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
6 changes: 3 additions & 3 deletions enrol/database/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@

$settings->add(new admin_setting_configtext('enrol_database/newcoursecategory', get_string('newcoursecategory', 'enrol_database'), '', ''));

if (!during_initial_install()) {
$settings->add(new admin_setting_configselect('enrol_database/defaultcategory', get_string('defaultcategory', 'enrol_database'), get_string('defaultcategory_desc', 'enrol_database'), 1, make_categories_options()));
}
require_once($CFG->dirroot.'/enrol/database/settingslib.php');

$settings->add(new enrol_database_admin_setting_category('enrol_database/defaultcategory', get_string('defaultcategory', 'enrol_database'), get_string('defaultcategory_desc', 'enrol_database')));

$settings->add(new admin_setting_configtext('enrol_database/templatecourse', get_string('templatecourse', 'enrol_database'), get_string('templatecourse_desc', 'enrol_database'), ''));
}
46 changes: 46 additions & 0 deletions enrol/database/settingslib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Database enrolment plugin custom settings.
*
* @package enrol_database
* @copyright 2013 Darko Miletic
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Class implements new specialized setting for course categories that are loaded
* only when required
* @author Darko Miletic
*
*/
class enrol_database_admin_setting_category extends admin_setting_configselect {
public function __construct($name, $visiblename, $description) {
parent::__construct($name, $visiblename, $description, 1, null);
}

public function load_choices() {
if (is_array($this->choices)) {
return true;
}

$this->choices = make_categories_options();
return true;
}
}
5 changes: 1 addition & 4 deletions enrol/ldap/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@
$settings->add(new admin_setting_heading('enrol_ldap_autocreation_settings', get_string('autocreation_settings', 'enrol_ldap'), ''));
$options = $yesno;
$settings->add(new admin_setting_configselect('enrol_ldap/autocreate', get_string('autocreate_key', 'enrol_ldap'), get_string('autocreate', 'enrol_ldap'), 0, $options));
if (!during_initial_install()) {
$options = make_categories_options();
$settings->add(new admin_setting_configselect('enrol_ldap/category', get_string('category_key', 'enrol_ldap'), get_string('category', 'enrol_ldap'), key($options), $options));
}
$settings->add(new enrol_ldap_admin_setting_category('enrol_ldap/category', get_string('category_key', 'enrol_ldap'), get_string('category', 'enrol_ldap')));
$settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/template', get_string('template_key', 'enrol_ldap'), get_string('template', 'enrol_ldap'), ''));

//--- course update settings ---
Expand Down
22 changes: 22 additions & 0 deletions enrol/ldap/settingslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,25 @@ public function output_html($data, $query='') {
$this->description, true, '', '', $query);
}
}

/**
* Class implements new specialized setting for course categories that are loaded
* only when required
* @author Darko Miletic
*
*/
class enrol_ldap_admin_setting_category extends admin_setting_configselect {
public function __construct($name, $visiblename, $description) {
parent::__construct($name, $visiblename, $description, null, null);
}

public function load_choices() {
if (is_array($this->choices)) {
return true;
}

$this->choices = make_categories_options();
$this->defaultsetting = key($this->choices);
return true;
}
}

0 comments on commit eb963e4

Please sign in to comment.