Skip to content

Commit

Permalink
fixes result list ordering issue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
diml committed May 31, 2008
1 parent fad5293 commit 27af904
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 46 deletions.
8 changes: 5 additions & 3 deletions search/documents/assignment_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(&$assignmentitem, $assignment_module_id, $itemtype,
$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);
}
}

Expand Down Expand Up @@ -343,8 +343,10 @@ function assignment_check_text_access($path, $itemtype, $this_id, $user, $group_
*/
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);
Expand Down
18 changes: 8 additions & 10 deletions search/documents/chat_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class ChatTrackSearchDocument extends SearchDocument {
/**
* 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;
Expand All @@ -50,10 +50,10 @@ public function __construct(&$chatsession, $chat_module_id, $course_id, $group_i
$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);
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ function chat_get_content_for_index(&$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);
}
}
}
Expand Down Expand Up @@ -207,7 +207,7 @@ function chat_single_document($id, $itemtype) {
$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;
}
}
Expand Down Expand Up @@ -255,8 +255,7 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c

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);
Expand All @@ -271,9 +270,8 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c

//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;
}
Expand Down
13 changes: 6 additions & 7 deletions search/documents/data_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(&$record, $course_id, $context_id) {
$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);
}
}

Expand Down Expand Up @@ -348,9 +348,8 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c

//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;
}
Expand All @@ -368,7 +367,7 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
// 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;
}
Expand All @@ -377,7 +376,7 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
// 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;
}
Expand All @@ -387,12 +386,12 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
// 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;
}
Expand Down
8 changes: 6 additions & 2 deletions search/documents/forum_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(&$post, $forum_id, $course_id, $itemtype, $context_i
$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);
}
}

Expand Down Expand Up @@ -87,6 +87,7 @@ function forum_get_content_for_index(&$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');
Expand All @@ -96,11 +97,13 @@ function forum_get_content_for_index(&$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);
Expand All @@ -109,6 +112,7 @@ function forum_get_content_for_index(&$forum) {
}
}
}
mtrace("Finished discussion");
return $documents;
}

Expand Down
6 changes: 3 additions & 3 deletions search/documents/glossary_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(&$entry, $course_id, $context_id) {
$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);
}
}

Expand Down Expand Up @@ -227,7 +227,7 @@ function glossary_check_text_access($path, $itemtype, $this_id, $user, $group_id
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);
Expand All @@ -251,7 +251,7 @@ function glossary_check_text_access($path, $itemtype, $this_id, $user, $group_id
* @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');
}

?>
4 changes: 2 additions & 2 deletions search/documents/lesson_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(&$page, $lessonmodule_id, $course_id, $itemtype, $co
// 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);
}
}

Expand Down Expand Up @@ -210,7 +210,7 @@ function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id,
*
*/
function lesson_link_post_processing($title){
return mb_convert_encoding($title, 'UTF-8', 'auto');
return mb_convert_encoding($title, 'auto', 'UTF-8');
}

?>
6 changes: 3 additions & 3 deletions search/documents/physical_doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
/**
* 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;
Expand All @@ -44,7 +44,7 @@ function get_text_for_indexing_doc(&$resource, $directfile = ''){
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 '';
Expand Down
4 changes: 2 additions & 2 deletions search/documents/physical_htm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

/**
* @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;
Expand Down
4 changes: 2 additions & 2 deletions search/documents/physical_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

/**
* @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;
Expand Down
4 changes: 2 additions & 2 deletions search/documents/physical_ppt.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@

/**
* @param object $resource
* @uses CFG, USER
* @uses $CFG
*/
function get_text_for_indexing_ppt(&$resource, $directfile = ''){
global $CFG, $USER;
global $CFG;

$indextext = null;

Expand Down
6 changes: 3 additions & 3 deletions search/documents/physical_swf.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

/**
* @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;
Expand All @@ -36,6 +36,7 @@ function get_text_for_indexing_swf(&$resource, $directfile = ''){

// 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 {
Expand All @@ -44,7 +45,6 @@ function get_text_for_indexing_swf(&$resource, $directfile = ''){
} 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);

Expand Down
4 changes: 2 additions & 2 deletions search/documents/physical_txt.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

/**
* @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;
Expand Down
4 changes: 2 additions & 2 deletions search/documents/physical_xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

/**
* @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;
Expand Down
5 changes: 3 additions & 2 deletions search/documents/resource_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(&$resource, $context_id) {
$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

Expand Down Expand Up @@ -323,6 +323,7 @@ function resource_check_text_access($path, $itemtype, $this_id, $user, $group_id
* @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');
}
?>
2 changes: 1 addition & 1 deletion search/documents/wiki_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(&$page, $wiki_id, $course_id, $group_id, $user_id, $
$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);
}
}

Expand Down

0 comments on commit 27af904

Please sign in to comment.