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 39 and 311]

   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   * This file contains the form definition for discussion export.
  19   *
  20   * @package   mod_forum
  21   * @copyright 2019 Simey Lameze <simey@moodle.com>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace mod_forum\form;
  26  
  27  defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
  28  
  29  require_once($CFG->dirroot.'/mod/forum/lib.php');
  30  require_once($CFG->libdir.'/formslib.php');
  31  
  32  /**
  33   * Export discussion form.
  34   *
  35   * @package   mod_forum
  36   * @copyright 2019 Simey Lameze <simey@moodle.com>
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL Juv3 or later
  38   */
  39  class export_form extends \moodleform {
  40  
  41      /**
  42       * Define the form - called by parent constructor
  43       */
  44      public function definition() {
  45          $mform = $this->_form;
  46          $forum = $this->_customdata['forum'];
  47  
  48          $mform->addElement('hidden', 'id');
  49          $mform->setType('id', PARAM_INT);
  50          $mform->setDefault('id', $forum->get_id());
  51  
  52          $options = [
  53              'ajax' => 'mod_forum/form-user-selector',
  54              'multiple' => true,
  55              'noselectionstring' => get_string('allusers', 'mod_forum'),
  56              'courseid' => $forum->get_course_id(),
  57                  'valuehtmlcallback' => function($value) {
  58                      global $OUTPUT;
  59  
  60                      $userfieldsapi = \core_user\fields::for_name();
  61                      $allusernames = $userfieldsapi->get_sql('', false, '', '', false)->selects;
  62                      $fields = 'id, ' . $allusernames;
  63                      $user = \core_user::get_user($value, $fields);
  64                      $useroptiondata = [
  65                          'fullname' => fullname($user),
  66                      ];
  67                      return $OUTPUT->render_from_template('mod_forum/form-user-selector-suggestion', $useroptiondata);
  68                  }
  69          ];
  70          $mform->addElement('autocomplete', 'useridsselected', get_string('users'), [], $options);
  71  
  72          // Get the discussions on this forum.
  73          $vaultfactory = \mod_forum\local\container::get_vault_factory();
  74          $discussionvault = $vaultfactory->get_discussion_vault();
  75          $discussions = array_map(function($discussion) {
  76              return $discussion->get_name();
  77          }, $discussionvault->get_all_discussions_in_forum($forum));
  78          $options = [
  79              'multiple' => true,
  80              'noselectionstring' => get_string('alldiscussions', 'mod_forum'),
  81          ];
  82          $mform->addElement('autocomplete', 'discussionids', get_string('discussions', 'mod_forum'), $discussions, $options);
  83  
  84          // Date fields.
  85          $mform->addElement('date_time_selector', 'from', get_string('postsfrom', 'mod_forum'),
  86                  ['optional' => true]);
  87          $mform->addElement('date_time_selector', 'to', get_string('poststo', 'mod_forum'),
  88                  ['optional' => true]);
  89  
  90          // Export formats.
  91          $formats = \core_plugin_manager::instance()->get_plugins_of_type('dataformat');
  92          $options = [];
  93          foreach ($formats as $format) {
  94              $options[$format->name] = $format->displayname;
  95          }
  96          $mform->addElement('select', 'format', 'Format', $options);
  97  
  98          $mform->addElement('header', 'optionsheader', get_string('exportoptions', 'mod_forum'));
  99  
 100          $mform->addElement('checkbox', 'striphtml', '', get_string('exportstriphtml', 'mod_forum'));
 101          $mform->addHelpButton('striphtml', 'exportstriphtml', 'mod_forum');
 102  
 103          $mform->addElement('checkbox', 'humandates', '', get_string('exporthumandates', 'mod_forum'));
 104          $mform->addHelpButton('humandates', 'exporthumandates', 'mod_forum');
 105  
 106          $this->add_action_buttons(true, get_string('export', 'mod_forum'));
 107      }
 108  }