Search moodle.org's
Developer Documentation

See Release Notes

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

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 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 submission data.
  19   *
  20   * @package    mod_workshop
  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_workshop\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use core\external\exporter;
  28  use renderer_base;
  29  use core_external\util as external_util;
  30  use core_external\external_files;
  31  
  32  /**
  33   * Class for exporting submission data.
  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 submission_exporter extends exporter {
  39  
  40      protected static function define_properties() {
  41  
  42          return array(
  43              'id' => array(
  44                  'type' => PARAM_INT,
  45                  'description' => 'The primary key of the record.',
  46              ),
  47              'workshopid' => array(
  48                  'type' => PARAM_INT,
  49                  'description' => 'The id of the workshop instance.',
  50              ),
  51              'example' => array(
  52                  'type' => PARAM_BOOL,
  53                  'null' => NULL_ALLOWED,
  54                  'default' => false,
  55                  'description' => 'Is this submission an example from teacher.',
  56              ),
  57              'authorid' => array(
  58                  'type' => PARAM_INT,
  59                  'description' => 'The author of the submission.',
  60              ),
  61              'timecreated' => array(
  62                  'type' => PARAM_INT,
  63                  'description' => 'Timestamp when the work was submitted for the first time.',
  64              ),
  65              'timemodified' => array(
  66                  'type' => PARAM_INT,
  67                  'description' => 'Timestamp when the submission has been updated.',
  68              ),
  69              'title' => array(
  70                  'type' => PARAM_RAW,
  71                  'description' => 'The submission title.',
  72              ),
  73              'content' => array(
  74                  'type' => PARAM_RAW,
  75                  'null' => NULL_ALLOWED,
  76                  'description' => 'Submission text.',
  77              ),
  78              'contentformat' => array(
  79                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
  80                  'type' => PARAM_INT,
  81                  'default' => FORMAT_MOODLE,
  82                  'description' => 'Submission text format.',
  83              ),
  84              'contenttrust' => array(
  85                  'type' => PARAM_INT,
  86                  'default' => 0,
  87                  'description' => 'The trust mode of the data.',
  88              ),
  89              'attachment' => array(
  90                  'type' => PARAM_INT,
  91                  'null' => NULL_ALLOWED,
  92                  'default' => 0,
  93                  'description' => 'Used by File API file_postupdate_standard_filemanager.',
  94              ),
  95              'grade' => array(
  96                  'type' => PARAM_FLOAT,
  97                  'null' => NULL_ALLOWED,
  98                  'description' => 'Aggregated grade for the submission. The grade is a decimal number from interval 0..100.
  99                      If NULL then the grade for submission has not been aggregated yet.',
 100                  'optional' => true,
 101              ),
 102              'gradeover' => array(
 103                  'type' => PARAM_FLOAT,
 104                  'null' => NULL_ALLOWED,
 105                  'description' => 'Grade for the submission manually overridden by a teacher. Grade is always from interval 0..100.
 106                      If NULL then the grade is not overriden.',
 107                  'optional' => true,
 108              ),
 109              'gradeoverby' => array(
 110                  'type' => PARAM_INT,
 111                  'null' => NULL_ALLOWED,
 112                  'description' => 'The id of the user who has overridden the grade for submission.',
 113                  'optional' => true,
 114              ),
 115              'feedbackauthor' => array(
 116                  'type' => PARAM_RAW,
 117                  'null' => NULL_ALLOWED,
 118                  'description' => 'Teacher comment/feedback for the author of the submission, for example describing the reasons
 119                      for the grade overriding.',
 120                  'optional' => true,
 121              ),
 122              'feedbackauthorformat' => array(
 123                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
 124                  'type' => PARAM_INT,
 125                  'default' => FORMAT_MOODLE,
 126                  'description' => 'Feedback text format.',
 127              ),
 128              'timegraded' => array(
 129                  'type' => PARAM_INT,
 130                  'null' => NULL_ALLOWED,
 131                  'description' => 'The timestamp when grade or gradeover was recently modified.',
 132                  'optional' => true,
 133              ),
 134              'published' => array(
 135                  'type' => PARAM_BOOL,
 136                  'null' => NULL_ALLOWED,
 137                  'default' => false,
 138                  'description' => 'Shall the submission be available to other when the workshop is closed.',
 139              ),
 140              'late' => array(
 141                  'type' => PARAM_INT,
 142                  'default' => 0,
 143                  'description' => 'Has this submission been submitted after the deadline or during the assessment phase?',
 144              ),
 145          );
 146      }
 147  
 148      protected static function define_related() {
 149          return array(
 150              'context' => 'context'
 151          );
 152      }
 153  
 154      protected static function define_other_properties() {
 155          return array(
 156              'contentfiles' => array(
 157                  'type' => external_files::get_properties_for_exporter(),
 158                  'multiple' => true,
 159                  'optional' => true
 160              ),
 161              'attachmentfiles' => array(
 162                  'type' => external_files::get_properties_for_exporter(),
 163                  'multiple' => true,
 164                  'optional' => true
 165              ),
 166          );
 167      }
 168  
 169      protected function get_other_values(renderer_base $output) {
 170          $context = $this->related['context'];
 171  
 172          if (!empty($this->data->content)) {
 173              $values['contentfiles'] =
 174                  external_util::get_area_files($context->id, 'mod_workshop', 'submission_content', $this->data->id);
 175          }
 176  
 177          $values['attachmentfiles'] =
 178                  external_util::get_area_files($context->id, 'mod_workshop', 'submission_attachment', $this->data->id);
 179  
 180          return $values;
 181      }
 182  
 183      /**
 184       * Get the formatting parameters for the content.
 185       *
 186       * @return array
 187       */
 188      protected function get_format_parameters_for_content() {
 189          return [
 190              'component' => 'mod_workshop',
 191              'filearea' => 'submission_content',
 192              'itemid' => $this->data->id,
 193          ];
 194      }
 195  }