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 lesson data.
  19   *
  20   * @package    mod_lesson
  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_lesson\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use core\external\exporter;
  28  use renderer_base;
  29  use external_files;
  30  use external_util;
  31  
  32  /**
  33   * Class for exporting partial lesson 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 lesson_summary_exporter extends exporter {
  39  
  40      protected static function define_properties() {
  41  
  42          return array(
  43              'id' => array(
  44                  'type' => PARAM_INT,
  45                  'description' => 'Standard Moodle primary key.'
  46              ),
  47              'course' => array(
  48                  'type' => PARAM_INT,
  49                  'description' => 'Foreign key reference to the course this lesson is part of.'
  50              ),
  51              'coursemodule' => array(
  52                  'type' => PARAM_INT,
  53                  'description' => 'Course module id.'
  54              ),
  55              'name' => array(
  56                  'type' => PARAM_RAW,
  57                  'description' => 'Lesson name.'
  58              ),
  59              'intro' => array(
  60                  'type' => PARAM_RAW,
  61                  'description' => 'Lesson introduction text.',
  62                  'optional' => true,
  63              ),
  64              'introformat' => array(
  65                  'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
  66                  'type' => PARAM_INT,
  67                  'default' => FORMAT_MOODLE
  68              ),
  69              'practice' => array(
  70                  'type' => PARAM_BOOL,
  71                  'description' => 'Practice lesson?',
  72                  'optional' => true,
  73              ),
  74              'modattempts' => array(
  75                  'type' => PARAM_BOOL,
  76                  'description' => 'Allow student review?',
  77                  'optional' => true,
  78              ),
  79              'usepassword' => array(
  80                  'type' => PARAM_BOOL,
  81                  'description' => 'Password protected lesson?',
  82                  'optional' => true,
  83              ),
  84              'password' => array(
  85                  'type' => PARAM_RAW,
  86                  'description' => 'Password',
  87                  'optional' => true,
  88              ),
  89              'dependency' => array(
  90                  'type' => PARAM_INT,
  91                  'description' => 'Dependent on (another lesson id)',
  92                  'optional' => true,
  93              ),
  94              'conditions' => array(
  95                  'type' => PARAM_RAW,
  96                  'description' => 'Conditions to enable the lesson',
  97                  'optional' => true,
  98              ),
  99              'grade' => array(
 100                  'type' => PARAM_INT,
 101                  'description' => 'The total that the grade is scaled to be out of',
 102                  'optional' => true,
 103              ),
 104              'custom' => array(
 105                  'type' => PARAM_BOOL,
 106                  'description' => 'Custom scoring?',
 107                  'optional' => true,
 108              ),
 109              'ongoing' => array(
 110                  'type' => PARAM_BOOL,
 111                  'description' => 'Display ongoing score?',
 112                  'optional' => true,
 113              ),
 114              'usemaxgrade' => array(
 115                  'type' => PARAM_INT,
 116                  'description' => 'How to calculate the final grade',
 117                  'optional' => true,
 118              ),
 119              'maxanswers' => array(
 120                  'type' => PARAM_INT,
 121                  'description' => 'Maximum answers per page',
 122                  'optional' => true,
 123              ),
 124              'maxattempts' => array(
 125                  'type' => PARAM_INT,
 126                  'description' => 'Maximum attempts',
 127                  'optional' => true,
 128              ),
 129              'review' => array(
 130                  'type' => PARAM_BOOL,
 131                  'description' => 'Provide option to try a question again',
 132                  'optional' => true,
 133              ),
 134              'nextpagedefault' => array(
 135                  'type' => PARAM_INT,
 136                  'description' => 'Action for a correct answer',
 137                  'optional' => true,
 138              ),
 139              'feedback' => array(
 140                  'type' => PARAM_BOOL,
 141                  'description' => 'Display default feedback',
 142                  'optional' => true,
 143              ),
 144              'minquestions' => array(
 145                  'type' => PARAM_INT,
 146                  'description' => 'Minimum number of questions',
 147                  'optional' => true,
 148              ),
 149              'maxpages' => array(
 150                  'type' => PARAM_INT,
 151                  'description' => 'Number of pages to show',
 152                  'optional' => true,
 153              ),
 154              'timelimit' => array(
 155                  'type' => PARAM_INT,
 156                  'description' => 'Time limit',
 157                  'optional' => true,
 158              ),
 159              'retake' => array(
 160                  'type' => PARAM_BOOL,
 161                  'description' => 'Re-takes allowed',
 162                  'optional' => true,
 163              ),
 164              'activitylink' => array(
 165                  'type' => PARAM_INT,
 166                  'description' => 'Id of the next activity to be linked once the lesson is completed',
 167                  'optional' => true,
 168              ),
 169              'mediafile' => array(
 170                  'type' => PARAM_RAW,
 171                  'description' => 'Local file path or full external URL',
 172                  'optional' => true,
 173              ),
 174              'mediaheight' => array(
 175                  'type' => PARAM_INT,
 176                  'description' => 'Popup for media file height',
 177                  'optional' => true,
 178              ),
 179              'mediawidth' => array(
 180                  'type' => PARAM_INT,
 181                  'description' => 'Popup for media with',
 182                  'optional' => true,
 183              ),
 184              'mediaclose' => array(
 185                  'type' => PARAM_INT,
 186                  'description' => 'Display a close button in the popup?',
 187                  'optional' => true,
 188              ),
 189              'slideshow' => array(
 190                  'type' => PARAM_BOOL,
 191                  'description' => 'Display lesson as slideshow',
 192                  'optional' => true,
 193              ),
 194              'width' => array(
 195                  'type' => PARAM_INT,
 196                  'description' => 'Slideshow width',
 197                  'optional' => true,
 198              ),
 199              'height' => array(
 200                  'type' => PARAM_INT,
 201                  'description' => 'Slideshow height',
 202                  'optional' => true,
 203              ),
 204              'bgcolor' => array(
 205                  'type' => PARAM_TEXT,
 206                  'description' => 'Slideshow bgcolor',
 207                  'optional' => true,
 208              ),
 209              'displayleft' => array(
 210                  'type' => PARAM_BOOL,
 211                  'description' => 'Display left pages menu?',
 212                  'optional' => true,
 213              ),
 214              'displayleftif' => array(
 215                  'type' => PARAM_INT,
 216                  'description' => 'Minimum grade to display menu',
 217                  'optional' => true,
 218              ),
 219              'progressbar' => array(
 220                  'type' => PARAM_BOOL,
 221                  'description' => 'Display progress bar?',
 222                  'optional' => true,
 223              ),
 224              'available' => array(
 225                  'type' => PARAM_INT,
 226                  'description' => 'Available from',
 227                  'optional' => true,
 228              ),
 229              'deadline' => array(
 230                  'type' => PARAM_INT,
 231                  'description' => 'Available until',
 232                  'optional' => true,
 233              ),
 234              'timemodified' => array(
 235                  'type' => PARAM_INT,
 236                  'description' => 'Last time settings were updated',
 237                  'optional' => true,
 238              ),
 239              'completionendreached' => array(
 240                  'type' => PARAM_INT,
 241                  'description' => 'Require end reached for completion?',
 242                  'optional' => true,
 243              ),
 244              'completiontimespent' => array(
 245                  'type' => PARAM_INT,
 246                  'description' => 'Student must do this activity at least for',
 247                  'optional' => true,
 248               ),
 249              'allowofflineattempts' => array(
 250                  'type' => PARAM_BOOL,
 251                  'description' => 'Whether to allow the lesson to be attempted offline in the mobile app',
 252              ),
 253          );
 254      }
 255  
 256      protected static function define_related() {
 257          return array(
 258              'context' => 'context'
 259          );
 260      }
 261  
 262      protected static function define_other_properties() {
 263          return array(
 264              'coursemodule' => array(
 265                  'type' => PARAM_INT
 266              ),
 267              'introfiles' => array(
 268                  'type' => external_files::get_properties_for_exporter(),
 269                  'multiple' => true,
 270                  'optional' => true,
 271              ),
 272              'mediafiles' => array(
 273                  'type' => external_files::get_properties_for_exporter(),
 274                  'multiple' => true,
 275                  'optional' => true,
 276              ),
 277          );
 278      }
 279  
 280      protected function get_other_values(renderer_base $output) {
 281          $context = $this->related['context'];
 282  
 283          $values = array(
 284              'coursemodule' => $context->instanceid,
 285          );
 286  
 287          if (isset($this->data->intro)) {
 288              $values['introfiles'] = external_util::get_area_files($context->id, 'mod_lesson', 'intro', false, false);
 289              $values['mediafiles'] = external_util::get_area_files($context->id, 'mod_lesson', 'mediafile', 0);
 290          }
 291  
 292          return $values;
 293      }
 294  
 295      /**
 296       * Get the formatting parameters for the intro.
 297       *
 298       * @return array
 299       */
 300      protected function get_format_parameters_for_intro() {
 301          return [
 302              'component' => 'mod_lesson',
 303              'filearea' => 'intro',
 304              'options' => array('noclean' => true),
 305          ];
 306      }
 307  }