fixes result list ordering issue
authordiml <diml>
Sat, 31 May 2008 17:09:59 +0000 (17:09 +0000)
committerdiml <diml>
Sat, 31 May 2008 17:09:59 +0000 (17:09 +0000)
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

15 files changed:
search/documents/assignment_document.php
search/documents/chat_document.php
search/documents/data_document.php
search/documents/forum_document.php
search/documents/glossary_document.php
search/documents/lesson_document.php
search/documents/physical_doc.php
search/documents/physical_htm.php
search/documents/physical_pdf.php
search/documents/physical_ppt.php
search/documents/physical_swf.php
search/documents/physical_txt.php
search/documents/physical_xml.php
search/documents/resource_document.php
search/documents/wiki_document.php

index 3dc0087d21cebd56b93b886b395517336f087f74..475f9a524a391efcf46c2ddaef4f89d754e1d872 100644 (file)
@@ -49,7 +49,7 @@ class AssignmentSearchDocument extends SearchDocument {
         $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);
     } 
 }
 
@@ -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);
index 371c8584c97689e9a034d6db89feb263af121b46..aca20523bce0a334331a8ab1c56ab970ccccc105 100644 (file)
@@ -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;
@@ -50,10 +50,10 @@ class ChatTrackSearchDocument extends SearchDocument {
         $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);
     } 
 }
 
@@ -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);
                 }
             }
         }
@@ -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;
         }
     }
@@ -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);
@@ -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;
     }
index 655b5d5ae0fe8168aa1944ad15fb9a5d282e2101..3462c123bd07467cca2d622ff6e3dc9ddf48e2cb 100644 (file)
@@ -54,7 +54,7 @@ class DataSearchDocument extends SearchDocument {
         $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);
     } 
 }
 
@@ -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;
     }
@@ -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;
     }
@@ -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;
     }
@@ -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;
         }
index a26afd4a4ced146ad98fbfe4fc2924420e38fe2b..5393752841992d416a686652c0aa1b9b39019f48 100644 (file)
@@ -51,7 +51,7 @@ class ForumSearchDocument extends SearchDocument {
         $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);
     } 
 }
 
@@ -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');
@@ -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);
@@ -109,6 +112,7 @@ function forum_get_content_for_index(&$forum) {
             } 
         } 
     } 
+    mtrace("Finished discussion");
     return $documents;
 }
 
index 2ec59ef8fd6b8adab350f919adc0a816171e8c64..8950a1c6e0c821f82382367e3086559e8fad3054 100644 (file)
@@ -52,7 +52,7 @@ class GlossarySearchDocument extends SearchDocument {
         $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);
     }
 }
 
@@ -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);
@@ -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');
 }
 
 ?>
\ No newline at end of file
index 674dc0b63ca57f37cb72f6747ed6ee0e216d28ac..476556bde0a0d8fd4aa0a304b7ab4fca8a9f3ce7 100644 (file)
@@ -49,7 +49,7 @@ class LessonPageSearchDocument extends SearchDocument {
         // 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);
     } 
 }
 
@@ -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');
 }
 
 ?>
\ No newline at end of file
index 9586ff12cc55e51ff3575ea794377b30286efc5e..2cd48cd4fae087787d189cb8bb16dcb3da6ebb47 100644 (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;
@@ -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 '';
index aa3e6bc0f11245e8c9e91589fea60b044c95e7f7..6cfe5967f522aa1bb0945ec3375c999b5095ad5e 100644 (file)
 
 /**
 * @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;
index 347b61f975e44bc251d13d47e6a8529d3b10a44e..f1b73f7eaf017c9c9b9cbb56d7a2f01e76199c82 100644 (file)
 
 /**
 * @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;
index 840d7dff266a7ef17565b9bda58e9ec9f123e3ea..76b97ae7bd1a8c6e8d4b57701b94c7937431685f 100644 (file)
 
 /**
 * @param object $resource
-* @uses CFG, USER
+* @uses $CFG
 */
 function get_text_for_indexing_ppt(&$resource, $directfile = ''){
-    global $CFG, $USER;
+    global $CFG;
 
     $indextext = null;
     
index b6d33445a04c7defb468a1382ba6583a640efa62..2d8a2628c8bdae170228a1fcd170cd39945dbd0a 100644 (file)
 
 /**
 * @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;
@@ -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 {
@@ -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);
             
index 4917f032b6742bfe5f2b3cfb32fd93d024e193ba..9db35f1bad1318b401a0b3ebee1f520dec23bcff 100644 (file)
 
 /**
 * @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;
index 68e39c5c2bb841a40379a242d628adf1eb062f09..9654b54e4f9277f9b9c83fff3d5173e6027b0466 100644 (file)
 
 /**
 * @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;
index 844da54bc7abb5cbb530d22c3b507d4e2bbd409e..bc73bf89d719f16d985f7bad287bd478426df402 100644 (file)
@@ -44,7 +44,7 @@ class ResourceSearchDocument extends SearchDocument {
         $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
 
@@ -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');
 }
 ?>
\ No newline at end of file
index d23ca9e8a4b005f7f3e7912e5efe7a1507c44bd2..e67f7154b0af051f87015ee80b7c5e985ea03ca1 100644 (file)
@@ -50,7 +50,7 @@ class WikiSearchDocument extends SearchDocument {
         $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);
     } 
 }