[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/search/classes/ -> base_mod.php (source)

   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   * Search area base class for areas working at module level.
  19   *
  20   * @package    core_search
  21   * @copyright  2015 David Monllao {@link http://www.davidmonllao.com}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_search;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Base implementation for search areas working at module level.
  31   *
  32   * Even if the search area works at multiple levels, if module is one of these levels
  33   * it should extend this class, as this class provides helper methods for module level search management.
  34   *
  35   * @package    core_search
  36   * @copyright  2015 David Monllao {@link http://www.davidmonllao.com}
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  abstract class base_mod extends base {
  40  
  41      /**
  42       * The context levels the search area is working on.
  43       *
  44       * This can be overwriten by the search area if it works at multiple
  45       * levels.
  46       *
  47       * @var array
  48       */
  49      protected static $levels = [CONTEXT_MODULE];
  50  
  51      /**
  52       * Gets the course module for the required instanceid + modulename.
  53       *
  54       * The returned data depends on the logged user, when calling this through
  55       * self::get_document the admin user is used so everything would be returned.
  56       *
  57       * No need more internal caching here, modinfo is already cached.
  58       *
  59       * @throws \dml_missing_record_exception
  60       * @param string $modulename The module name
  61       * @param int $instanceid Module instance id (depends on the module)
  62       * @param int $courseid Helps speeding up things
  63       * @return \cm_info
  64       */
  65      protected function get_cm($modulename, $instanceid, $courseid) {
  66          $modinfo = get_fast_modinfo($courseid);
  67  
  68          // Hopefully not many, they are indexed by cmid.
  69          $instances = $modinfo->get_instances_of($modulename);
  70          foreach ($instances as $cminfo) {
  71              if ($cminfo->instance == $instanceid) {
  72                  return $cminfo;
  73              }
  74          }
  75  
  76          // Nothing found.
  77          throw new \dml_missing_record_exception($modulename);
  78  
  79          return $cm;
  80      }
  81  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1