Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

   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  namespace mod_feedback\external;
  18  
  19  use core\external\exporter;
  20  use renderer_base;
  21  use core_external\util as external_util;
  22  use core_external\external_files;
  23  
  24  /**
  25   * Class for exporting partial feedback data (some fields are only viewable by admins).
  26   *
  27   * @copyright  2017 Juan Leyva <juan@moodle.com>
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   * @package    mod_feedback
  30   */
  31  class feedback_summary_exporter extends exporter {
  32  
  33      protected static function define_properties() {
  34          return array(
  35              'id' => array(
  36                  'type' => PARAM_INT,
  37                  'description' => 'The primary key of the record.',
  38              ),
  39              'course' => array(
  40                  'type' => PARAM_INT,
  41                  'description' => 'Course id this feedback is part of.',
  42              ),
  43              'name' => array(
  44                  'type' => PARAM_TEXT,
  45                  'description' => 'Feedback name.',
  46              ),
  47              'intro' => array(
  48                  'default' => '',
  49                  'type' => PARAM_RAW,
  50                  'description' => 'Feedback introduction text.',
  51              ),
  52              'introformat' => array(
  53                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
  54                  'type' => PARAM_INT,
  55                  'default' => FORMAT_MOODLE,
  56                  'description' => 'Feedback intro text format.',
  57              ),
  58              'lang' => array(
  59                  'type' => PARAM_LANG,
  60                  'description' => 'Forced activity language',
  61                  'null' => NULL_ALLOWED,
  62              ),
  63              'anonymous' => array(
  64                  'type' => PARAM_INT,
  65                  'description' => 'Whether the feedback is anonymous.',
  66              ),
  67              'email_notification' => array(
  68                  'type' => PARAM_BOOL,
  69                  'optional' => true,
  70                  'description' => 'Whether email notifications will be sent to teachers.',
  71              ),
  72              'multiple_submit' => array(
  73                  'default' => 1,
  74                  'type' => PARAM_BOOL,
  75                  'description' => 'Whether multiple submissions are allowed.',
  76              ),
  77              'autonumbering' => array(
  78                  'default' => 1,
  79                  'type' => PARAM_BOOL,
  80                  'description' => 'Whether questions should be auto-numbered.',
  81              ),
  82              'site_after_submit' => array(
  83                  'type' => PARAM_TEXT,
  84                  'optional' => true,
  85                  'description' => 'Link to next page after submission.',
  86              ),
  87              'page_after_submit' => array(
  88                  'type' => PARAM_RAW,
  89                  'optional' => true,
  90                  'description' => 'Text to display after submission.',
  91              ),
  92              'page_after_submitformat' => array(
  93                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
  94                  'type' => PARAM_INT,
  95                  'default' => FORMAT_MOODLE,
  96                  'description' => 'Text to display after submission format.',
  97              ),
  98              'publish_stats' => array(
  99                  'default' => 0,
 100                  'type' => PARAM_BOOL,
 101                  'description' => 'Whether stats should be published.',
 102              ),
 103              'timeopen' => array(
 104                  'type' => PARAM_INT,
 105                  'optional' => true,
 106                  'description' => 'Allow answers from this time.',
 107              ),
 108              'timeclose' => array(
 109                  'type' => PARAM_INT,
 110                  'optional' => true,
 111                  'description' => 'Allow answers until this time.',
 112              ),
 113              'timemodified' => array(
 114                  'type' => PARAM_INT,
 115                  'optional' => true,
 116                  'description' => 'The time this record was modified.',
 117              ),
 118              'completionsubmit' => array(
 119                  'default' => 0,
 120                  'type' => PARAM_BOOL,
 121                  'description' => 'If this field is set to 1, then the activity will be automatically marked as complete on submission.',
 122              ),
 123          );
 124      }
 125  
 126      protected static function define_related() {
 127          return array(
 128              'context' => 'context'
 129          );
 130      }
 131  
 132      protected static function define_other_properties() {
 133          return array(
 134              'coursemodule' => array(
 135                  'type' => PARAM_INT
 136              ),
 137              'introfiles' => array(
 138                  'type' => external_files::get_properties_for_exporter(),
 139                  'multiple' => true
 140              ),
 141              'pageaftersubmitfiles' => array(
 142                  'type' => external_files::get_properties_for_exporter(),
 143                  'multiple' => true,
 144                  'optional' => true
 145              ),
 146          );
 147      }
 148  
 149      protected function get_other_values(renderer_base $output) {
 150          $context = $this->related['context'];
 151  
 152          $values = array(
 153              'coursemodule' => $context->instanceid,
 154          );
 155  
 156          $values['introfiles'] = external_util::get_area_files($context->id, 'mod_feedback', 'intro', false, false);
 157  
 158          if (!empty($this->data->page_after_submit)) {
 159              $values['pageaftersubmitfiles'] = external_util::get_area_files($context->id, 'mod_feedback', 'page_after_submit');
 160          }
 161  
 162          return $values;
 163      }
 164  
 165      /**
 166       * Get the formatting parameters for the intro.
 167       *
 168       * @return array
 169       */
 170      protected function get_format_parameters_for_intro() {
 171          return [
 172              'component' => 'mod_feedback',
 173              'filearea' => 'intro',
 174              'options' => array('noclean' => true),
 175          ];
 176      }
 177  
 178      /**
 179       * Get the formatting parameters for the page_after_submit.
 180       *
 181       * @return array
 182       */
 183      protected function get_format_parameters_for_page_after_submit() {
 184          return [
 185              'component' => 'mod_feedback',
 186              'filearea' => 'page_after_submit',
 187              'itemid' => 0
 188          ];
 189      }
 190  }