Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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   * This page lets users manage default purposes and categories.
  19   *
  20   * @package    tool_dataprivacy
  21   * @copyright  2018 David Monllao
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../../config.php');
  26  require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/dataprivacy/lib.php');
  27  
  28  require_login(null, false);
  29  
  30  $url = new \moodle_url('/admin/tool/dataprivacy/defaults.php');
  31  $title = get_string('setdefaults', 'tool_dataprivacy');
  32  
  33  \tool_dataprivacy\page_helper::setup($url, $title, 'dataregistry');
  34  
  35  $mode = optional_param('mode', CONTEXT_COURSECAT, PARAM_INT);
  36  $classname = context_helper::get_class_for_level($mode);
  37  list($purposevar, $categoryvar) = \tool_dataprivacy\data_registry::var_names_from_context($classname);
  38  $purpose = get_config('tool_dataprivacy', $purposevar);
  39  $category = get_config('tool_dataprivacy', $categoryvar);
  40  
  41  $otherdefaults = [];
  42  if ($mode == CONTEXT_MODULE) {
  43      // Get activity module plugin info.
  44      $pluginmanager = core_plugin_manager::instance();
  45      $modplugins = $pluginmanager->get_enabled_plugins('mod');
  46  
  47      foreach ($modplugins as $name) {
  48          list($purposevar, $categoryvar) = \tool_dataprivacy\data_registry::var_names_from_context($classname, $name);
  49          $plugincategory = get_config('tool_dataprivacy', $categoryvar);
  50          $pluginpurpose = get_config('tool_dataprivacy', $purposevar);
  51          if ($plugincategory === false && $pluginpurpose === false) {
  52              // If no purpose and category has been set for this plugin, then there's no need to show this on the list.
  53              continue;
  54          }
  55  
  56          $displayname = $pluginmanager->plugin_name('mod_' . $name);
  57          $otherdefaults[$name] = (object)[
  58              'name' => $displayname,
  59              'category' => $plugincategory,
  60              'purpose' => $pluginpurpose,
  61          ];
  62      }
  63  }
  64  
  65  $defaultspage = new \tool_dataprivacy\output\defaults_page($mode, $category, $purpose, $otherdefaults, true);
  66  
  67  $output = $PAGE->get_renderer('tool_dataprivacy');
  68  echo $output->header();
  69  echo $output->heading($title);
  70  echo $output->render_from_template('tool_dataprivacy/defaults_page', $defaultspage->export_for_template($output));
  71  echo $output->footer();