mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-31989 search: New search areas
Some search areas have been introduced as part of the initial search API and search engine API implementation. - Forum posts - Glossary enties - All moodle activities
This commit is contained in:
parent
28b70ba536
commit
e2be996171
37
mod/assign/classes/search/activity.php
Normal file
37
mod/assign/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_assign activities.
|
||||
*
|
||||
* @package mod_assign
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_assign\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_assign activities.
|
||||
*
|
||||
* @package mod_assign
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -340,6 +340,7 @@ $string['savegradingresult'] = 'Grade';
|
||||
$string['saveallquickgradingchanges'] = 'Save all quick grading changes';
|
||||
$string['savenext'] = 'Save and show next';
|
||||
$string['scale'] = 'Scale';
|
||||
$string['search:activity'] = 'Assignment activities';
|
||||
$string['sendstudentnotificationsdefault'] = 'Default setting for "Notify students"';
|
||||
$string['sendstudentnotificationsdefault_help'] = 'Set the default value for the "Notify students" checkbox on the grading form.';
|
||||
$string['sendstudentnotifications'] = 'Notify students';
|
||||
|
37
mod/book/classes/search/activity.php
Normal file
37
mod/book/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_book activities.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_book\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_book activities.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -55,6 +55,7 @@ $string['editchapter'] = 'Edit chapter "{$a}"';
|
||||
$string['hidechapter'] = 'Hide chapter "{$a}"';
|
||||
$string['movechapterup'] = 'Move chapter up "{$a}"';
|
||||
$string['movechapterdown'] = 'Move chapter down "{$a}"';
|
||||
$string['search:activity'] = 'Book activities';
|
||||
$string['showchapter'] = 'Show chapter "{$a}"';
|
||||
$string['subchapter'] = 'Subchapter';
|
||||
$string['navimages'] = 'Images';
|
||||
|
37
mod/chat/classes/search/activity.php
Normal file
37
mod/chat/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_chat activities.
|
||||
*
|
||||
* @package mod_chat
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_chat\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_chat activities.
|
||||
*
|
||||
* @package mod_chat
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -123,6 +123,7 @@ $string['repeatweekly'] = 'At the same time every week';
|
||||
$string['saidto'] = 'said to';
|
||||
$string['savemessages'] = 'Save past sessions';
|
||||
$string['seesession'] = 'See this session';
|
||||
$string['search:activity'] = 'Chat activities';
|
||||
$string['send'] = 'Send';
|
||||
$string['sending'] = 'Sending';
|
||||
$string['serverhost'] = 'Server name';
|
||||
|
37
mod/choice/classes/search/activity.php
Normal file
37
mod/choice/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_choice activities.
|
||||
*
|
||||
* @package mod_choice
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_choice\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_choice activities.
|
||||
*
|
||||
* @package mod_choice
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -112,6 +112,7 @@ $string['responsesresultgraphheader'] = 'Graph display';
|
||||
$string['responsesto'] = 'Responses to {$a}';
|
||||
$string['results'] = 'Results';
|
||||
$string['savemychoice'] = 'Save my choice';
|
||||
$string['search:activity'] = 'Choice activities';
|
||||
$string['showpreview'] = 'Show preview';
|
||||
$string['showpreview_help'] = 'Allow students to preview the available options before the choice is opened for submission.';
|
||||
$string['showunanswered'] = 'Show column for unanswered';
|
||||
|
37
mod/feedback/classes/search/activity.php
Normal file
37
mod/feedback/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_feedback activities.
|
||||
*
|
||||
* @package mod_feedback
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_feedback\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_feedback activities.
|
||||
*
|
||||
* @package mod_feedback
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -242,6 +242,7 @@ $string['save_entries'] = 'Submit your answers';
|
||||
$string['save_item'] = 'Save question';
|
||||
$string['saving_failed'] = 'Saving failed';
|
||||
$string['saving_failed_because_missing_or_false_values'] = 'Saving failed because missing or false values';
|
||||
$string['search:activity'] = 'Feedback activities';
|
||||
$string['search_course'] = 'Search course';
|
||||
$string['searchcourses'] = 'Search courses';
|
||||
$string['searchcourses_help'] = 'Search for the code or name of the course(s) that you wish to associate with this feedback.';
|
||||
|
37
mod/folder/classes/search/activity.php
Normal file
37
mod/folder/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_folder activities.
|
||||
*
|
||||
* @package mod_folder
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_folder\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_folder activities.
|
||||
*
|
||||
* @package mod_folder
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -51,6 +51,7 @@ Also note that participants view actions can not be logged in this case.';
|
||||
$string['displaypage'] = 'On a separate page';
|
||||
$string['displayinline'] = 'Inline on a course page';
|
||||
$string['noautocompletioninline'] = 'Automatic completion on viewing of activity can not be selected together with "Display inline" option';
|
||||
$string['search:activity'] = 'Folder activities';
|
||||
$string['showdownloadfolder'] = 'Show download folder button';
|
||||
$string['showdownloadfolder_help'] = 'If set to \'yes\', a button will be shown to allow users to download a zip archive containing all files.';
|
||||
$string['showexpanded'] = 'Show subfolders expanded';
|
||||
|
37
mod/forum/classes/search/activity.php
Normal file
37
mod/forum/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Forum activities search area
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Forum activities search area.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
216
mod/forum/classes/search/post.php
Normal file
216
mod/forum/classes/search/post.php
Normal file
@ -0,0 +1,216 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Forum posts search area
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/forum/lib.php');
|
||||
|
||||
/**
|
||||
* Forum posts search area.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class post extends \core_search\area\base_mod {
|
||||
|
||||
/**
|
||||
* @var array Internal quick static cache.
|
||||
*/
|
||||
protected $forumsdata = array();
|
||||
|
||||
/**
|
||||
* @var array Internal quick static cache.
|
||||
*/
|
||||
protected $discussionsdata = array();
|
||||
|
||||
/**
|
||||
* @var array Internal quick static cache.
|
||||
*/
|
||||
protected $postsdata = array();
|
||||
|
||||
/**
|
||||
* Returns recordset containing required data for indexing forum posts.
|
||||
*
|
||||
* @param int $modifiedfrom timestamp
|
||||
* @return moodle_recordset
|
||||
*/
|
||||
public function get_recordset_by_timestamp($modifiedfrom = 0) {
|
||||
global $DB;
|
||||
|
||||
$sql = 'SELECT fp.*, f.id AS forumid, f.course AS courseid
|
||||
FROM {forum_posts} fp
|
||||
JOIN {forum_discussions} fd ON fd.id = fp.discussion
|
||||
JOIN {forum} f ON f.id = fd.forum
|
||||
WHERE fp.modified >= ? ORDER BY fp.modified ASC';
|
||||
return $DB->get_recordset_sql($sql, array($modifiedfrom));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the document associated with this post id.
|
||||
*
|
||||
* @param stdClass $record Post info.
|
||||
* @return \core_search\document
|
||||
*/
|
||||
public function get_document($record) {
|
||||
|
||||
try {
|
||||
$cm = $this->get_cm('forum', $record->forumid, $record->courseid);
|
||||
$context = \context_module::instance($cm->id);
|
||||
} catch (\dml_missing_record_exception $ex) {
|
||||
// Notify it as we run here as admin, we should see everything.
|
||||
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' .
|
||||
$ex->getMessage(), DEBUG_DEVELOPER);
|
||||
return false;
|
||||
} catch (\dml_exception $ex) {
|
||||
// Notify it as we run here as admin, we should see everything.
|
||||
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prepare associative array with data from DB.
|
||||
$doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
|
||||
$doc->set('title', $record->subject);
|
||||
$doc->set('content', editor_input_to_text($record->message, $record->messageformat));
|
||||
$doc->set('contextid', $context->id);
|
||||
$doc->set('type', \core_search\manager::TYPE_TEXT);
|
||||
$doc->set('courseid', $record->courseid);
|
||||
$doc->set('userid', $record->userid);
|
||||
$doc->set('modified', $record->modified);
|
||||
|
||||
return $doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the user can access the document or not.
|
||||
*
|
||||
* @throws \dml_missing_record_exception
|
||||
* @throws \dml_exception
|
||||
* @param int $id Forum post id
|
||||
* @return bool
|
||||
*/
|
||||
public function check_access($id) {
|
||||
global $USER;
|
||||
|
||||
try {
|
||||
$post = $this->get_post($id);
|
||||
$forum = $this->get_forum($post->forum);
|
||||
$discussion = $this->get_discussion($post->discussion);
|
||||
$cminfo = $this->get_cm('forum', $forum->id, $forum->course);
|
||||
$cm = $cminfo->get_course_module_record();
|
||||
} catch (\dml_missing_record_exception $ex) {
|
||||
return \core_search\manager::ACCESS_DELETED;
|
||||
} catch (\dml_exception $ex) {
|
||||
return \core_search\manager::ACCESS_DENIED;
|
||||
}
|
||||
|
||||
// Recheck uservisible although it should have already been checked in core_search.
|
||||
if ($cminfo->uservisible === false) {
|
||||
return \core_search\manager::ACCESS_DENIED;
|
||||
}
|
||||
|
||||
if (!forum_user_can_see_post($forum, $discussion, $post, $USER, $cm)) {
|
||||
return \core_search\manager::ACCESS_DENIED;
|
||||
}
|
||||
|
||||
return \core_search\manager::ACCESS_GRANTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the forum post discussion
|
||||
*
|
||||
* @param \core_search\document $doc
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_doc_url(\core_search\document $doc) {
|
||||
// The post is already in static cache, we fetch it in self::search_access.
|
||||
$post = $this->get_post($doc->get('itemid'));
|
||||
return new \moodle_url('/mod/forum/discuss.php', array('d' => $post->discussion));
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the forum.
|
||||
*
|
||||
* @param \core_search\document $doc
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_context_url(\core_search\document $doc) {
|
||||
$contextmodule = \context::instance_by_id($doc->get('contextid'));
|
||||
return new \moodle_url('/mod/forum/view.php', array('id' => $contextmodule->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified forum post from its internal cache.
|
||||
*
|
||||
* @throws \dml_missing_record_exception
|
||||
* @param int $postid
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function get_post($postid) {
|
||||
if (empty($this->postsdata[$postid])) {
|
||||
$this->postsdata[$postid] = forum_get_post_full($postid);
|
||||
if (!$this->postsdata[$postid]) {
|
||||
throw new \dml_missing_record_exception('forum_posts');
|
||||
}
|
||||
}
|
||||
return $this->postsdata[$postid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified forum checking the internal cache.
|
||||
*
|
||||
* Store minimal information as this might grow.
|
||||
*
|
||||
* @throws \dml_exception
|
||||
* @param int $forumid
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function get_forum($forumid) {
|
||||
global $DB;
|
||||
|
||||
if (empty($this->forumsdata[$forumid])) {
|
||||
$this->forumsdata[$forumid] = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
|
||||
}
|
||||
return $this->forumsdata[$forumid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the discussion checking the internal cache.
|
||||
*
|
||||
* @throws \dml_missing_record_exception
|
||||
* @param int $discussionid
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function get_discussion($discussionid) {
|
||||
global $DB;
|
||||
|
||||
if (empty($this->discussionsdata[$discussionid])) {
|
||||
$this->discussionsdata[$discussionid] = $DB->get_record('forum_discussions',
|
||||
array('id' => $discussionid), '*', MUST_EXIST);
|
||||
}
|
||||
return $this->discussionsdata[$discussionid];
|
||||
}
|
||||
}
|
@ -443,6 +443,8 @@ $string['rsstype'] = 'RSS feed for this activity';
|
||||
$string['rsstype_help'] = 'To enable the RSS feed for this activity, select either discussions or posts to be included in the feed.';
|
||||
$string['rsstypedefault'] = 'RSS feed type';
|
||||
$string['search'] = 'Search';
|
||||
$string['search:post'] = 'Forum posts';
|
||||
$string['search:activity'] = 'Forum activities';
|
||||
$string['searchdatefrom'] = 'Posts must be newer than this';
|
||||
$string['searchdateto'] = 'Posts must be older than this';
|
||||
$string['searchforumintro'] = 'Please enter search terms into one or more of the following fields:';
|
||||
|
270
mod/forum/tests/search_test.php
Normal file
270
mod/forum/tests/search_test.php
Normal file
@ -0,0 +1,270 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Forum search unit tests.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @category test
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/search/tests/fixtures/testable_core_search.php');
|
||||
require_once($CFG->dirroot . '/mod/forum/tests/generator/lib.php');
|
||||
require_once($CFG->dirroot . '/mod/forum/lib.php');
|
||||
|
||||
/**
|
||||
* Provides the unit tests for forum search.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @category test
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class mod_forum_search_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* @var string Area id
|
||||
*/
|
||||
protected $forumpostareaid = null;
|
||||
|
||||
public function setUp() {
|
||||
$this->resetAfterTest(true);
|
||||
set_config('enableglobalsearch', true);
|
||||
|
||||
$this->forumpostareaid = \core_search\manager::generate_areaid('mod_forum', 'post');
|
||||
|
||||
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
|
||||
$search = testable_core_search::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Availability.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_search_enabled() {
|
||||
|
||||
$searcharea = \core_search\manager::get_search_area($this->forumpostareaid);
|
||||
list($componentname, $varname) = $searcharea->get_config_var_name();
|
||||
|
||||
// Enabled by default once global search is enabled.
|
||||
$this->assertTrue($searcharea->is_enabled());
|
||||
|
||||
set_config('enable' . $varname, false, $componentname);
|
||||
$this->assertFalse($searcharea->is_enabled());
|
||||
|
||||
set_config('enable' . $varname, true, $componentname);
|
||||
$this->assertTrue($searcharea->is_enabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexing mod forum contents.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_posts_indexing() {
|
||||
global $DB;
|
||||
|
||||
// Returns the instance as long as the area is supported.
|
||||
$searcharea = \core_search\manager::get_search_area($this->forumpostareaid);
|
||||
$this->assertInstanceOf('\mod_forum\search\post', $searcharea);
|
||||
|
||||
$user1 = self::getDataGenerator()->create_user();
|
||||
$user2 = self::getDataGenerator()->create_user();
|
||||
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
$course2 = self::getDataGenerator()->create_course();
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course1->id, 'student');
|
||||
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
|
||||
// Available for both student and teacher.
|
||||
$forum1 = self::getDataGenerator()->create_module('forum', $record);
|
||||
|
||||
// Create discussion1.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $user1->id;
|
||||
$record->forum = $forum1->id;
|
||||
$record->message = 'discussion';
|
||||
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
// Create post1 in discussion1.
|
||||
$record = new stdClass();
|
||||
$record->discussion = $discussion1->id;
|
||||
$record->parent = $discussion1->firstpost;
|
||||
$record->userid = $user2->id;
|
||||
$record->message = 'post2';
|
||||
$discussion1reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
|
||||
|
||||
// All records.
|
||||
$recordset = $searcharea->get_recordset_by_timestamp(0);
|
||||
$this->assertTrue($recordset->valid());
|
||||
$nrecords = 0;
|
||||
foreach ($recordset as $record) {
|
||||
$this->assertInstanceOf('stdClass', $record);
|
||||
$doc = $searcharea->get_document($record);
|
||||
$this->assertInstanceOf('\core_search\document', $doc);
|
||||
|
||||
// Static caches are working.
|
||||
$dbreads = $DB->perf_get_reads();
|
||||
$doc = $searcharea->get_document($record);
|
||||
$this->assertEquals($dbreads, $DB->perf_get_reads());
|
||||
$this->assertInstanceOf('\core_search\document', $doc);
|
||||
$nrecords++;
|
||||
}
|
||||
// If there would be an error/failure in the foreach above the recordset would be closed on shutdown.
|
||||
$recordset->close();
|
||||
$this->assertEquals(2, $nrecords);
|
||||
|
||||
// The +2 is to prevent race conditions.
|
||||
$recordset = $searcharea->get_recordset_by_timestamp(time() + 2);
|
||||
|
||||
// No new records.
|
||||
$this->assertFalse($recordset->valid());
|
||||
$recordset->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Document contents.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_posts_document() {
|
||||
global $DB;
|
||||
|
||||
// Returns the instance as long as the area is supported.
|
||||
$searcharea = \core_search\manager::get_search_area($this->forumpostareaid);
|
||||
$this->assertInstanceOf('\mod_forum\search\post', $searcharea);
|
||||
|
||||
$user = self::getDataGenerator()->create_user();
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course1->id, 'teacher');
|
||||
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$forum1 = self::getDataGenerator()->create_module('forum', $record);
|
||||
|
||||
// Teacher only.
|
||||
$forum2 = self::getDataGenerator()->create_module('forum', $record);
|
||||
set_coursemodule_visible($forum2->cmid, 0);
|
||||
|
||||
// Create discussion1.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $user->id;
|
||||
$record->forum = $forum1->id;
|
||||
$record->message = 'discussion';
|
||||
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
// Create post1 in discussion1.
|
||||
$record = new stdClass();
|
||||
$record->discussion = $discussion1->id;
|
||||
$record->parent = $discussion1->firstpost;
|
||||
$record->userid = $user->id;
|
||||
$record->subject = 'subject1';
|
||||
$record->message = 'post1';
|
||||
$discussion1reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
|
||||
|
||||
$post1 = $DB->get_record('forum_posts', array('id' => $discussion1reply1->id));
|
||||
$post1->forumid = $forum1->id;
|
||||
$post1->courseid = $forum1->course;
|
||||
|
||||
$doc = $searcharea->get_document($post1);
|
||||
$this->assertInstanceOf('\core_search\document', $doc);
|
||||
$this->assertEquals($discussion1reply1->id, $doc->get('itemid'));
|
||||
$this->assertEquals($this->forumpostareaid . '-' . $discussion1reply1->id, $doc->get('id'));
|
||||
$this->assertEquals($course1->id, $doc->get('courseid'));
|
||||
$this->assertEquals($user->id, $doc->get('userid'));
|
||||
$this->assertEquals($discussion1reply1->subject, $doc->get('title'));
|
||||
$this->assertEquals($discussion1reply1->message, $doc->get('content'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Document accesses.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_posts_access() {
|
||||
global $DB;
|
||||
|
||||
// Returns the instance as long as the area is supported.
|
||||
$searcharea = \core_search\manager::get_search_area($this->forumpostareaid);
|
||||
|
||||
$user1 = self::getDataGenerator()->create_user();
|
||||
$user2 = self::getDataGenerator()->create_user();
|
||||
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
$course2 = self::getDataGenerator()->create_course();
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, 'teacher');
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course1->id, 'student');
|
||||
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
|
||||
// Available for both student and teacher.
|
||||
$forum1 = self::getDataGenerator()->create_module('forum', $record);
|
||||
|
||||
// Teacher only.
|
||||
$forum2 = self::getDataGenerator()->create_module('forum', $record);
|
||||
set_coursemodule_visible($forum2->cmid, 0);
|
||||
|
||||
// Create discussion1.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $user1->id;
|
||||
$record->forum = $forum1->id;
|
||||
$record->message = 'discussion';
|
||||
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
// Create post1 in discussion1.
|
||||
$record = new stdClass();
|
||||
$record->discussion = $discussion1->id;
|
||||
$record->parent = $discussion1->firstpost;
|
||||
$record->userid = $user2->id;
|
||||
$record->message = 'post1';
|
||||
$discussion1reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
|
||||
|
||||
// Create discussion2 only visible to teacher.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $user1->id;
|
||||
$record->forum = $forum2->id;
|
||||
$record->message = 'discussion';
|
||||
$discussion2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
// Create post2 in discussion2.
|
||||
$record = new stdClass();
|
||||
$record->discussion = $discussion2->id;
|
||||
$record->parent = $discussion2->firstpost;
|
||||
$record->userid = $user1->id;
|
||||
$record->message = 'post2';
|
||||
$discussion2reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
|
||||
|
||||
$this->setUser($user2);
|
||||
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $searcharea->check_access($discussion1reply1->id));
|
||||
$this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($discussion2reply1->id));
|
||||
}
|
||||
}
|
@ -401,9 +401,9 @@ class mod_glossary_external extends external_api {
|
||||
|
||||
// Get and validate the glossary.
|
||||
$entry = $DB->get_record('glossary_entries', array('id' => $id), '*', MUST_EXIST);
|
||||
list($glossary, $context) = self::validate_glossary($entry->glossaryid);
|
||||
list($glossary, $context, $course, $cm) = self::validate_glossary($entry->glossaryid);
|
||||
|
||||
if (empty($entry->approved) && $entry->userid != $USER->id && !has_capability('mod/glossary:approve', $context)) {
|
||||
if (!glossary_can_view_entry($entry, $cm)) {
|
||||
throw new invalid_parameter_exception('invalidentry');
|
||||
}
|
||||
|
||||
|
37
mod/glossary/classes/search/activity.php
Normal file
37
mod/glossary/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_glossary activities.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_glossary\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_glossary activities.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
188
mod/glossary/classes/search/entry.php
Normal file
188
mod/glossary/classes/search/entry.php
Normal file
@ -0,0 +1,188 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Glossary entries search.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_glossary\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/glossary/lib.php');
|
||||
|
||||
/**
|
||||
* Glossary entries search.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class entry extends \core_search\area\base_mod {
|
||||
|
||||
/**
|
||||
* @var array Internal quick static cache.
|
||||
*/
|
||||
protected $entriesdata = array();
|
||||
|
||||
/**
|
||||
* Returns recordset containing required data for indexing glossary entries.
|
||||
*
|
||||
* @param int $modifiedfrom timestamp
|
||||
* @return moodle_recordset
|
||||
*/
|
||||
public function get_recordset_by_timestamp($modifiedfrom = 0) {
|
||||
global $DB;
|
||||
|
||||
$sql = "SELECT ge.*, g.course FROM {glossary_entries} ge
|
||||
JOIN {glossary} g ON g.id = ge.glossaryid
|
||||
WHERE ge.timemodified >= ?";
|
||||
return $DB->get_recordset_sql($sql, array($modifiedfrom));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the documents associated with this glossary entry id.
|
||||
*
|
||||
* @param stdClass $entry glossary entry.
|
||||
* @return \core_search\document
|
||||
*/
|
||||
public function get_document($entry) {
|
||||
global $DB;
|
||||
|
||||
$keywords = array();
|
||||
if ($aliases = $DB->get_records('glossary_alias', array('entryid' => $entry->id))) {
|
||||
foreach ($aliases as $alias) {
|
||||
$keywords[] = $alias->alias;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$cm = $this->get_cm('glossary', $entry->glossaryid, $entry->course);
|
||||
$context = \context_module::instance($cm->id);
|
||||
} catch (\dml_missing_record_exception $ex) {
|
||||
// Notify it as we run here as admin, we should see everything.
|
||||
debugging('Error retrieving mod_glossary ' . $entry->id . ' document, not all required data is available: ' .
|
||||
$ex->getMessage(), DEBUG_DEVELOPER);
|
||||
return false;
|
||||
} catch (\dml_exception $ex) {
|
||||
// Notify it as we run here as admin, we should see everything.
|
||||
debugging('Error retrieving mod_glossary' . $entry->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prepare associative array with data from DB.
|
||||
$doc = \core_search\document_factory::instance($entry->id, $this->componentname, $this->areaname);
|
||||
$doc->set('title', $entry->concept);
|
||||
$doc->set('content', editor_input_to_text($entry->definition, $entry->definitionformat));
|
||||
$doc->set('contextid', $context->id);
|
||||
$doc->set('type', \core_search\manager::TYPE_TEXT);
|
||||
$doc->set('courseid', $entry->course);
|
||||
$doc->set('userid', $entry->userid);
|
||||
$doc->set('modified', $entry->timemodified);
|
||||
|
||||
// Adding keywords as extra info.
|
||||
if ($keywords) {
|
||||
$doc->set('description1', implode(' ' , $keywords));
|
||||
}
|
||||
|
||||
return $doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the user can access the document or not.
|
||||
*
|
||||
* @throws \dml_missing_record_exception
|
||||
* @throws \dml_exception
|
||||
* @param int $id Glossary entry id
|
||||
* @return bool
|
||||
*/
|
||||
public function check_access($id) {
|
||||
global $USER;
|
||||
|
||||
try {
|
||||
$entry = $this->get_entry($id);
|
||||
$cminfo = $this->get_cm('glossary', $entry->glossaryid, $entry->course);
|
||||
} catch (\dml_missing_record_exception $ex) {
|
||||
return \core_search\manager::ACCESS_DELETED;
|
||||
} catch (\dml_exception $ex) {
|
||||
return \core_search\manager::ACCESS_DENIED;
|
||||
}
|
||||
|
||||
if (!glossary_can_view_entry($entry, $cminfo)) {
|
||||
return \core_search\manager::ACCESS_DENIED;
|
||||
}
|
||||
|
||||
return \core_search\manager::ACCESS_GRANTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to glossary entry.
|
||||
*
|
||||
* @param \core_search\document $doc
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_doc_url(\core_search\document $doc) {
|
||||
global $USER;
|
||||
|
||||
// The post is already in static cache, we fetch it in self::search_access.
|
||||
$entry = $this->get_entry($doc->get('itemid'));
|
||||
$contextmodule = \context::instance_by_id($doc->get('contextid'));
|
||||
|
||||
if ($entry->approved == false && $entry->userid != $USER->id) {
|
||||
// The URL should change when the entry is not approved and it was not created by the user.
|
||||
$docparams = array('id' => $contextmodule->instanceid, 'mode' => 'approval');
|
||||
} else {
|
||||
$docparams = array('id' => $contextmodule->instanceid, 'mode' => 'entry', 'hook' => $doc->get('itemid'));
|
||||
|
||||
}
|
||||
return new \moodle_url('/mod/glossary/view.php', $docparams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the glossary.
|
||||
*
|
||||
* @param \core_search\document $doc
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_context_url(\core_search\document $doc) {
|
||||
$contextmodule = \context::instance_by_id($doc->get('contextid'));
|
||||
return new \moodle_url('/mod/glossary/view.php', array('id' => $contextmodule->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified glossary entry checking the internal cache.
|
||||
*
|
||||
* Store minimal information as this might grow.
|
||||
*
|
||||
* @throws \dml_exception
|
||||
* @param int $entryid
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function get_entry($entryid) {
|
||||
global $DB;
|
||||
|
||||
if (empty($this->entriesdata[$entryid])) {
|
||||
$this->entriesdata[$entryid] = $DB->get_record_sql("SELECT ge.*, g.course, g.defaultapproval FROM {glossary_entries} ge
|
||||
JOIN {glossary} g ON g.id = ge.glossaryid
|
||||
WHERE ge.id = ?", array('id' => $entryid), MUST_EXIST);
|
||||
}
|
||||
return $this->entriesdata[$entryid];
|
||||
}
|
||||
}
|
@ -273,6 +273,8 @@ $string['rssarticles_help'] = 'This setting specifies the number of glossary ent
|
||||
$string['rsssubscriberss'] = 'Display the RSS feed for \'{$a}\' concepts';
|
||||
$string['rsstype'] = 'RSS feed for this activity';
|
||||
$string['rsstype_help'] = 'To enable the RSS feed for this activity, select either concepts with author or concepts without author to be included in the feed.';
|
||||
$string['search:activity'] = 'Glossary activities';
|
||||
$string['search:entry'] = 'Glossary entries';
|
||||
$string['searchindefinition'] = 'Search full text';
|
||||
$string['secondaryglossary'] = 'Secondary glossary';
|
||||
$string['showall'] = 'Show \'ALL\' link';
|
||||
|
@ -3895,3 +3895,30 @@ function glossary_get_entry_by_id($id) {
|
||||
}
|
||||
return array_pop($entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current user can see the glossary entry.
|
||||
*
|
||||
* @since Moodle 3.1
|
||||
* @param stdClass $entry
|
||||
* @param cm_info $cminfo
|
||||
* @return bool
|
||||
*/
|
||||
function glossary_can_view_entry($entry, $cminfo) {
|
||||
global $USER;
|
||||
|
||||
$cm = $cminfo->get_course_module_record();
|
||||
$context = \context_module::instance($cm->id);
|
||||
|
||||
// Recheck uservisible although it should have already been checked in core_search.
|
||||
if ($cminfo->uservisible === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check approval.
|
||||
if (empty($entry->approved) && $entry->userid != $USER->id && !has_capability('mod/glossary:approve', $context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
216
mod/glossary/tests/search_test.php
Normal file
216
mod/glossary/tests/search_test.php
Normal file
@ -0,0 +1,216 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Glossary search unit tests.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @category test
|
||||
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/search/tests/fixtures/testable_core_search.php');
|
||||
require_once($CFG->dirroot . '/mod/glossary/tests/generator/lib.php');
|
||||
|
||||
/**
|
||||
* Provides the unit tests for glossary search.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @category test
|
||||
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class mod_glossary_search_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* @var string Area id
|
||||
*/
|
||||
protected $entryareaid = null;
|
||||
|
||||
public function setUp() {
|
||||
$this->resetAfterTest(true);
|
||||
set_config('enableglobalsearch', true);
|
||||
|
||||
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
|
||||
$search = testable_core_search::instance();
|
||||
|
||||
$this->entryareaid = \core_search\manager::generate_areaid('mod_glossary', 'entry');
|
||||
}
|
||||
|
||||
/**
|
||||
* Availability.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_search_enabled() {
|
||||
|
||||
$searcharea = \core_search\manager::get_search_area($this->entryareaid);
|
||||
list($componentname, $varname) = $searcharea->get_config_var_name();
|
||||
|
||||
// Enabled by default once global search is enabled.
|
||||
$this->assertTrue($searcharea->is_enabled());
|
||||
|
||||
set_config('enable' . $varname, false, $componentname);
|
||||
$this->assertFalse($searcharea->is_enabled());
|
||||
|
||||
set_config('enable' . $varname, true, $componentname);
|
||||
$this->assertTrue($searcharea->is_enabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexing contents.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_entries_indexing() {
|
||||
global $DB;
|
||||
|
||||
$searcharea = \core_search\manager::get_search_area($this->entryareaid);
|
||||
$this->assertInstanceOf('\mod_glossary\search\entry', $searcharea);
|
||||
|
||||
$user1 = self::getDataGenerator()->create_user();
|
||||
$user2 = self::getDataGenerator()->create_user();
|
||||
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
$course2 = self::getDataGenerator()->create_course();
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course1->id, 'student');
|
||||
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
|
||||
$this->setUser($user1);
|
||||
|
||||
// Approved entries by default glossary.
|
||||
$glossary1 = self::getDataGenerator()->create_module('glossary', $record);
|
||||
$entry1 = self::getDataGenerator()->get_plugin_generator('mod_glossary')->create_content($glossary1);
|
||||
$entry2 = self::getDataGenerator()->get_plugin_generator('mod_glossary')->create_content($glossary1);
|
||||
|
||||
// All records.
|
||||
$recordset = $searcharea->get_recordset_by_timestamp(0);
|
||||
$this->assertTrue($recordset->valid());
|
||||
$nrecords = 0;
|
||||
foreach ($recordset as $record) {
|
||||
$this->assertInstanceOf('stdClass', $record);
|
||||
$doc = $searcharea->get_document($record);
|
||||
$this->assertInstanceOf('\core_search\document', $doc);
|
||||
|
||||
// Static caches are working.
|
||||
$dbreads = $DB->perf_get_reads();
|
||||
$doc = $searcharea->get_document($record);
|
||||
|
||||
// The +1 is because we are not caching glossary alias (keywords) as they depend on a single entry.
|
||||
$this->assertEquals($dbreads + 1, $DB->perf_get_reads());
|
||||
$this->assertInstanceOf('\core_search\document', $doc);
|
||||
$nrecords++;
|
||||
}
|
||||
// If there would be an error/failure in the foreach above the recordset would be closed on shutdown.
|
||||
$recordset->close();
|
||||
$this->assertEquals(2, $nrecords);
|
||||
|
||||
// The +2 is to prevent race conditions.
|
||||
$recordset = $searcharea->get_recordset_by_timestamp(time() + 2);
|
||||
|
||||
// No new records.
|
||||
$this->assertFalse($recordset->valid());
|
||||
$recordset->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Document contents.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_entries_document() {
|
||||
global $DB;
|
||||
|
||||
$searcharea = \core_search\manager::get_search_area($this->entryareaid);
|
||||
|
||||
$user = self::getDataGenerator()->create_user();
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course1->id, 'teacher');
|
||||
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
|
||||
$this->setUser($user);
|
||||
$glossary = self::getDataGenerator()->create_module('glossary', $record);
|
||||
$entry = self::getDataGenerator()->get_plugin_generator('mod_glossary')->create_content($glossary);
|
||||
$entry->course = $glossary->course;
|
||||
|
||||
$doc = $searcharea->get_document($entry);
|
||||
$this->assertInstanceOf('\core_search\document', $doc);
|
||||
$this->assertEquals($entry->id, $doc->get('itemid'));
|
||||
$this->assertEquals($course1->id, $doc->get('courseid'));
|
||||
$this->assertEquals($user->id, $doc->get('userid'));
|
||||
$this->assertEquals($entry->concept, $doc->get('title'));
|
||||
$this->assertEquals($entry->definition, $doc->get('content'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Document accesses.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_entries_access() {
|
||||
global $DB;
|
||||
|
||||
// Returns the instance as long as the component is supported.
|
||||
$searcharea = \core_search\manager::get_search_area($this->entryareaid);
|
||||
|
||||
$user1 = self::getDataGenerator()->create_user();
|
||||
$user2 = self::getDataGenerator()->create_user();
|
||||
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
$course2 = self::getDataGenerator()->create_course();
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, 'teacher');
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course1->id, 'student');
|
||||
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
|
||||
// Approved entries by default glossary, created by teacher.
|
||||
$this->setUser($user1);
|
||||
$glossary1 = self::getDataGenerator()->create_module('glossary', $record);
|
||||
$teacherapproved = self::getDataGenerator()->get_plugin_generator('mod_glossary')->create_content($glossary1);
|
||||
$teachernotapproved = self::getDataGenerator()->get_plugin_generator('mod_glossary')->create_content($glossary1, array('approved' => false));
|
||||
|
||||
// Entries need to be approved and created by student.
|
||||
$glossary2 = self::getDataGenerator()->create_module('glossary', $record);
|
||||
$this->setUser($user2);
|
||||
$studentapproved = self::getDataGenerator()->get_plugin_generator('mod_glossary')->create_content($glossary2);
|
||||
$studentnotapproved = self::getDataGenerator()->get_plugin_generator('mod_glossary')->create_content($glossary2, array('approved' => false));
|
||||
|
||||
// Activity hidden to students.
|
||||
$this->setUser($user1);
|
||||
$glossary3 = self::getDataGenerator()->create_module('glossary', $record);
|
||||
$hidden = self::getDataGenerator()->get_plugin_generator('mod_glossary')->create_content($glossary3);
|
||||
set_coursemodule_visible($glossary3->cmid, 0);
|
||||
|
||||
$this->setUser($user2);
|
||||
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $searcharea->check_access($teacherapproved->id));
|
||||
$this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($teachernotapproved->id));
|
||||
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $searcharea->check_access($studentapproved->id));
|
||||
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $searcharea->check_access($studentnotapproved->id));
|
||||
$this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($hidden->id));
|
||||
}
|
||||
}
|
37
mod/imscp/classes/search/activity.php
Normal file
37
mod/imscp/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_imscp activities.
|
||||
*
|
||||
* @package mod_imscp
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_imscp\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_imscp activities.
|
||||
*
|
||||
* @package mod_imscp
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -43,4 +43,5 @@ $string['page-mod-imscp-x'] = 'Any IMS content package module page';
|
||||
$string['packagefile'] = 'Package file';
|
||||
$string['pluginadministration'] = 'IMSCP administration';
|
||||
$string['pluginname'] = 'IMS content package';
|
||||
$string['search:activity'] = 'IMS content package activities';
|
||||
$string['toc'] = 'TOC';
|
||||
|
64
mod/label/classes/search/activity.php
Normal file
64
mod/label/classes/search/activity.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?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 mod_label activities.
|
||||
*
|
||||
* @package mod_label
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_label\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_label activities.
|
||||
*
|
||||
* Although there is no name field the intro value is stored internally, so no need
|
||||
* to overwrite self::get_document.
|
||||
*
|
||||
* @package mod_label
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
|
||||
/**
|
||||
* Overwritten as labels are displayed in-course.
|
||||
*
|
||||
* @param \core_search\document $doc
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_doc_url(\core_search\document $doc) {
|
||||
$cminfo = $this->get_cm($this->get_module_name(), strval($doc->get('itemid')), $doc->get('courseid'));
|
||||
return new \moodle_url('/course/view.php', array('id' => $doc->get('courseid')), 'module-' . $cminfo->id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwritten as labels are displayed in-course. Link to the course.
|
||||
*
|
||||
* @param \core_search\document $doc
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_context_url(\core_search\document $doc) {
|
||||
return new \moodle_url('/course/view.php', array('id' => $doc->get('courseid')));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -45,3 +45,4 @@ $string['modulename_link'] = 'mod/label/view';
|
||||
$string['modulenameplural'] = 'Labels';
|
||||
$string['pluginadministration'] = 'Label administration';
|
||||
$string['pluginname'] = 'Label';
|
||||
$string['search:activity'] = 'Label activities';
|
||||
|
37
mod/lesson/classes/search/activity.php
Normal file
37
mod/lesson/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_lesson activities.
|
||||
*
|
||||
* @package mod_lesson
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_lesson\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_lesson activities.
|
||||
*
|
||||
* @package mod_lesson
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -441,6 +441,7 @@ $string['savepage'] = 'Save page';
|
||||
$string['score'] = 'Score';
|
||||
$string['score_help'] = 'Score is only used when custom scoring is enabled. Each answer can then be given a numerical point value (positive or negative).';
|
||||
$string['scores'] = 'Scores';
|
||||
$string['search:activity'] = 'Lesson activities';
|
||||
$string['secondpluswrong'] = 'Not quite. Would you like to try again?';
|
||||
$string['selectaqtype'] = 'Select a question type';
|
||||
$string['shortanswer'] = 'Short answer';
|
||||
|
37
mod/lti/classes/search/activity.php
Normal file
37
mod/lti/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_lti activities.
|
||||
*
|
||||
* @package mod_lti
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_lti\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_lti activities.
|
||||
*
|
||||
* @package mod_lti
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -374,6 +374,7 @@ may not require a resource key.';
|
||||
$string['resourceurl'] = 'Resource URL';
|
||||
$string['return_to_course'] = 'Click <a href="{$a->link}" target="_top">here</a> to return to the course.';
|
||||
$string['saveallfeedback'] = 'Save all my feedback';
|
||||
$string['search:activity'] = 'LTI activities';
|
||||
$string['secure_icon_url'] = 'Secure icon URL';
|
||||
$string['secure_icon_url_help'] = 'Similar to the icon URL, but used if the user accessing Moodle securely through SSL. The main purpose for this field is to prevent
|
||||
the browser from warning the user if the underlying page was accessed over SSL, but requesting to show an unsecure image.';
|
||||
|
76
mod/page/classes/search/activity.php
Normal file
76
mod/page/classes/search/activity.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?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 mod_page activities.
|
||||
*
|
||||
* @package mod_page
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_page\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_page activities.
|
||||
*
|
||||
* @package mod_page
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the document associated with this activity.
|
||||
*
|
||||
* Overwriting base_activity method as page contents field is required,
|
||||
* description field is not.
|
||||
*
|
||||
* @param stdClass $record
|
||||
* @return \core_search\document
|
||||
*/
|
||||
public function get_document($record) {
|
||||
|
||||
try {
|
||||
$cm = $this->get_cm($this->get_module_name(), $record->id, $record->course);
|
||||
$context = \context_module::instance($cm->id);
|
||||
} catch (\dml_missing_record_exception $ex) {
|
||||
// Notify it as we run here as admin, we should see everything.
|
||||
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' .
|
||||
$ex->getMessage(), DEBUG_DEVELOPER);
|
||||
return false;
|
||||
} catch (\dml_exception $ex) {
|
||||
// Notify it as we run here as admin, we should see everything.
|
||||
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prepare associative array with data from DB.
|
||||
$doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
|
||||
$doc->set('title', $record->name);
|
||||
$doc->set('content', editor_input_to_text($record->content, $record->contentformat));
|
||||
$doc->set('contextid', $context->id);
|
||||
$doc->set('type', \core_search\manager::TYPE_TEXT);
|
||||
$doc->set('courseid', $record->course);
|
||||
$doc->set('modified', $record->timemodified);
|
||||
$doc->set('description1', editor_input_to_text($record->intro, $record->introformat));
|
||||
|
||||
return $doc;
|
||||
}
|
||||
}
|
@ -60,3 +60,4 @@ $string['printheading'] = 'Display page name';
|
||||
$string['printheadingexplain'] = 'Display page name above content?';
|
||||
$string['printintro'] = 'Display page description';
|
||||
$string['printintroexplain'] = 'Display page description above content?';
|
||||
$string['search:activity'] = 'Page activities';
|
||||
|
37
mod/quiz/classes/search/activity.php
Normal file
37
mod/quiz/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_quiz activities.
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_quiz\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_quiz activities.
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -806,6 +806,7 @@ $string['savingnewgradeforquestion'] = 'Saving new grade for question id {$a}.';
|
||||
$string['savingnewmaximumgrade'] = 'Saving new maximum grade.';
|
||||
$string['score'] = 'Raw score';
|
||||
$string['scores'] = 'Scores';
|
||||
$string['search:activity'] = 'Quiz activities';
|
||||
$string['sectionheadingedit'] = 'Edit heading \'{$a}\'';
|
||||
$string['sectionheadingremove'] = 'Remove heading \'{$a}\'';
|
||||
$string['seequestions'] = '(See questions)';
|
||||
|
37
mod/resource/classes/search/activity.php
Normal file
37
mod/resource/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_resource activities.
|
||||
*
|
||||
* @package mod_resource
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_resource\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_resource activities.
|
||||
*
|
||||
* @package mod_resource
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -97,6 +97,7 @@ $string['resourcedetails_typedate'] = '{$a->type} {$a->date}';
|
||||
$string['resourcedetails_sizetypedate'] = '{$a->size} {$a->type} {$a->date}';
|
||||
$string['resource:exportresource'] = 'Export resource';
|
||||
$string['resource:view'] = 'View resource';
|
||||
$string['search:activity'] = 'Resource activities';
|
||||
$string['selectmainfile'] = 'Please select the main file by clicking the icon next to file name.';
|
||||
$string['showdate'] = 'Show upload/modified date';
|
||||
$string['showdate_desc'] = 'Display upload/modified date on course page?';
|
||||
|
37
mod/scorm/classes/search/activity.php
Normal file
37
mod/scorm/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_scorm activities.
|
||||
*
|
||||
* @package mod_scorm
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_scorm\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_scorm activities.
|
||||
*
|
||||
* @package mod_scorm
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -354,6 +354,7 @@ $string['scormtype_help'] = 'This setting determines how the package is included
|
||||
$string['scorm:viewreport'] = 'View reports';
|
||||
$string['scorm:viewscores'] = 'View scores';
|
||||
$string['scrollbars'] = 'Allow the window to be scrolled';
|
||||
$string['search:activity'] = 'SCORM package activities';
|
||||
$string['selectall'] = 'Select all';
|
||||
$string['selectnone'] = 'Deselect all';
|
||||
$string['show'] = 'Show';
|
||||
|
37
mod/survey/classes/search/activity.php
Normal file
37
mod/survey/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_survey activities.
|
||||
*
|
||||
* @package mod_survey
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_survey\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_survey activities.
|
||||
*
|
||||
* @package mod_survey
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -237,6 +237,7 @@ $string['savednotes'] = 'Your notes were saved';
|
||||
$string['scaleagree5'] = 'Strongly disagree,Somewhat disagree,Neither agree nor disagree,Somewhat agree,Strongly agree';
|
||||
$string['scales'] = 'Scales';
|
||||
$string['scaletimes5'] = 'Almost never,Seldom,Sometimes,Often,Almost always';
|
||||
$string['search:activity'] = 'Survey activities';
|
||||
$string['seemoredetail'] = 'Click here to see more detail';
|
||||
$string['selectedquestions'] = 'Selected questions from a scale, all students';
|
||||
$string['summary'] = 'Summary';
|
||||
|
55
mod/url/classes/search/activity.php
Normal file
55
mod/url/classes/search/activity.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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 mod_url activities.
|
||||
*
|
||||
* @package mod_url
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_url\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_url activities.
|
||||
*
|
||||
* @package mod_url
|
||||
* @copyright 2016 Dan Poltawski
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
|
||||
/**
|
||||
* Returns the document associated with this activity.
|
||||
*
|
||||
* Overwrites base_activity to add the provided URL as description.
|
||||
*
|
||||
* @param stdClass $record
|
||||
* @return \core_search\document
|
||||
*/
|
||||
public function get_document($record) {
|
||||
$doc = parent::get_document($record);
|
||||
if (!$doc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$doc->set('description1', $record->externalurl);
|
||||
return $doc;
|
||||
}
|
||||
}
|
@ -67,6 +67,7 @@ $string['popupwidthexplain'] = 'Specifies default width of popup windows.';
|
||||
$string['printintro'] = 'Display URL description';
|
||||
$string['printintroexplain'] = 'Display URL description below content? Some display types may not display description even if enabled.';
|
||||
$string['rolesinparams'] = 'Include role names in parameters';
|
||||
$string['search:activity'] = 'URL activities';
|
||||
$string['serverurl'] = 'Server URL';
|
||||
$string['url:addinstance'] = 'Add a new URL resource';
|
||||
$string['url:view'] = 'View URL';
|
||||
|
37
mod/wiki/classes/search/activity.php
Normal file
37
mod/wiki/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_wiki activities.
|
||||
*
|
||||
* @package mod_wiki
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_wiki\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_wiki activities.
|
||||
*
|
||||
* @package mod_wiki
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -213,6 +213,7 @@ $string['return'] = 'Go back';
|
||||
$string['save'] = 'Save';
|
||||
$string['saving'] = 'Saving wiki page';
|
||||
$string['savingerror'] = 'Saving error';
|
||||
$string['search:activity'] = 'Wiki activities';
|
||||
$string['searchcontent'] = 'Search in page content';
|
||||
$string['searchresult'] = 'Search results:';
|
||||
$string['searchterms'] = 'Search terms';
|
||||
|
37
mod/workshop/classes/search/activity.php
Normal file
37
mod/workshop/classes/search/activity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 mod_workshop activities.
|
||||
*
|
||||
* @package mod_workshop
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_workshop\search;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Search area for mod_workshop activities.
|
||||
*
|
||||
* @package mod_workshop
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class activity extends \core_search\area\base_activity {
|
||||
}
|
@ -239,6 +239,7 @@ $string['saveandclose'] = 'Save and close';
|
||||
$string['saveandcontinue'] = 'Save and continue editing';
|
||||
$string['saveandpreview'] = 'Save and preview';
|
||||
$string['saveandshownext'] = 'Save and show next';
|
||||
$string['search:activity'] = 'Workshop activities';
|
||||
$string['selfassessmentdisabled'] = 'Self-assessment disabled';
|
||||
$string['showingperpage'] = 'Showing {$a} items per page';
|
||||
$string['showingperpagechange'] = 'Change ...';
|
||||
|
Loading…
x
Reference in New Issue
Block a user