Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

   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   * This file contains main class for the course format Social
  19   *
  20   * @since     Moodle 2.0
  21   * @package   format_social
  22   * @copyright 2009 Sam Hemelryk
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  require_once($CFG->dirroot. '/course/format/lib.php');
  28  
  29  /**
  30   * Main class for the Social course format
  31   *
  32   * @package    format_social
  33   * @copyright  2012 Marina Glancy
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class format_social extends core_courseformat\base {
  37  
  38      /**
  39       * The URL to use for the specified course
  40       *
  41       * @param int|stdClass $section Section object from database or just field course_sections.section
  42       *     if null the course view page is returned
  43       * @param array $options options for view URL. At the moment core uses:
  44       *     'navigation' (bool) if true and section has no separate page, the function returns null
  45       *     'sr' (int) used by multipage formats to specify to which section to return
  46       * @return null|moodle_url
  47       */
  48      public function get_view_url($section, $options = array()) {
  49          if (!empty($options['navigation']) && $section !== null) {
  50              return null;
  51          }
  52          return new moodle_url('/course/view.php', array('id' => $this->courseid));
  53      }
  54  
  55      /**
  56       * Loads all of the course sections into the navigation
  57       *
  58       * @param global_navigation $navigation
  59       * @param navigation_node $node The course node within the navigation
  60       */
  61      public function extend_course_navigation($navigation, navigation_node $node) {
  62          // Social course format does not extend navigation, it uses social_activities block instead
  63      }
  64  
  65      /**
  66       * Returns the list of blocks to be automatically added for the newly created course
  67       *
  68       * @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT
  69       *     each of values is an array of block names (for left and right side columns)
  70       */
  71      public function get_default_blocks() {
  72          return array(
  73              BLOCK_POS_LEFT => array(),
  74              BLOCK_POS_RIGHT => array('social_activities')
  75          );
  76      }
  77  
  78      /**
  79       * Definitions of the additional options that this course format uses for course
  80       *
  81       * social format uses the following options:
  82       * - numdiscussions
  83       *
  84       * @param bool $foreditform
  85       * @return array of options
  86       */
  87      public function course_format_options($foreditform = false) {
  88          static $courseformatoptions = false;
  89          if ($courseformatoptions === false) {
  90              $courseformatoptions = array(
  91                  'numdiscussions' => array(
  92                      'default' => 10,
  93                      'type' => PARAM_INT,
  94                  )
  95              );
  96          }
  97  
  98          if ($foreditform && !isset($courseformatoptions['numdiscussions']['label'])) {
  99              $courseformatoptionsedit = array(
 100                  'numdiscussions' => array(
 101                      'label' => new lang_string('numberdiscussions', 'format_social'),
 102                      'help' => 'numberdiscussions',
 103                      'help_component' => 'format_social',
 104                      'element_type' => 'text',
 105                  )
 106              );
 107              $courseformatoptions = array_merge_recursive($courseformatoptions, $courseformatoptionsedit);
 108          }
 109          return $courseformatoptions;
 110      }
 111  
 112      /**
 113       * Returns whether this course format allows the activity to
 114       * have "triple visibility state" - visible always, hidden on course page but available, hidden.
 115       *
 116       * @param stdClass|cm_info $cm course module (may be null if we are displaying a form for adding a module)
 117       * @param stdClass|section_info $section section where this module is located or will be added to
 118       * @return bool
 119       */
 120      public function allow_stealth_module_visibility($cm, $section) {
 121          return true;
 122      }
 123  
 124      /**
 125       * Return the plugin configs for external functions.
 126       *
 127       * @return array the list of configuration settings
 128       * @since Moodle 3.5
 129       */
 130      public function get_config_for_external() {
 131          // Return everything (nothing to hide).
 132          return $this->get_format_options();
 133      }
 134  
 135      /**
 136       * Returns the information about the ajax support in the given source format.
 137       *
 138       * The returned object's property (boolean)capable indicates that
 139       * the course format supports Moodle course ajax features.
 140       *
 141       * @return stdClass
 142       */
 143      public function supports_ajax() {
 144          $ajaxsupport = new stdClass();
 145          $ajaxsupport->capable = true;
 146          return $ajaxsupport;
 147      }
 148  
 149  }