Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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   * Summary page renderable.
  19   *
  20   * @package    tool_dataprivacy
  21   * @copyright  2018 Adrian Greeve
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace tool_dataprivacy\output;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use renderable;
  28  use renderer_base;
  29  use templatable;
  30  
  31  
  32  /**
  33   * Class containing the summary page renderable.
  34   *
  35   * @copyright  2018 Adrian Greeve
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class summary_page implements renderable, templatable {
  39  
  40      /**
  41       * Export this data so it can be used as the context for a mustache template.
  42       *
  43       * @param renderer_base $output
  44       * @return array
  45       */
  46      public function export_for_template(renderer_base $output) {
  47          $contextlevels = [
  48              'contextlevelname10' => CONTEXT_SYSTEM,
  49              'contextlevelname30' => CONTEXT_USER,
  50              'contextlevelname40' => CONTEXT_COURSECAT,
  51              'contextlevelname50' => CONTEXT_COURSE,
  52              'contextlevelname70' => CONTEXT_MODULE,
  53              'contextlevelname80' => CONTEXT_BLOCK
  54          ];
  55  
  56          $data = [];
  57          $context = \context_system::instance();
  58  
  59          foreach ($contextlevels as $levelname => $level) {
  60              $classname = \context_helper::get_class_for_level($level);
  61              list($purposevar, $categoryvar) = \tool_dataprivacy\data_registry::var_names_from_context($classname);
  62              $purposeid = get_config('tool_dataprivacy', $purposevar);
  63              $categoryid = get_config('tool_dataprivacy', $categoryvar);
  64  
  65              $section = [];
  66              $section['contextname'] = get_string($levelname, 'tool_dataprivacy');
  67  
  68              if (empty($purposeid)) {
  69                  list($purposeid, $categoryid) =
  70                          \tool_dataprivacy\data_registry::get_effective_default_contextlevel_purpose_and_category($level);
  71              }
  72              if ($purposeid == -1) {
  73                  $purposeid = 0;
  74              }
  75              $purpose = new \tool_dataprivacy\purpose($purposeid);
  76              $export = new \tool_dataprivacy\external\purpose_exporter($purpose, ['context' => $context]);
  77              $purposedata = $export->export($output);
  78              $section['purpose'] = $purposedata;
  79  
  80              if (empty($categoryid)) {
  81                  list($purposeid, $categoryid) =
  82                          \tool_dataprivacy\data_registry::get_effective_default_contextlevel_purpose_and_category($level);
  83              }
  84              if ($categoryid == -1) {
  85                  $categoryid = 0;
  86              }
  87              $category = new \tool_dataprivacy\category($categoryid);
  88              $export = new \tool_dataprivacy\external\category_exporter($category, ['context' => $context]);
  89              $categorydata = $export->export($output);
  90              $section['category'] = $categorydata;
  91              $data['contexts'][] = $section;
  92          }
  93  
  94          // Get activity module plugin info.
  95          $pluginmanager = \core_plugin_manager::instance();
  96          $modplugins = $pluginmanager->get_enabled_plugins('mod');
  97  
  98          foreach ($modplugins as $name) {
  99              $classname = \context_helper::get_class_for_level($contextlevels['contextlevelname70']);
 100              list($purposevar, $categoryvar) = \tool_dataprivacy\data_registry::var_names_from_context($classname, $name);
 101              $categoryid = get_config('tool_dataprivacy', $categoryvar);
 102              $purposeid = get_config('tool_dataprivacy', $purposevar);
 103              if ($categoryid === false && $purposeid === false) {
 104                  // If no purpose and category has been set for this plugin, then there's no need to show this on the list.
 105                  continue;
 106              }
 107  
 108              $section = [];
 109              $section['contextname'] = $pluginmanager->plugin_name('mod_' . $name);
 110  
 111              if ($purposeid == -1) {
 112                  $purposeid = 0;
 113              }
 114              $purpose = new \tool_dataprivacy\purpose($purposeid);
 115              $export = new \tool_dataprivacy\external\purpose_exporter($purpose, ['context' => $context]);
 116              $purposedata = $export->export($output);
 117              $section['purpose'] = $purposedata;
 118  
 119              if ($categoryid == -1) {
 120                  $categoryid = 0;
 121              }
 122              $category = new \tool_dataprivacy\category($categoryid);
 123              $export = new \tool_dataprivacy\external\category_exporter($category, ['context' => $context]);
 124              $categorydata = $export->export($output);
 125              $section['category'] = $categorydata;
 126  
 127              $data['contexts'][] = $section;
 128          }
 129  
 130          return $data;
 131      }
 132  }