Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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   * Assign feedback subplugin info class.
  19   *
  20   * @package   mod_assign
  21   * @copyright 2013 Petr Skoda {@link http://skodak.org}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace mod_assign\plugininfo;
  25  
  26  use core\plugininfo\base, core_plugin_manager, moodle_url;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  
  31  class assignfeedback extends base {
  32      /**
  33       * Finds all enabled plugins, the result may include missing plugins.
  34       * @return array|null of enabled plugins $pluginname=>$pluginname, null means unknown
  35       */
  36      public static function get_enabled_plugins() {
  37          global $DB;
  38  
  39          $plugins = core_plugin_manager::instance()->get_installed_plugins('assignfeedback');
  40          if (!$plugins) {
  41              return array();
  42          }
  43          $installed = array();
  44          foreach ($plugins as $plugin => $version) {
  45              $installed[] = 'assignfeedback_'.$plugin;
  46          }
  47  
  48          list($installed, $params) = $DB->get_in_or_equal($installed, SQL_PARAMS_NAMED);
  49          $disabled = $DB->get_records_select('config_plugins', "plugin $installed AND name = 'disabled'", $params, 'plugin ASC');
  50          foreach ($disabled as $conf) {
  51              if (empty($conf->value)) {
  52                  continue;
  53              }
  54              list($type, $name) = explode('_', $conf->plugin, 2);
  55              unset($plugins[$name]);
  56          }
  57  
  58          $enabled = array();
  59          foreach ($plugins as $plugin => $version) {
  60              $enabled[$plugin] = $plugin;
  61          }
  62  
  63          return $enabled;
  64      }
  65  
  66      public function is_uninstall_allowed() {
  67          return true;
  68      }
  69  
  70      /**
  71       * Return URL used for management of plugins of this type.
  72       * @return moodle_url
  73       */
  74      public static function get_manage_url() {
  75          return new moodle_url('/mod/assign/adminmanageplugins.php', array('subtype'=>'assignfeedback'));
  76      }
  77  
  78      /**
  79       * Pre-uninstall hook.
  80       * @private
  81       */
  82      public function uninstall_cleanup() {
  83          global $DB;
  84  
  85          $DB->delete_records('assign_plugin_config', array('plugin'=>$this->name, 'subtype'=>'assignfeedback'));
  86  
  87          parent::uninstall_cleanup();
  88      }
  89  
  90      public function get_settings_section_name() {
  91          return $this->type . '_' . $this->name;
  92      }
  93  
  94      /**
  95       * Loads plugin settings to the settings tree
  96       *
  97       * This function usually includes settings.php file in plugins folder.
  98       * Alternatively it can create a link to some settings page (instance of admin_externalpage)
  99       *
 100       * @param \part_of_admin_tree $adminroot
 101       * @param string $parentnodename
 102       * @param bool $hassiteconfig whether the current user has moodle/site:config capability
 103       */
 104      public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
 105          global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
 106          $ADMIN = $adminroot; // May be used in settings.php.
 107          $plugininfo = $this; // Also can be used inside settings.php.
 108  
 109          if (!$this->is_installed_and_upgraded()) {
 110              return;
 111          }
 112  
 113          if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) {
 114              return;
 115          }
 116  
 117          $section = $this->get_settings_section_name();
 118  
 119          $settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
 120  
 121          if ($adminroot->fulltree) {
 122              $shortsubtype = substr($this->type, strlen('assign'));
 123              include($this->full_path('settings.php'));
 124          }
 125  
 126          $adminroot->add($this->type . 'plugins', $settings);
 127      }
 128  }