[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/page/classes/search/ -> activity.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 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      /**
  40       * Returns the document associated with this activity.
  41       *
  42       * Overwriting base_activity method as page contents field is required,
  43       * description field is not.
  44       *
  45       * @param stdClass $record
  46       * @param array    $options
  47       * @return \core_search\document
  48       */
  49      public function get_document($record, $options = array()) {
  50  
  51          try {
  52              $cm = $this->get_cm($this->get_module_name(), $record->id, $record->course);
  53              $context = \context_module::instance($cm->id);
  54          } catch (\dml_missing_record_exception $ex) {
  55              // Notify it as we run here as admin, we should see everything.
  56              debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' .
  57                  $ex->getMessage(), DEBUG_DEVELOPER);
  58              return false;
  59          } catch (\dml_exception $ex) {
  60              // Notify it as we run here as admin, we should see everything.
  61              debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
  62              return false;
  63          }
  64  
  65          // Prepare associative array with data from DB.
  66          $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
  67          $doc->set('title', content_to_text($record->name, false));
  68          $doc->set('content', content_to_text($record->content, $record->contentformat));
  69          $doc->set('contextid', $context->id);
  70          $doc->set('courseid', $record->course);
  71          $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
  72          $doc->set('modified', $record->timemodified);
  73          $doc->set('description1', content_to_text($record->intro, $record->introformat));
  74  
  75          return $doc;
  76      }
  77  }


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