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 assessment 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 assessment 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 assessment_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              'submissionid' => array(
  48                  'type' => PARAM_INT,
  49                  'description' => 'The id of the assessed submission',
  50              ),
  51              'reviewerid' => array(
  52                  'type' => PARAM_INT,
  53                  'description' => 'The id of the reviewer who makes this assessment',
  54              ),
  55              'weight' => array(
  56                  'type' => PARAM_INT,
  57                  'default' => 1,
  58                  'description' => 'The weight of the assessment for the purposes of aggregation',
  59              ),
  60              'timecreated' => array(
  61                  'type' => PARAM_INT,
  62                  'null' => NULL_ALLOWED,
  63                  'default' => 0,
  64                  'description' => 'If 0 then the assessment was allocated but the reviewer has not assessed yet.
  65                      If greater than 0 then the timestamp of when the reviewer assessed for the first time',
  66              ),
  67              'timemodified' => array(
  68                  'type' => PARAM_INT,
  69                  'null' => NULL_ALLOWED,
  70                  'default' => 0,
  71                  'description' => 'If 0 then the assessment was allocated but the reviewer has not assessed yet.
  72                      If greater than 0 then the timestamp of when the reviewer assessed for the last time',
  73              ),
  74              'grade' => array(
  75                  'type' => PARAM_FLOAT,
  76                  'null' => NULL_ALLOWED,
  77                  'description' => 'The aggregated grade for submission suggested by the reviewer.
  78                      The grade 0..100 is computed from the values assigned to the assessment dimensions fields. If NULL then it has not been aggregated yet.',
  79              ),
  80              'gradinggrade' => array(
  81                  'type' => PARAM_FLOAT,
  82                  'null' => NULL_ALLOWED,
  83                  'description' => 'The computed grade 0..100 for this assessment. If NULL then it has not been computed yet.',
  84              ),
  85              'gradinggradeover' => array(
  86                  'type' => PARAM_FLOAT,
  87                  'null' => NULL_ALLOWED,
  88                  'description' => 'Grade for the assessment manually overridden by a teacher.
  89                      Grade is always from interval 0..100. If NULL then the grade is not overriden.',
  90              ),
  91              'gradinggradeoverby' => array(
  92                  'type' => PARAM_INT,
  93                  'null' => NULL_ALLOWED,
  94                  'description' => 'The id of the user who has overridden the grade for submission.',
  95              ),
  96              'feedbackauthor' => array(
  97                  'type' => PARAM_RAW,
  98                  'null' => NULL_ALLOWED,
  99                  'description' => 'The comment/feedback from the reviewer for the author.',
 100              ),
 101              'feedbackauthorformat' => array(
 102                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
 103                  'type' => PARAM_INT,
 104                  'default' => FORMAT_MOODLE,
 105                  'description' => 'Feedback text format.',
 106              ),
 107              'feedbackauthorattachment' => array(
 108                  'type' => PARAM_INT,
 109                  'null' => NULL_ALLOWED,
 110                  'default' => 0,
 111                  'description' => 'Are there some files attached to the feedbackauthor field?
 112                      Sets to 1 by file_postupdate_standard_filemanager().',
 113              ),
 114              'feedbackreviewer' => array(
 115                  'type' => PARAM_RAW,
 116                  'null' => NULL_ALLOWED,
 117                  'description' => 'The comment/feedback from the teacher for the reviewer.
 118                      For example the reason why the grade for assessment was overridden',
 119                  'optional' => true,
 120              ),
 121              'feedbackreviewerformat' => array(
 122                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
 123                  'type' => PARAM_INT,
 124                  'default' => FORMAT_MOODLE,
 125                  'description' => 'Feedback text format.',
 126              ),
 127  
 128              'feedbackauthorformat' => array(
 129                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
 130                  'type' => PARAM_INT,
 131                  'default' => FORMAT_MOODLE,
 132                  'description' => 'Feedback text format.',
 133              ),
 134          );
 135      }
 136  
 137      protected static function define_related() {
 138          return array(
 139              'context' => 'context'
 140          );
 141      }
 142  
 143      protected static function define_other_properties() {
 144          return array(
 145              'feedbackcontentfiles' => array(
 146                  'type' => external_files::get_properties_for_exporter(),
 147                  'multiple' => true,
 148              ),
 149              'feedbackattachmentfiles' => array(
 150                  'type' => external_files::get_properties_for_exporter(),
 151                  'multiple' => true,
 152              ),
 153          );
 154      }
 155  
 156      protected function get_other_values(renderer_base $output) {
 157          $context = $this->related['context'];
 158  
 159          $values['feedbackcontentfiles'] =
 160                  external_util::get_area_files($context->id, 'mod_workshop', 'overallfeedback_content', $this->data->id);
 161          $values['feedbackattachmentfiles'] =
 162                  external_util::get_area_files($context->id, 'mod_workshop', 'overallfeedback_attachment', $this->data->id);
 163  
 164          return $values;
 165      }
 166  
 167      /**
 168       * Get the formatting parameters for the content.
 169       *
 170       * @return array
 171       */
 172      protected function get_format_parameters_for_feedbackauthor() {
 173          return [
 174              'component' => 'mod_workshop',
 175              'filearea' => 'overallfeedback_content',
 176              'itemid' => $this->data->id,
 177          ];
 178      }
 179  }