66e3702680
This change considers all existing search areas in Moodle and makes necessary changes. Custom change to course search, supported by helper in base.php: * course/classes/search/mycourse.php Custom change to message search: * message/classes/search/message_received.php * message/classes/search/message_sent.php Custom change to user search: * user/classes/search/user.php Custom changes to module areas, supported by helper in base_mod.php: * mod/book/classes/search/chapter.php * mod/data/classes/search/entry.php * mod/forum/classes/search/post.php * mod/glossary/classes/search/entry.php * mod/survey/classes/search/activity.php * mod/wiki/classes/search/collaborative_page.php (Note: the unit tests do not exhaustively check every context type for these, given that's mainly handled by the helper function which was already tested in the base_activity test.) Handled by block base class (no change): * blocks/html/classes/search/content.php Handled by activity base class (no change): * mod/assign/classes/search/activity.php * mod/book/classes/search/activity.php * mod/chat/classes/search/activity.php * mod/choice/classes/search/activity.php * mod/data/classes/search/activity.php * mod/feedback/classes/search/activity.php * mod/folder/classes/search/activity.php * mod/forum/classes/search/activity.php * mod/glossary/classes/search/activity.php * mod/imscp/classes/search/activity.php * mod/label/classes/search/activity.php * mod/lesson/classes/search/activity.php * mod/lti/classes/search/activity.php * mod/page/classes/search/activity.php * mod/quiz/classes/search/activity.php * mod/resource/classes/search/activity.php * mod/scorm/classes/search/activity.php * mod/url/classes/search/activity.php * mod/wiki/classes/search/activity.php * mod/workshop/classes/search/activity.php
97 lines
3.0 KiB
PHP
97 lines
3.0 KiB
PHP
<?php
|
|
// This file is part of Moodle - http://moodle.org/
|
|
//
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
* Search area for received messages.
|
|
*
|
|
* @package core_message
|
|
* @copyright 2016 Devang Gaur
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
namespace core_message\search;
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
/**
|
|
* Search area for received messages.
|
|
*
|
|
* @package core_message
|
|
* @copyright 2016 Devang Gaur
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class message_received extends base_message {
|
|
|
|
/**
|
|
* Returns a recordset with the messages for indexing.
|
|
*
|
|
* @param int $modifiedfrom
|
|
* @param \context|null $context Optional context to restrict scope of returned results
|
|
* @return moodle_recordset|null Recordset (or null if no results)
|
|
*/
|
|
public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
|
|
return $this->get_document_recordset_helper($modifiedfrom, $context, 'useridto');
|
|
}
|
|
|
|
/**
|
|
* Returns the document associated with this message record.
|
|
*
|
|
* @param stdClass $record
|
|
* @param array $options
|
|
* @return \core_search\document
|
|
*/
|
|
public function get_document($record, $options = array()) {
|
|
return parent::get_document($record, array('user1id' => $record->useridto, 'user2id' => $record->useridfrom));
|
|
}
|
|
|
|
/**
|
|
* Whether the user can access the document or not.
|
|
*
|
|
* @param int $id The message instance id.
|
|
* @return int
|
|
*/
|
|
public function check_access($id) {
|
|
global $CFG, $DB, $USER;
|
|
|
|
if (!$CFG->messaging) {
|
|
return \core_search\manager::ACCESS_DENIED;
|
|
}
|
|
|
|
$message = $DB->get_record('message_read', array('id' => $id));
|
|
if (!$message) {
|
|
return \core_search\manager::ACCESS_DELETED;
|
|
}
|
|
|
|
$userfrom = \core_user::get_user($message->useridfrom, 'id, deleted');
|
|
$userto = \core_user::get_user($message->useridto, 'id, deleted');
|
|
|
|
if (!$userfrom || !$userto || $userfrom->deleted || $userto->deleted) {
|
|
return \core_search\manager::ACCESS_DELETED;
|
|
}
|
|
|
|
if ($USER->id != $userto->id) {
|
|
return \core_search\manager::ACCESS_DENIED;
|
|
}
|
|
|
|
if ($message->timeusertodeleted != 0) {
|
|
return \core_search\manager::ACCESS_DELETED;
|
|
}
|
|
|
|
return \core_search\manager::ACCESS_GRANTED;
|
|
}
|
|
|
|
}
|