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