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.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   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   * The mform for exporting calendar events
  19   *
  20   * @package core_calendar
  21   * @copyright 2014 Brian Barnes
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  // Always include formslib.
  26  if (!defined('MOODLE_INTERNAL')) {
  27      die('Direct access to this script is forbidden.');    // It must be included from a Moodle page.
  28  }
  29  
  30  require_once($CFG->dirroot.'/lib/formslib.php');
  31  
  32  /**
  33   * The mform class for creating and editing a calendar
  34   *
  35   * @copyright 2014 Brian Barnes
  36   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class core_calendar_export_form extends moodleform {
  39  
  40      /**
  41       * The export form definition
  42       * @throws coding_exception
  43       */
  44      public function definition() {
  45          global $CFG;
  46          $mform = $this->_form;
  47          $mform->addElement('html', '<div class="mt-3 mb-xl-6">' . get_string('exporthelp', 'calendar') . '</div>');
  48  
  49          $export = array();
  50          $export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventsall', 'calendar'), 'all');
  51          $export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventsrelatedtocategories', 'calendar'), 'categories');
  52          $export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventsrelatedtocourses', 'calendar'), 'courses');
  53          $export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventsrelatedtogroups', 'calendar'), 'groups');
  54          $export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventspersonal', 'calendar'), 'user');
  55  
  56          $mform->addGroup($export, 'events', get_string('eventstoexport', 'calendar'), '<br/>');
  57          $mform->addGroupRule('events', get_string('required'), 'required');
  58          $mform->setDefault('events', 'all');
  59  
  60          $range = array();
  61          if ($this->_customdata['allowthisweek']) {
  62              $range[] = $mform->createElement('radio', 'timeperiod', '', get_string('weekthis', 'calendar'), 'weeknow');
  63          }
  64          if ($this->_customdata['allownextweek']) {
  65              $range[] = $mform->createElement('radio', 'timeperiod', '', get_string('weeknext', 'calendar'), 'weeknext');
  66          }
  67          $range[] = $mform->createElement('radio', 'timeperiod', '', get_string('monththis', 'calendar'), 'monthnow');
  68          if ($this->_customdata['allownextmonth']) {
  69              $range[] = $mform->createElement('radio', 'timeperiod', '', get_string('monthnext', 'calendar'), 'monthnext');
  70          }
  71          $range[] = $mform->createElement('radio', 'timeperiod', '', get_string('recentupcoming', 'calendar'), 'recentupcoming');
  72  
  73          if ($CFG->calendar_customexport) {
  74              $a = new stdClass();
  75              $now = time();
  76              $time = $now - $CFG->calendar_exportlookback * DAYSECS;
  77              $a->timestart = userdate($time, get_string('strftimedatefullshort', 'langconfig'));
  78              $time = $now + $CFG->calendar_exportlookahead * DAYSECS;
  79              $a->timeend = userdate($time, get_string('strftimedatefullshort', 'langconfig'));
  80  
  81              $range[] = $mform->createElement('radio', 'timeperiod', '', get_string('customexport', 'calendar', $a), 'custom');
  82          }
  83  
  84          $mform->addGroup($range, 'period', get_string('timeperiod', 'calendar'), '<br/>');
  85          $mform->addGroupRule('period', get_string('required'), 'required');
  86          $mform->setDefault('period', 'recentupcoming');
  87  
  88          $buttons = array();
  89          $buttons[] = $mform->createElement('submit', 'generateurl', get_string('generateurlbutton', 'calendar'));
  90          $buttons[] = $mform->createElement('submit', 'export', get_string('exportbutton', 'calendar'));
  91          $mform->addGroup($buttons);
  92      }
  93  }