Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Provides an overview of installed availability conditions.
  19   *
  20   * You can also enable/disable them from this screen.
  21   *
  22   * @package tool_availabilityconditions
  23   * @copyright 2014 The Open University
  24   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  require_once(__DIR__ . '/../../../config.php');
  28  require_once($CFG->libdir . '/adminlib.php');
  29  require_once($CFG->libdir . '/tablelib.php');
  30  
  31  admin_externalpage_setup('manageavailability');
  32  
  33  // Get sorted list of all availability condition plugins.
  34  $plugins = array();
  35  foreach (core_component::get_plugin_list('availability') as $plugin => $plugindir) {
  36      if (get_string_manager()->string_exists('pluginname', 'availability_' . $plugin)) {
  37          $strpluginname = get_string('pluginname', 'availability_' . $plugin);
  38      } else {
  39          $strpluginname = $plugin;
  40      }
  41      $plugins[$plugin] = $strpluginname;
  42  }
  43  core_collator::asort($plugins);
  44  
  45  // Do plugin actions.
  46  $pageurl = new moodle_url('/' . $CFG->admin . '/tool/availabilityconditions/');
  47  if (($plugin = optional_param('plugin', '', PARAM_PLUGIN))) {
  48      require_sesskey();
  49      if (!array_key_exists($plugin, $plugins)) {
  50          throw new \moodle_exception('invalidcomponent', 'error', $pageurl);
  51      }
  52      $action = required_param('action', PARAM_ALPHA);
  53      switch ($action) {
  54          case 'hide' :
  55              $class = \core_plugin_manager::resolve_plugininfo_class('availability');
  56              $class::enable_plugin($plugin, false);
  57              break;
  58          case 'show' :
  59              $class = \core_plugin_manager::resolve_plugininfo_class('availability');
  60              $class::enable_plugin($plugin, true);
  61              break;
  62      }
  63  
  64      // Always redirect back after an action.
  65      redirect($pageurl);
  66  }
  67  
  68  echo $OUTPUT->header();
  69  echo $OUTPUT->heading(get_string('manageplugins', 'availability'));
  70  
  71  // Show a table of installed availability conditions.
  72  $table = new flexible_table('availabilityconditions_administration_table');
  73  $table->define_columns(array('name', 'version', 'enable'));
  74  $table->define_headers(array(get_string('plugin'),
  75          get_string('version'), get_string('hide') . '/' . get_string('show')));
  76  $table->define_baseurl($PAGE->url);
  77  $table->set_attribute('id', 'availabilityconditions');
  78  $table->set_attribute('class', 'admintable generaltable');
  79  $table->setup();
  80  
  81  $enabledlist = core\plugininfo\availability::get_enabled_plugins();
  82  foreach ($plugins as $plugin => $name) {
  83  
  84      // Get version or ? if unknown.
  85      $version = get_config('availability_' . $plugin);
  86      if (!empty($version->version)) {
  87          $version = $version->version;
  88      } else {
  89          $version = '?';
  90      }
  91  
  92      // Get enabled status and use to grey out name if necessary.
  93      $enabled = in_array($plugin, $enabledlist);
  94      if ($enabled) {
  95          $enabledaction = 'hide';
  96          $enabledstr = get_string('hide');
  97          $class = '';
  98      } else {
  99          $enabledaction = 'show';
 100          $enabledstr = get_string('show');
 101          $class = 'dimmed_text';
 102      }
 103  
 104      // Make enable control. This is a POST request (using a form control rather
 105      // than just a link) because it makes a database change.
 106      $params = array('sesskey' => sesskey(), 'plugin' => $plugin, 'action' => $enabledaction);
 107      $url = new moodle_url('/' . $CFG->admin . '/tool/availabilityconditions/', $params);
 108      $enablecontrol = html_writer::link($url, $OUTPUT->pix_icon('t/' . $enabledaction, $enabledstr));
 109  
 110      $table->add_data([$name, $version, $enablecontrol], $class);
 111  }
 112  
 113  $table->print_html();
 114  
 115  echo $OUTPUT->footer();