forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MDL-44070-master' of https://github.com/sammarshallou/m…
…oodle Conflicts: theme/bootstrapbase/less/moodle/forms.less theme/bootstrapbase/style/moodle.css version.php
- Loading branch information
Showing
163 changed files
with
17,194 additions
and
3,123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Provides an overview of installed availability conditions. | ||
* | ||
* You can also enable/disable them from this screen. | ||
* | ||
* @package tool_availabilityconditions | ||
* @copyright 2014 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require_once(__DIR__ . '/../../../config.php'); | ||
require_once($CFG->libdir . '/adminlib.php'); | ||
require_once($CFG->libdir . '/tablelib.php'); | ||
|
||
admin_externalpage_setup('manageavailability'); | ||
|
||
// Get sorted list of all availability condition plugins. | ||
$plugins = array(); | ||
foreach (core_component::get_plugin_list('availability') as $plugin => $plugindir) { | ||
if (get_string_manager()->string_exists('pluginname', 'availability_' . $plugin)) { | ||
$strpluginname = get_string('pluginname', 'availability_' . $plugin); | ||
} else { | ||
$strpluginname = $plugin; | ||
} | ||
$plugins[$plugin] = $strpluginname; | ||
} | ||
core_collator::asort($plugins); | ||
|
||
// Do plugin actions. | ||
$pageurl = new moodle_url('/' . $CFG->admin . '/availabilityconditions.php'); | ||
if (($plugin = optional_param('plugin', '', PARAM_PLUGIN))) { | ||
require_sesskey(); | ||
if (!array_key_exists($plugin, $plugins)) { | ||
print_error('invalidcomponent', 'error', $pageurl); | ||
} | ||
$action = required_param('action', PARAM_ALPHA); | ||
switch ($action) { | ||
case 'hide' : | ||
set_config('disabled', 1, 'availability_' . $plugin); | ||
break; | ||
case 'show' : | ||
unset_config('disabled', 'availability_' . $plugin); | ||
break; | ||
} | ||
core_plugin_manager::reset_caches(); | ||
|
||
// Always redirect back after an action. | ||
redirect($pageurl); | ||
} | ||
|
||
echo $OUTPUT->header(); | ||
echo $OUTPUT->heading(get_string('manageplugins', 'availability')); | ||
|
||
// Show a table of installed availability conditions. | ||
$table = new flexible_table('availabilityconditions_administration_table'); | ||
$table->define_columns(array('name', 'version', 'enable')); | ||
$table->define_headers(array(get_string('plugin'), | ||
get_string('version'), get_string('hide') . '/' . get_string('show'))); | ||
$table->define_baseurl($PAGE->url); | ||
$table->set_attribute('id', 'availabilityconditions'); | ||
$table->set_attribute('class', 'admintable generaltable'); | ||
$table->setup(); | ||
|
||
$enabledlist = core\plugininfo\availability::get_enabled_plugins(); | ||
foreach ($plugins as $plugin => $name) { | ||
|
||
// Get version or ? if unknown. | ||
$version = get_config('availability_' . $plugin); | ||
if (!empty($version->version)) { | ||
$version = $version->version; | ||
} else { | ||
$version = '?'; | ||
} | ||
|
||
// Get enabled status and use to grey out name if necessary. | ||
$enabled = in_array($plugin, $enabledlist); | ||
if ($enabled) { | ||
$enabledaction = 'hide'; | ||
$enabledstr = get_string('hide'); | ||
$class = ''; | ||
} else { | ||
$enabledaction = 'show'; | ||
$enabledstr = get_string('show'); | ||
$class = 'dimmed_text'; | ||
} | ||
$namespan = html_writer::span($name, $class); | ||
|
||
// Make enable control. This is a POST request (using a form control rather | ||
// than just a link) because it makes a database change. | ||
$targeturl = new moodle_url('availabilityconditions.php', array( | ||
'plugin' => $plugin, 'action' => $enabledaction, 'sesskey' => sesskey())); | ||
$enablecontrol = html_writer::tag('form', html_writer::div( | ||
html_writer::empty_tag('input', array('type' => 'hidden', | ||
'name' => 'sesskey', 'value' => sesskey())) . | ||
html_writer::empty_tag('input', array('type' => 'hidden', | ||
'name' => 'plugin', 'value' => $plugin)) . | ||
html_writer::empty_tag('input', array('type' => 'hidden', | ||
'name' => 'action', 'value' => $enabledaction)) . | ||
html_writer::empty_tag('input', array('type' => 'image', | ||
'src' => $OUTPUT->pix_url('t/' . $enabledaction), 'alt' => $enabledstr, | ||
'title' => $enabledstr)) | ||
), array( | ||
'method' => 'post', 'action' => 'availabilityconditions.php')); | ||
|
||
$table->add_data(array($namespan, $version, $enablecontrol)); | ||
} | ||
|
||
$table->print_html(); | ||
|
||
echo $OUTPUT->footer(); |
26 changes: 26 additions & 0 deletions
26
admin/tool/availabilityconditions/lang/en/tool_availabilityconditions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Strings for availability conditions options. | ||
* | ||
* @package core_availability | ||
* @copyright 2014 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
$string['manageplugins'] = 'Manage restrictions'; | ||
$string['pluginname'] = 'Availability condition management'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Adds settings links to admin tree. | ||
* | ||
* @package tool_availabilityconditions | ||
* @copyright 2014 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
if ($hassiteconfig) { | ||
$ADMIN->add('modules', new admin_category('availabilitysettings', | ||
new lang_string('type_availability_plural', 'plugin'))); | ||
$ADMIN->add('availabilitysettings', new admin_externalpage('manageavailability', | ||
new lang_string('manageplugins', 'tool_availabilityconditions'), | ||
$CFG->wwwroot . '/' . $CFG->admin . '/tool/availabilityconditions/')); | ||
foreach (core_plugin_manager::instance()->get_plugins_of_type('availability') as $plugin) { | ||
/** @var \core\plugininfo\format $plugin */ | ||
$plugin->load_settings($ADMIN, 'availabilitysettings', $hassiteconfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Version | ||
* | ||
* @package tool_availabilityconditions | ||
* @copyright 2014 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$plugin->version = 2014012900; | ||
$plugin->requires = 2014040401; | ||
$plugin->component = 'tool_availabilityconditions'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Used while evaluating conditions in bulk. | ||
* | ||
* This object caches get_users_by_capability results in case they are needed | ||
* by multiple conditions. | ||
* | ||
* @package core_availability | ||
* @copyright 2014 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_availability; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Used while evaluating conditions in bulk. | ||
* | ||
* This object caches get_users_by_capability results in case they are needed | ||
* by multiple conditions. | ||
* | ||
* @package core_availability | ||
* @copyright 2014 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class capability_checker { | ||
/** @var \context Course or module context */ | ||
protected $context; | ||
|
||
/** @var array Associative array of capability => result */ | ||
protected $cache = array(); | ||
|
||
/** | ||
* Constructs for given context. | ||
* | ||
* @param \context $context Context | ||
*/ | ||
public function __construct(\context $context) { | ||
$this->context = $context; | ||
} | ||
|
||
/** | ||
* Gets users on course who have the specified capability. Returns an array | ||
* of user objects which only contain the 'id' field. If the same capability | ||
* has already been checked (e.g. by another condition) then a cached | ||
* result will be used. | ||
* | ||
* More fields are not necessary because this code is only used to filter | ||
* users from an existing list. | ||
* | ||
* @param string $capability Required capability | ||
* @return array Associative array of user id => objects containing only id | ||
*/ | ||
public function get_users_by_capability($capability) { | ||
if (!array_key_exists($capability, $this->cache)) { | ||
$this->cache[$capability] = get_users_by_capability( | ||
$this->context, $capability, 'u.id'); | ||
} | ||
return $this->cache[$capability]; | ||
} | ||
} |
Oops, something went wrong.