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.
   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 for mod_page activities.
  19   *
  20   * @package    mod_page
  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 mod_page\search;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Search area for mod_page activities.
  31   *
  32   * @package    mod_page
  33   * @copyright  2015 David Monllao {@link http://www.davidmonllao.com}
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class activity extends \core_search\base_activity {
  37  
  38      /**
  39       * Returns the document associated with this activity.
  40       *
  41       * Overwriting base_activity method as page contents field is required,
  42       * description field is not.
  43       *
  44       * @param stdClass $record
  45       * @param array    $options
  46       * @return \core_search\document
  47       */
  48      public function get_document($record, $options = array()) {
  49  
  50          try {
  51              $cm = $this->get_cm($this->get_module_name(), $record->id, $record->course);
  52              $context = \context_module::instance($cm->id);
  53          } catch (\dml_missing_record_exception $ex) {
  54              // Notify it as we run here as admin, we should see everything.
  55              debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' .
  56                  $ex->getMessage(), DEBUG_DEVELOPER);
  57              return false;
  58          } catch (\dml_exception $ex) {
  59              // Notify it as we run here as admin, we should see everything.
  60              debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
  61              return false;
  62          }
  63  
  64          // Prepare associative array with data from DB.
  65          $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
  66          $doc->set('title', content_to_text($record->name, false));
  67          $doc->set('content', content_to_text($record->content, $record->contentformat));
  68          $doc->set('contextid', $context->id);
  69          $doc->set('courseid', $record->course);
  70          $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
  71          $doc->set('modified', $record->timemodified);
  72          $doc->set('description1', content_to_text($record->intro, $record->introformat));
  73  
  74          return $doc;
  75      }
  76  
  77      /**
  78       * Returns true if this area uses file indexing.
  79       *
  80       * @return bool
  81       */
  82      public function uses_file_indexing() {
  83          return true;
  84      }
  85  
  86      /**
  87       * Return the context info required to index files for
  88       * this search area.
  89       *
  90       * @return array
  91       */
  92      public function get_search_fileareas() {
  93          $fileareas = array('intro', 'content'); // Fileareas.
  94  
  95          return $fileareas;
  96      }
  97  }