[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/user/classes/search/ -> user.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 Users for whom I have authority to view profile.
  19   *
  20   * @package    core_user
  21   * @copyright  2016 Devang Gaur {@link http://www.devanggaur.com}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_user\search;
  26  
  27  require_once($CFG->dirroot . '/user/lib.php');
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  /**
  32   * Search area for Users for whom I have access to view profile.
  33   *
  34   * @package    core_user
  35   * @copyright  2016 Devang Gaur {@link http://www.devanggaur.com}
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class user extends \core_search\base {
  39  
  40      /**
  41       * Returns recordset containing required data attributes for indexing.
  42       *
  43       * @param number $modifiedfrom
  44       * @return \moodle_recordset
  45       */
  46      public function get_recordset_by_timestamp($modifiedfrom = 0) {
  47          global $DB;
  48          return $DB->get_recordset_select('user', 'timemodified >= ? AND deleted = ? AND
  49                  confirmed = ?', array($modifiedfrom, 0, 1));
  50      }
  51  
  52      /**
  53       * Returns document instances for each record in the recordset.
  54       *
  55       * @param StdClass $record
  56       * @param array $options
  57       * @return core_search/document
  58       */
  59      public function get_document($record, $options = array()) {
  60  
  61          $context = \context_system::instance();
  62  
  63          // Prepare associative array with data from DB.
  64          $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
  65          // Assigning properties to our document.
  66          $doc->set('title', content_to_text(fullname($record), false));
  67          $doc->set('contextid', $context->id);
  68          $doc->set('courseid', SITEID);
  69          $doc->set('itemid', $record->id);
  70          $doc->set('modified', $record->timemodified);
  71          $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
  72          $doc->set('content', content_to_text($record->description, $record->descriptionformat));
  73  
  74          // Check if this document should be considered new.
  75          if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) {
  76              // If the document was created after the last index time, it must be new.
  77              $doc->set_is_new(true);
  78          }
  79  
  80          return $doc;
  81      }
  82  
  83      /**
  84       * Checking whether I can access a document
  85       *
  86       * @param int $id user id
  87       * @return int
  88       */
  89      public function check_access($id) {
  90          global $DB, $USER;
  91  
  92          $user = $DB->get_record('user', array('id' => $id));
  93          if (!$user || $user->deleted) {
  94              return \core_search\manager::ACCESS_DELETED;
  95          }
  96  
  97          if (user_can_view_profile($user)) {
  98              return \core_search\manager::ACCESS_GRANTED;
  99          }
 100  
 101          return \core_search\manager::ACCESS_DENIED;
 102      }
 103  
 104      /**
 105       * Returns a url to the profile page of user.
 106       *
 107       * @param \core_search\document $doc
 108       * @return moodle_url
 109       */
 110      public function get_doc_url(\core_search\document $doc) {
 111          return $this->get_context_url($doc);
 112      }
 113  
 114      /**
 115       * Returns a url to the document context.
 116       *
 117       * @param \core_search\document $doc
 118       * @return moodle_url
 119       */
 120      public function get_context_url(\core_search\document $doc) {
 121          return new \moodle_url('/user/profile.php', array('id' => $doc->get('itemid')));
 122      }
 123  }


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