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   * Class for exporting calendar footer view options data.
  19   *
  20   * @package    core_calendar
  21   * @copyright  2017 Simey Lameze <simey@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core_calendar\external;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  use core\external\exporter;
  29  use renderer_base;
  30  use stdClass;
  31  use moodle_url;
  32  
  33  /**
  34   * Class for exporting calendar footer view options data.
  35   *
  36   * @copyright  2017 Simey Lameze
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class footer_options_exporter extends exporter {
  40  
  41      /**
  42       * @var \calendar_information $calendar The calendar to be rendered.
  43       */
  44      protected $calendar;
  45  
  46      /**
  47       * @var int $userid The user id.
  48       */
  49      protected $userid;
  50  
  51      /**
  52       * @var string $token The user sha1 token.
  53       */
  54      protected $token;
  55  
  56      /**
  57       * Constructor for month_exporter.
  58       *
  59       * @param \calendar_information $calendar The calendar being represented
  60       * @param int $userid The user id
  61       * @param string $token The user sha1 token.
  62       */
  63      public function __construct(\calendar_information $calendar, $userid, $token) {
  64          $this->calendar = $calendar;
  65          $this->userid = $userid;
  66          $this->token = $token;
  67      }
  68  
  69      /**
  70       * Get the export calendar button.
  71       *
  72       * @return \single_button The export calendar button html.
  73       */
  74      protected function get_export_calendar_button() {
  75          $exportcalendarurl = new moodle_url('/calendar/export.php', $this->get_link_params());
  76          return new \single_button($exportcalendarurl, get_string('exportcalendar', 'calendar'), 'get');
  77      }
  78  
  79      /**
  80       * Get manage subscription button.
  81       *
  82       * @return string The manage subscription button html.
  83       */
  84      protected function get_manage_subscriptions_button() {
  85          if (calendar_user_can_add_event($this->calendar->course)) {
  86              $managesubscriptionurl = new moodle_url('/calendar/managesubscriptions.php', $this->get_link_params());
  87              return new \single_button($managesubscriptionurl,
  88                      get_string('managesubscriptions', 'calendar'), 'get');
  89          }
  90      }
  91  
  92      /**
  93       * Get the list of URL parameters for calendar links.
  94       *
  95       * @return array
  96       */
  97      protected function get_link_params() {
  98          $params = [];
  99          if (SITEID !== $this->calendar->course->id) {
 100              $params['course'] = $this->calendar->course->id;
 101          } else if (null !== $this->calendar->categoryid && $this->calendar->categoryid > 0) {
 102              $params['category'] = $this->calendar->categoryid;
 103          }
 104  
 105          return $params;
 106      }
 107  
 108      /**
 109       * Get the additional values to inject while exporting.
 110       *
 111       * @param renderer_base $output The renderer.
 112       * @return array Keys are the property names, values are their values.
 113       */
 114      protected function get_other_values(renderer_base $output) {
 115          global $CFG;
 116  
 117          $values = new stdClass();
 118  
 119          if (!empty($CFG->enablecalendarexport)) {
 120              if ($exportbutton = $this->get_export_calendar_button()) {
 121                  $values->exportcalendarbutton = $exportbutton->export_for_template($output);
 122              }
 123              if ($managesubscriptionbutton = $this->get_manage_subscriptions_button()) {
 124                  $values->managesubscriptionbutton = $managesubscriptionbutton->export_for_template($output);
 125              }
 126          }
 127  
 128          return (array) $values;
 129      }
 130  
 131      /**
 132       * Return the list of additional properties.
 133       *
 134       * @return array
 135       */
 136      public static function define_other_properties() {
 137          return array(
 138              'exportcalendarbutton' => [
 139                  'type' => PARAM_RAW,
 140                  'default' => null,
 141              ],
 142              'managesubscriptionbutton' => [
 143                  'type' => PARAM_RAW,
 144                  'default' => null,
 145              ],
 146          );
 147      }
 148  }