Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

   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  defined('MOODLE_INTERNAL') || die();
  18  
  19  require_once($CFG->dirroot . '/course/format/lib.php');
  20  
  21  /**
  22   * Fixture for fake course format testing course format API.
  23   *
  24   * @package    core_course
  25   * @copyright  2014 Marina Glancy
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  class format_theunittest extends format_base {
  29  
  30      /**
  31       * Definitions of the additional options that format uses
  32       *
  33       * @param bool $foreditform
  34       * @return array of options
  35       */
  36      public function course_format_options($foreditform = false) {
  37          static $courseformatoptions = false;
  38          if ($courseformatoptions === false) {
  39              $courseformatoptions = array(
  40                  'hideoddsections' => array(
  41                      'default' => 0,
  42                      'type' => PARAM_INT,
  43                  ),
  44                  'summary_editor' => array(
  45                      'default' => '',
  46                      'type' => PARAM_RAW,
  47                  ),
  48              );
  49          }
  50          if ($foreditform && !isset($courseformatoptions['hideoddsections']['label'])) {
  51              $sectionmenu = array(
  52                  0 => 'Never',
  53                  1 => 'Hide without notice',
  54                  2 => 'Hide with notice'
  55              );
  56              $courseformatoptionsedit = array(
  57                  'hideoddsections' => array(
  58                      'label' => 'Hide odd sections',
  59                      'element_type' => 'select',
  60                      'element_attributes' => array($sectionmenu),
  61                  ),
  62                  'summary_editor' => array(
  63                      'label' => 'Summary Text',
  64                      'element_type' => 'editor',
  65                  ),
  66              );
  67              $courseformatoptions = array_merge_recursive($courseformatoptions, $courseformatoptionsedit);
  68          }
  69          return $courseformatoptions;
  70      }
  71  
  72      /**
  73       * Allows to specify for modinfo that section is not available even when it is visible and conditionally available.
  74       *
  75       * @param section_info $section
  76       * @param bool $available
  77       * @param string $availableinfo
  78       */
  79      public function section_get_available_hook(section_info $section, &$available, &$availableinfo) {
  80          if (($section->section % 2) && ($hideoddsections = $this->get_course()->hideoddsections)) {
  81              $available = false;
  82              if ($hideoddsections == 2) {
  83                  $availableinfo = 'Odd sections are oddly hidden';
  84              } else {
  85                  $availableinfo = '';
  86              }
  87          }
  88      }
  89  }