Search moodle.org's
Developer Documentation

See Release Notes

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

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

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