engine give nicer results with adequate pagination.
Adding icon and reference to course origine.
Generalizing replacement of isadmin by doanithing capability check
should contribute to close many global search related issues from
http://tracker.moodle.org/browse/MDL-14646
startpoint
$data->assignmenttype = $assignmentitem['assignmenttype'];
// construct the parent class
- parent::__construct($doc, $data, $course_id, 0, 0, PATH_FOR_SEARCH_TYPE_ASSIGNMENT);
+ parent::__construct($doc, $data, $course_id, 0, 0, 'mod/'.SEARCH_TYPE_ASSIGNMENT);
}
}
*/
function assignment_link_post_processing($title){
- function search_assignment_getstring($matches){
- return get_string($matches[1], 'assignment');
+ if (!function_exists('search_assignment_getstring')){
+ function search_assignment_getstring($matches){
+ return get_string($matches[1], 'assignment');
+ }
}
$title = preg_replace_callback('/^(description|submitted)/', 'search_assignment_getstring', $title);
/**
* constructor
*/
- public function __construct(&$chatsession, $chat_module_id, $course_id, $group_id, $context_id) {
+ public function __construct(&$chatsession, $chat_id, $chat_module_id, $course_id, $group_id, $context_id) {
// generic information; required
- $doc->docid = $chat_module_id.'-'.$chatsession['sessionstart'].'-'.$chatsession['sessionend'];
+ $doc->docid = $chat_id.'-'.$chatsession['sessionstart'].'-'.$chatsession['sessionend'];
$doc->documenttype = SEARCH_TYPE_CHAT;
$doc->itemtype = 'session';
$doc->contextid = $context_id;
$doc->url = chat_make_link($chat_module_id, $chatsession['sessionstart'], $chatsession['sessionend']);
// module specific information; optional
- $data->chat = $chat_module_id;
+ $data->chat = $chat_id;
// construct the parent class
- parent::__construct($doc, $data, $course_id, $group_id, 0, PATH_FOR_SEARCH_TYPE_CHAT);
+ parent::__construct($doc, $data, $course_id, $group_id, 0, 'mod/'.SEARCH_TYPE_CHAT);
}
}
foreach($aTrack->sessionusers as $aUserId){
$user = get_record('user', 'id', $aUserId);
$aTrack->authors = ($user) ? fullname($user) : '' ;
- $documents[] = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
+ $documents[] = new ChatTrackSearchDocument(get_object_vars($aTrack), $chat->id, $cm->id, $chat->course, $aTrack->groupid, $context->id);
}
}
}
$tracks = chat_get_session_tracks($chat->id, $sessionstart, $sessionstart);
if ($tracks){
$aTrack = $tracks[0];
- $document = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
+ $document = new ChatTrackSearchDocument(get_object_vars($aTrack), $chat_id, $cm->id, $chat->course, $aTrack->groupid, $context->id);
return $document;
}
}
include_once("{$CFG->dirroot}/{$path}/lib.php");
- list($chat_id, $sessionstart, $sessionend) = split('-', $id);
-
+ list($chat_id, $sessionstart, $sessionend) = split('-', $this_id);
// get the chat session and all related stuff
$chat = get_record('chat', 'id', $chat_id);
$context = get_record('context', 'id', $context_id);
//group consistency check : checks the following situations about groups
// trap if user is not same group and groups are separated
- $current_group = get_current_group($course->id);
$course = get_record('course', 'id', $chat->course);
- if ((groupmode($course, $cm) == SEPARATEGROUPS) && !groups_is_member($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
+ if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : chat element is in separated group ";
return false;
}
$data->database = $record['dataid'];
// construct the parent class
- parent::__construct($doc, $data, $course_id, $record['groupid'], $record['userid'], PATH_FOR_SEARCH_TYPE_DATA);
+ parent::__construct($doc, $data, $course_id, $record['groupid'], $record['userid'], 'mod/'.SEARCH_TYPE_DATA);
}
}
//group consistency check : checks the following situations about groups
// trap if user is not same group and groups are separated
- $current_group = get_current_group($course->id);
$course = get_record('course', 'id', $data->course);
- if ((groupmode($course, $cm) == SEPARATEGROUPS) && !groups_is_member($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
+ if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : separated group owned resource ";
return false;
}
// trap if unapproved and has not approval capabilities
// TODO : report a potential capability lack of : mod/data:approve
$approval = get_field('data_records', 'approved', 'id', $record->id);
- if (!$approval && !isteacher($data->course) && !has_capability('mod/data:manageentries', $context)){
+ if (!$approval && !has_capability('mod/data:manageentries', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : unapproved resource ";
return false;
}
// trap if too few records
// TODO : report a potential capability lack of : mod/data:viewhiddenentries
$recordsAmount = count_records('data_records', 'dataid', $data->id);
- if ($data->requiredentriestoview > $recordsAmount && !isteacher($data->course) && !has_capability('mod/data:manageentries', $context)) {
+ if ($data->requiredentriestoview > $recordsAmount && !has_capability('mod/data:manageentries', $context)) {
if (!empty($CFG->search_access_debug)) echo "search reject : not enough records to view ";
return false;
}
// TODO : report a potential capability lack of : mod/data:viewhiddenentries
$now = usertime(time());
if ($data->timeviewfrom > 0)
- if ($now < $data->timeviewfrom && !isteacher($data->course) && !has_capability('mod/data:manageentries', $context)) {
+ if ($now < $data->timeviewfrom && !has_capability('mod/data:manageentries', $context)) {
if (!empty($CFG->search_access_debug)) echo "search reject : still not open activity ";
return false;
}
if ($data->timeviewto > 0)
- if ($now > $data->timeviewto && !isteacher($data->course) && !has_capability('mod/data:manageentries', $context)) {
+ if ($now > $data->timeviewto && !has_capability('mod/data:manageentries', $context)) {
if (!empty($CFG->search_access_debug)) echo "search reject : closed activity ";
return false;
}
$data->forum = $forum_id;
$data->discussion = $post['discussion'];
- parent::__construct($doc, $data, $course_id, $post['groupid'], $post['userid'], PATH_FOR_SEARCH_TYPE_FORUM);
+ parent::__construct($doc, $data, $course_id, $post['groupid'], $post['userid'], 'mod/'.SEARCH_TYPE_FORUM);
}
}
if (!$forum) return $documents;
$posts = forum_get_discussions_fast($forum->id);
+ mtrace("Found ".count($posts)." discussions to analyse in forum ".$forum->name);
if (!$posts) return $documents;
$coursemodule = get_field('modules', 'id', 'name', 'forum');
foreach($posts as $aPost) {
$aPost->itemtype = 'head';
if ($aPost) {
- if (strlen($aPost->message) > 0) {
+ if (!empty($aPost->message)) {
+ echo "*";
$documents[] = new ForumSearchDocument(get_object_vars($aPost), $forum->id, $forum->course, 'head', $context->id);
}
if ($children = forum_get_child_posts_fast($aPost->id, $forum->id)) {
foreach($children as $aChild) {
+ echo ".";
$aChild->itemtype = 'post';
if (strlen($aChild->message) > 0) {
$documents[] = new ForumSearchDocument(get_object_vars($aChild), $forum->id, $forum->course, 'post', $context->id);
}
}
}
+ mtrace("Finished discussion");
return $documents;
}
$data->glossary = $entry['glossaryid'];
// construct the parent class
- parent::__construct($doc, $data, $course_id, -1, $entry['userid'], PATH_FOR_SEARCH_TYPE_GLOSSARY);
+ parent::__construct($doc, $data, $course_id, -1, $entry['userid'], 'mod/'.SEARCH_TYPE_GLOSSARY);
}
}
global $CFG;
// get the glossary object and all related stuff
- $entry = get_record('glossary_entries', 'id', $id);
+ $entry = get_record('glossary_entries', 'id', $this_id);
$glossary = get_record('glossary', 'id', $entry->glossaryid);
$context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $context->instanceid);
* @param string $title
*/
function glossary_link_post_processing($title){
- return mb_convert_encoding($title, 'UTF-8', 'auto');
+ return mb_convert_encoding($title, 'auto', 'UTF-8');
}
?>
\ No newline at end of file
// module specific information
$data->lesson = $page['lessonid'];
- parent::__construct($doc, $data, $course_id, 0, 0, PATH_FOR_SEARCH_TYPE_LESSON);
+ parent::__construct($doc, $data, $course_id, 0, 0, 'mod/'.SEARCH_TYPE_LESSON);
}
}
*
*/
function lesson_link_post_processing($title){
- return mb_convert_encoding($title, 'UTF-8', 'auto');
+ return mb_convert_encoding($title, 'auto', 'UTF-8');
}
?>
\ No newline at end of file
/**
* MS Word extractor
* @param object $resource
-* @uses CFG, USER
+* @uses $CFG
*/
function get_text_for_indexing_doc(&$resource, $directfile = ''){
- global $CFG, $USER;
+ global $CFG;
// SECURITY : do not allow non admin execute anything on system !!
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
mtrace("Executing : $text_converter_cmd");
$result = shell_exec($text_converter_cmd);
if ($result){
- return mb_convert_encoding($result, 'UTF8', 'auto');
+ return mb_convert_encoding($result, 'UTF-8', 'auto');
} else {
mtrace('Error with MSWord to text converter command : execution failed. ');
return '';
/**
* @param object $resource
-* @uses CFG, USER
+* @uses $CFG
*/
function get_text_for_indexing_htm(&$resource, $directfile = ''){
- global $CFG, $USER;
+ global $CFG;
// SECURITY : do not allow non admin execute anything on system !!
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
/**
* @param object $resource
-* @uses CFG, USER
+* @uses $CFG
*/
function get_text_for_indexing_pdf(&$resource, $directfile = ''){
- global $CFG, $USER;
+ global $CFG;
// SECURITY : do not allow non admin execute anything on system !!
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
/**
* @param object $resource
-* @uses CFG, USER
+* @uses $CFG
*/
function get_text_for_indexing_ppt(&$resource, $directfile = ''){
- global $CFG, $USER;
+ global $CFG;
$indextext = null;
/**
* @param object $resource
-* @uses CFG, USER
+* @uses $CFG
*/
function get_text_for_indexing_swf(&$resource, $directfile = ''){
- global $CFG, $USER;
+ global $CFG;
// SECURITY : do not allow non admin execute anything on system !!
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
// just call pdftotext over stdout and capture the output
if (!empty($CFG->block_search_pdf_to_text_cmd)){
+ $command = trim($CFG->block_search_swf_to_text_cmd);
if (!file_exists("{$moodleroot}{$command}")){
mtrace('Error with swf to text converter command : executable not found as '.$moodleroot.$command);
} else {
} else {
$file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
}
- $command = trim($CFG->block_search_swf_to_text_cmd);
$text_converter_cmd = "{$moodleroot}{$command} -t $file";
$result = shell_exec($text_converter_cmd);
/**
* @param object $resource
-* @uses CFG, USER
+* @uses $CFG
*/
function get_text_for_indexing_txt(&$resource, $directfile = ''){
- global $CFG, $USER;
+ global $CFG;
// SECURITY : do not allow non admin execute anything on system !!
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
/**
* @param object $resource
-* @uses CFG, USER
+* @uses $CFG
*/
function get_text_for_indexing_xml(&$resource, $directfile = ''){
- global $CFG, $USER;
+ global $CFG;
// SECURITY : do not allow non admin execute anything on system !!
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
$data = array();
// construct the parent class
- parent::__construct($doc, $data, $resource['course'], 0, 0, PATH_FOR_SEARCH_TYPE_RESOURCE);
+ parent::__construct($doc, $data, $resource['course'], 0, 0, 'mod/'.SEARCH_TYPE_RESOURCE);
} //constructor
} //ResourceSearchDocument
* @param string $title
*/
function resource_link_post_processing($title){
- return mb_convert_encoding($title, 'UTF-8', 'auto');
+ // return mb_convert_encoding($title, 'UTF-8', 'auto');
+ return mb_convert_encoding($title, 'auto', 'UTF-8');
}
?>
\ No newline at end of file
$data->wiki = $wiki_id;
// construct the parent class
- parent::__construct($doc, $data, $course_id, $group_id, $user_id, PATH_FOR_SEARCH_TYPE_WIKI);
+ parent::__construct($doc, $data, $course_id, $group_id, $user_id, 'mod/'.SEARCH_TYPE_WIKI);
}
}