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.
   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   * Utility class for browsing of content bank files in the system context.
  19   *
  20   * @package    repository_contentbank
  21   * @copyright  2020 Mihail Geshoski <mihail@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace repository_contentbank\browser;
  26  
  27  /**
  28   * Represents the content bank browser in the system context.
  29   *
  30   * @package    repository_contentbank
  31   * @copyright  2020 Mihail Geshoski <mihail@moodle.com>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class contentbank_browser_context_system extends contentbank_browser {
  35  
  36      /**
  37       * Constructor.
  38       *
  39       * @param \context_system $context The current context
  40       */
  41      public function __construct(\context_system $context) {
  42          $this->context = $context;
  43      }
  44  
  45      /**
  46       * Define the allowed child context levels.
  47       *
  48       * @return int[] The array containing the relevant child context levels
  49       */
  50      protected function allowed_child_context_levels(): array {
  51          // The expected child context in the system context level is the course category context.
  52          return [\CONTEXT_COURSECAT];
  53      }
  54  
  55      /**
  56       * The required condition to enable the user to view/access the content bank content in this context.
  57       *
  58       * @return bool Whether the user can view/access the content bank content in the context
  59       */
  60      public function can_access_content(): bool {
  61          // When the following conditions are met, the user would be able to share the content created in the system
  62          // context level all over the site.
  63          // The content from the system context level should be available to:
  64          // * Every user that has a capability to access the 'general' content.
  65  
  66          return has_capability('repository/contentbank:accessgeneralcontent', $this->context);
  67      }
  68  }