Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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   * Abstract renderer for independent renderable elements.
  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  namespace tool_dataprivacy\output;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use renderable;
  28  use renderer_base;
  29  use stdClass;
  30  use templatable;
  31  use tool_dataprivacy\external\purpose_exporter;
  32  use tool_dataprivacy\external\category_exporter;
  33  
  34  /**
  35   * Abstract renderer for independent renderable elements.
  36   *
  37   * @copyright  2018 David Monllao
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  abstract class crud_element {
  41  
  42      /**
  43       * Returns the top navigation buttons.
  44       *
  45       * @return \action_link[]
  46       */
  47      protected final function get_navigation() {
  48          $back = new \action_link(
  49              new \moodle_url('/admin/tool/dataprivacy/dataregistry.php'),
  50              get_string('back'),
  51              null,
  52              ['class' => 'btn btn-primary']
  53          );
  54          return [$back];
  55      }
  56  
  57      /**
  58       * Adds an action menu for the provided element
  59       *
  60       * @param string $elementname 'purpose' or 'category'.
  61       * @param \stdClass $exported
  62       * @param \core\persistent $persistent
  63       * @return \action_menu
  64       */
  65      protected final function action_menu($elementname, $exported, $persistent) {
  66  
  67          // Just in case, we are doing funny stuff below.
  68          $elementname = clean_param($elementname, PARAM_ALPHA);
  69  
  70          // Actions.
  71          $actionmenu = new \action_menu();
  72          $actionmenu->set_menu_trigger(get_string('actions'));
  73          $actionmenu->set_owner_selector($elementname . '-' . $exported->id . '-actions');
  74          $actionmenu->set_alignment(\action_menu::TL, \action_menu::BL);
  75  
  76          $url = new \moodle_url('/admin/tool/dataprivacy/edit' . $elementname . '.php',
  77              ['id' => $exported->id]);
  78          $link = new \action_menu_link_secondary($url, new \pix_icon('t/edit',
  79              get_string('edit')), get_string('edit'));
  80          $actionmenu->add($link);
  81  
  82          if (!$persistent->is_used()) {
  83              $url = new \moodle_url('#');
  84              $attrs = ['data-id' => $exported->id, 'data-action' => 'delete' . $elementname, 'data-name' => $exported->name];
  85              $link = new \action_menu_link_secondary($url, new \pix_icon('t/delete',
  86                  get_string('delete')), get_string('delete'), $attrs);
  87              $actionmenu->add($link);
  88          }
  89  
  90          return $actionmenu;
  91      }
  92  }