Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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 workshop 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 external_util;
  30  use external_files;
  31  
  32  /**
  33   * Class for exporting partial workshop 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 workshop_summary_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              'course' => array(
  48                  'type' => PARAM_INT,
  49                  'description' => 'Course id this workshop is part of.',
  50              ),
  51              'name' => array(
  52                  'type' => PARAM_TEXT,
  53                  'description' => 'Workshop name.',
  54              ),
  55              'intro' => array(
  56                  'default' => '',
  57                  'type' => PARAM_RAW,
  58                  'description' => 'Workshop introduction text.',
  59                  'null' => NULL_ALLOWED,
  60              ),
  61              'introformat' => array(
  62                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
  63                  'type' => PARAM_INT,
  64                  'default' => FORMAT_MOODLE,
  65                  'description' => 'Workshop intro text format.',
  66              ),
  67              'instructauthors' => array(
  68                  'type' => PARAM_RAW,
  69                  'description' => 'Instructions for the submission phase.',
  70                  'optional' => true,
  71                  'null' => NULL_ALLOWED,
  72              ),
  73              'instructauthorsformat' => array(
  74                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
  75                  'type' => PARAM_INT,
  76                  'default' => FORMAT_MOODLE,
  77                  'description' => 'Instructions text format.',
  78              ),
  79              'instructreviewers' => array(
  80                  'type' => PARAM_RAW,
  81                  'description' => 'Instructions for the assessment phase.',
  82                  'optional' => true,
  83                  'null' => NULL_ALLOWED,
  84              ),
  85              'instructreviewersformat' => array(
  86                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
  87                  'type' => PARAM_INT,
  88                  'default' => FORMAT_MOODLE,
  89                  'description' => 'Instructions text format.',
  90              ),
  91              'timemodified' => array(
  92                  'type' => PARAM_INT,
  93                  'description' => 'The timestamp when the module was modified.',
  94                  'optional' => true,
  95              ),
  96              'phase' => array(
  97                  'type' => PARAM_INT,
  98                  'default' => 0,
  99                  'description' => 'The current phase of workshop (0 = not available, 1 = submission, 2 = assessment, 3 = closed).',
 100                  'optional' => true,
 101              ),
 102              'useexamples' => array(
 103                  'type' => PARAM_BOOL,
 104                  'default' => false,
 105                  'description' => 'Optional feature: students practise evaluating on example submissions from teacher.',
 106                  'optional' => true,
 107              ),
 108              'usepeerassessment' => array(
 109                  'type' => PARAM_BOOL,
 110                  'default' => false,
 111                  'description' => 'Optional feature: students perform peer assessment of others\' work.',
 112                  'optional' => true,
 113              ),
 114              'useselfassessment' => array(
 115                  'type' => PARAM_BOOL,
 116                  'default' => false,
 117                  'description' => 'Optional feature: students perform self assessment of their own work.',
 118                  'optional' => true,
 119              ),
 120              'grade' => array(
 121                  'type' => PARAM_FLOAT,
 122                  'default' => 80,
 123                  'description' => 'The maximum grade for submission.',
 124                  'optional' => true,
 125              ),
 126              'gradinggrade' => array(
 127                  'type' => PARAM_FLOAT,
 128                  'default' => 20,
 129                  'description' => 'The maximum grade for assessment.',
 130                  'optional' => true,
 131              ),
 132              'strategy' => array(
 133                  'type' => PARAM_PLUGIN,
 134                  'description' => 'The type of the current grading strategy used in this workshop.',
 135                  'optional' => true,
 136              ),
 137              'evaluation' => array(
 138                  'type' => PARAM_PLUGIN,
 139                  'description' => 'The recently used grading evaluation method.',
 140                  'optional' => true,
 141              ),
 142              'gradedecimals' => array(
 143                  'type' => PARAM_INT,
 144                  'default' => 0,
 145                  'description' => 'Number of digits that should be shown after the decimal point when displaying grades.',
 146                  'optional' => true,
 147              ),
 148              'submissiontypetext' => array (
 149                  'type' => PARAM_INT,
 150                  'default' => 1,
 151                  'description' => 'Indicates whether text is required as part of each submission. ' .
 152                          '0 for no, 1 for optional, 2 for required.',
 153                  'optional' => true
 154              ),
 155              'submissiontypefile' => array (
 156                  'type' => PARAM_INT,
 157                  'default' => 1,
 158                  'description' => 'Indicates whether a file upload is required as part of each submission. ' .
 159                          '0 for no, 1 for optional, 2 for required.',
 160                  'optional' => true
 161              ),
 162              'nattachments' => array(
 163                  'type' => PARAM_INT,
 164                  'default' => 1,
 165                  'description' => 'Maximum number of submission attachments.',
 166                  'optional' => true,
 167              ),
 168              'submissionfiletypes' => array(
 169                  'type' => PARAM_RAW,
 170                  'description' => 'Comma separated list of file extensions.',
 171                  'optional' => true,
 172                  'null' => NULL_ALLOWED,
 173              ),
 174              'latesubmissions' => array(
 175                  'type' => PARAM_BOOL,
 176                  'default' => false,
 177                  'description' => 'Allow submitting the work after the deadline.',
 178                  'optional' => true,
 179              ),
 180              'maxbytes' => array(
 181                  'type' => PARAM_INT,
 182                  'default' => 100000,
 183                  'description' => 'Maximum size of the one attached file.',
 184                  'optional' => true,
 185              ),
 186              'examplesmode' => array(
 187                  'type' => PARAM_INT,
 188                  'default' => 0,
 189                  'description' => '0 = example assessments are voluntary, 1 = examples must be assessed before submission,
 190                      2 = examples are available after own submission and must be assessed before peer/self assessment phase.',
 191                  'optional' => true,
 192              ),
 193              'submissionstart' => array(
 194                  'type' => PARAM_INT,
 195                  'default' => 0,
 196                  'description' => '0 = will be started manually, greater than 0 the timestamp of the start of the submission phase.',
 197                  'optional' => true,
 198              ),
 199              'submissionend' => array(
 200                  'type' => PARAM_INT,
 201                  'default' => 0,
 202                  'description' => '0 = will be closed manually, greater than 0 the timestamp of the end of the submission phase.',
 203                  'optional' => true,
 204              ),
 205              'assessmentstart' => array(
 206                  'type' => PARAM_INT,
 207                  'default' => 0,
 208                  'description' => '0 = will be started manually, greater than 0 the timestamp of the start of the assessment phase.',
 209                  'optional' => true,
 210              ),
 211              'assessmentend' => array(
 212                  'type' => PARAM_INT,
 213                  'default' => 0,
 214                  'description' => '0 = will be closed manually, greater than 0 the timestamp of the end of the assessment phase.',
 215                  'optional' => true,
 216              ),
 217              'phaseswitchassessment' => array(
 218                  'type' => PARAM_BOOL,
 219                  'default' => false,
 220                  'description' => 'Automatically switch to the assessment phase after the submissions deadline.',
 221                  'optional' => true,
 222              ),
 223              'conclusion' => array(
 224                  'type' => PARAM_RAW,
 225                  'description' => 'A text to be displayed at the end of the workshop.',
 226                  'optional' => true,
 227                  'null' => NULL_ALLOWED,
 228              ),
 229              'conclusionformat' => array(
 230                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
 231                  'type' => PARAM_INT,
 232                  'default' => FORMAT_MOODLE,
 233                  'description' => 'Workshop conclusion text format.',
 234              ),
 235              'overallfeedbackmode' => array(
 236                  'type' => PARAM_INT,
 237                  'default' => 1,
 238                  'description' => 'Mode of the overall feedback support.',
 239                  'optional' => true,
 240              ),
 241              'overallfeedbackfiles' => array(
 242                  'type' => PARAM_INT,
 243                  'default' => 0,
 244                  'description' => 'Number of allowed attachments to the overall feedback.',
 245                  'optional' => true,
 246              ),
 247              'overallfeedbackfiletypes' => array(
 248                  'type' => PARAM_RAW,
 249                  'description' => 'Comma separated list of file extensions.',
 250                  'optional' => true,
 251                  'null' => NULL_ALLOWED,
 252              ),
 253              'overallfeedbackmaxbytes' => array(
 254                  'type' => PARAM_INT,
 255                  'default' => 100000,
 256                  'description' => 'Maximum size of one file attached to the overall feedback.',
 257                  'optional' => true,
 258              ),
 259          );
 260      }
 261  
 262      protected static function define_related() {
 263          return array(
 264              'context' => 'context'
 265          );
 266      }
 267  
 268      protected static function define_other_properties() {
 269          return array(
 270              'coursemodule' => array(
 271                  'type' => PARAM_INT
 272              ),
 273              'introfiles' => array(
 274                  'type' => external_files::get_properties_for_exporter(),
 275                  'multiple' => true
 276              ),
 277              'instructauthorsfiles' => array(
 278                  'type' => external_files::get_properties_for_exporter(),
 279                  'multiple' => true,
 280                  'optional' => true
 281              ),
 282              'instructreviewersfiles' => array(
 283                  'type' => external_files::get_properties_for_exporter(),
 284                  'multiple' => true,
 285                  'optional' => true
 286              ),
 287              'conclusionfiles' => array(
 288                  'type' => external_files::get_properties_for_exporter(),
 289                  'multiple' => true,
 290                  'optional' => true
 291              ),
 292          );
 293      }
 294  
 295      protected function get_other_values(renderer_base $output) {
 296          $context = $this->related['context'];
 297  
 298          $values = array(
 299              'coursemodule' => $context->instanceid,
 300          );
 301  
 302          $values['introfiles'] = external_util::get_area_files($context->id, 'mod_workshop', 'intro', false, false);
 303  
 304          if (!empty($this->data->instructauthors)) {
 305              $values['instructauthorsfiles'] = external_util::get_area_files($context->id, 'mod_workshop', 'instructauthors');
 306          }
 307  
 308          if (!empty($this->data->instructreviewers)) {
 309              $values['instructreviewersfiles'] = external_util::get_area_files($context->id, 'mod_workshop', 'instructreviewers');
 310          }
 311  
 312          if (!empty($this->data->conclusion)) {
 313              $values['conclusionfiles'] = external_util::get_area_files($context->id, 'mod_workshop', 'conclusion');
 314          }
 315  
 316          return $values;
 317      }
 318  
 319      /**
 320       * Get the formatting parameters for the intro.
 321       *
 322       * @return array with the formatting parameters
 323       */
 324      protected function get_format_parameters_for_intro() {
 325          return [
 326              'component' => 'mod_workshop',
 327              'filearea' => 'intro',
 328              'options' => array('noclean' => true),
 329          ];
 330      }
 331  
 332      /**
 333       * Get the formatting parameters for the instructauthors.
 334       *
 335       * @return array with the formatting parameters
 336       */
 337      protected function get_format_parameters_for_instructauthors() {
 338          return [
 339              'component' => 'mod_workshop',
 340              'filearea' => 'instructauthors',
 341              'itemid' => 0
 342          ];
 343      }
 344  
 345      /**
 346       * Get the formatting parameters for the instructreviewers.
 347       *
 348       * @return array with the formatting parameters
 349       */
 350      protected function get_format_parameters_for_instructreviewers() {
 351          return [
 352              'component' => 'mod_workshop',
 353              'filearea' => 'instructreviewers',
 354              'itemid' => 0
 355          ];
 356      }
 357  
 358      /**
 359       * Get the formatting parameters for the conclusion.
 360       *
 361       * @return array with the formatting parameters
 362       */
 363      protected function get_format_parameters_for_conclusion() {
 364          return [
 365              'component' => 'mod_workshop',
 366              'filearea' => 'conclusion',
 367              'itemid' => 0
 368          ];
 369      }
 370  }