Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 402] [Versions 311 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   * Provides {@link tool_policy\output\renderer} class.
  19   *
  20   * @package     tool_policy
  21   * @category    output
  22   * @copyright   2018 Sara Arjona <sara@moodle.com>
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace tool_policy\output;
  27  
  28  use moodle_exception;
  29  
  30  defined('MOODLE_INTERNAL') || die();
  31  
  32  require_once("$CFG->libdir/filelib.php");
  33  
  34  use context_system;
  35  use moodle_url;
  36  use renderable;
  37  use renderer_base;
  38  use single_button;
  39  use templatable;
  40  use tool_policy\api;
  41  use tool_policy\policy_version;
  42  
  43  /**
  44   * Represents a page for showing all the policy documents with a current version.
  45   *
  46   * @copyright 2018 Sara Arjona <sara@moodle.com>
  47   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  48   */
  49  class page_viewalldoc implements renderable, templatable {
  50  
  51      /** @var ?moodle_url Return url */
  52      private $returnurl = null;
  53  
  54      /**
  55       * Prepare the page for rendering.
  56       *
  57       */
  58      public function __construct($returnurl) {
  59          if (!empty($returnurl)) {
  60              $this->returnurl = new moodle_url($returnurl);
  61          }
  62  
  63          $this->prepare_global_page_access();
  64          $this->prepare_policies();
  65      }
  66  
  67      /**
  68       * Loads the policy versions to display on the page.
  69       *
  70       */
  71      protected function prepare_policies() {
  72          $this->policies = api::list_current_versions();
  73      }
  74  
  75      /**
  76       * Sets up the global $PAGE and performs the access checks.
  77       */
  78      protected function prepare_global_page_access() {
  79          global $PAGE, $SITE, $USER;
  80  
  81          $myurl = new moodle_url('/admin/tool/policy/viewall.php', []);
  82  
  83          // Disable notifications for new users, guests or users who haven't agreed to the policies.
  84          if (isguestuser() || empty($USER->id) || !$USER->policyagreed) {
  85              $PAGE->set_popup_notification_allowed(false);
  86          }
  87  
  88          $PAGE->set_context(context_system::instance());
  89          $PAGE->set_pagelayout('popup');
  90          $PAGE->set_url($myurl);
  91          $PAGE->set_heading($SITE->fullname);
  92          $PAGE->set_title(get_string('policiesagreements', 'tool_policy'));
  93      }
  94  
  95      /**
  96       * Export the page data for the mustache template.
  97       *
  98       * @param renderer_base $output renderer to be used to render the page elements.
  99       * @return stdClass
 100       */
 101      public function export_for_template(renderer_base $output) {
 102  
 103          $data = (object) [
 104              'pluginbaseurl' => (new moodle_url('/admin/tool/policy'))->out(false),
 105          ];
 106  
 107          $data->policies = array_values($this->policies);
 108          if (!empty($this->returnurl)) {
 109              $data->returnurl = $this->returnurl;
 110          }
 111  
 112          array_walk($data->policies, function($item, $key) {
 113              $item->policytypestr = get_string('policydoctype'.$item->type, 'tool_policy');
 114              $item->policyaudiencestr = get_string('policydocaudience'.$item->audience, 'tool_policy');
 115          });
 116  
 117          return $data;
 118      }
 119  }