# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/search/documents/assignment_document.php
--- moodle/search/documents/assignment_document.php Base (1.7)
+++ moodle/search/documents/assignment_document.php Locally Modified (Based On 1.7)
@@ -30,7 +30,7 @@
     /**
     * constructor
     */
-    public function __construct(&$assignmentitem, $assignment_module_id, $itemtype, $course_id, $owner_id, $context_id) {
+    public function __construct(&$assignmentitem, $assignment_module_id, $itemtype, $course_id, $owner_id, $context_id , $submissionoffset = null) {
         // generic information; required
         $doc->docid         = $assignmentitem['id'];
         $doc->documenttype  = SEARCH_TYPE_ASSIGNMENT;
@@ -43,8 +43,13 @@
 
         //remove '(ip.ip.ip.ip)' from chat author list
         $doc->author        = $assignmentitem['authors'];
-        $doc->contents      = $assignmentitem['description'];
+        if ($itemtype == 'intro') {
+            $doc->contents      = $assignmentitem['intro'];
         $doc->url           = assignment_make_link($assignment_module_id, $itemtype, $owner_id);
+        } else {
+            $doc->contents      = $assignmentitem['data1'];
+            $doc->url           = assignment_make_link($assignment_module_id, $itemtype, $owner_id, $submissionoffset);
+        }
 
         // module specific information; optional
         $data->assignment         = $assignment_module_id;
@@ -64,12 +69,16 @@
 * @uses CFG
 * @return a well formed link to session display
 */
-function assignment_make_link($cm_id, $itemtype, $owner) {
+function assignment_make_link($cm_id, $itemtype, $owner, $submissionoffset=null) {
     global $CFG;
 
-    if ($itemtype == 'description')
+    if ($itemtype == 'intro') {
         return $CFG->wwwroot.'/mod/assignment/view.php?id='.$cm_id;
+    } else {
+        return $CFG->wwwroot.'/mod/assignment/submissions.php?id='.$cm_id.'&userid='.$owner.'&mode=single&offset='.$submissionoffset;
+        //?id=80&userid=4&mode=single&filter=0&offset=1
 }
+}
 
 /**
 * part of search engine API
@@ -102,11 +111,13 @@
 
         $assignment->authors = '';
         $assignment->date = $assignment->timemodified;
-        $documents[] = new AssignmentSearchDocument(get_object_vars($assignment), $cm->id, 'description', $assignment->course, null, $context->id);
+        $documents[] = new AssignmentSearchDocument(get_object_vars($assignment), $cm->id, 'intro', $assignment->course, null, $context->id);
 
         $submissions = assignment_get_all_submissions($assignment);
         if ($submissions){
+            $submissionoffset=-1;
             foreach($submissions as $submission){
+                $submissionoffset++;
                 $owner = $DB->get_record('user', array('id' => $submission->userid));
                 $submission->authors = fullname($owner);
                 $submission->assignmenttype = $assignment->assignmenttype;
@@ -140,7 +151,7 @@
                 if ($submitted->source = 'text'){
                     $submission->description = $submitted->data;
                     $submission->description = preg_replace("/<[^>]*>/", '', $submission->description); // stip all tags
-                    $documents[] = new AssignmentSearchDocument(get_object_vars($submission), $cm->id, 'submission', $assignment->course, $submission->userid, $context->id);
+                    $documents[] = new AssignmentSearchDocument(get_object_vars($submission), $cm->id, 'submission', $assignment->course, $submission->userid, $context->id, $submissionoffset);
                     mtrace("finished online submission for {$submission->authors} in assignment {$assignment->name}");
                 } elseif ($submitted->source = 'files'){
                     $SUBMITTED = opendir($submitted->path);
Index: moodle/search/documents/chat_document.php
--- moodle/search/documents/chat_document.php Base (1.14)
+++ moodle/search/documents/chat_document.php Locally Modified (Based On 1.14)
@@ -100,7 +100,7 @@
     $fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : '';
     $totimeclause = ($totime) ? "AND timestamp <= {$totime}" : '';
     $tracks = array();
-    $messages = $DB->get_records_select('chat_messages', "chatid = ':chatid' :from :to", array('chatid' => $chat_id, 'from' => $fromtimeclause, 'to' => $totimeclause), 'timestamp DESC');
+    $messages = $DB->get_records_select('chat_messages', "chatid = :chatid :from :to", array('chatid' => $chat_id, 'from' => $fromtimeclause, 'to' => $totimeclause), 'timestamp DESC');
     if ($messages){
         // splits discussions against groups
         $groupedMessages = array();
Index: moodle/search/documents/data_document.php
--- moodle/search/documents/data_document.php Base (1.14)
+++ moodle/search/documents/data_document.php Locally Modified (Based On 1.14)
@@ -161,16 +161,15 @@
           c.id,
           r.groupid,
           c.userid,
-          c.recordid,
+          c.itemid,
           c.content,
-          c.created,
-          c.modified,
+          c.timecreated,
           r.dataid
        FROM
-          {data_comments} as c,
           {data_records} as r 
+       JOIN
+          {comments} as c ON c.contextid = r.id
        WHERE
-          c.recordid = r.id AND
           r.dataid = ?
     ";
     $comments = $DB->get_records_sql($query, array($database_id));
@@ -232,7 +231,7 @@
     $records_comments = data_get_comments($database->id);
     if ($records_comments){
         foreach($records_comments as $aComment){
-            $aComment->title = $recordsTitle[$aComment->recordid];
\ No newline at end of file
+            $aComment->title = $recordsTitle[$aComment->itemid];
\ No newline at end of file
             $authoruser = $DB->get_record('user', array('id' => $aComment->userid));
             $aComment->author = fullname($authoruser);
             $documents[] = new DataCommentSearchDocument(get_object_vars($aComment), $database->course, $context->id);
Index: moodle/search/documents/glossary_document.php
--- moodle/search/documents/glossary_document.php Base (1.17)
+++ moodle/search/documents/glossary_document.php Locally Modified (Based On 1.17)
@@ -74,19 +74,19 @@
         global $DB;
         
         // generic information; required
-        $doc->docid     = $entry['id'];
+        $doc->docid     = $entry['itemid'];
         $doc->documenttype  = SEARCH_TYPE_GLOSSARY;
         $doc->itemtype      = 'comment';
         $doc->contextid     = $context_id;
 
         $doc->title     = get_string('commenton', 'search') . ' ' . $entry['concept'];
-        $doc->date      = $entry['timemodified'];
+        $doc->date      = $entry['timecreated'];
 
         if ($entry['userid'])
             $user = $DB->get_record('user', array('id' => $entry['userid']));
         $doc->author    = ($user ) ? $user->firstname.' '.$user->lastname : '' ;
-        $doc->contents  = strip_tags($entry['entrycomment']);
-        $doc->url       = glossary_make_link($entry['entryid']);
+        $doc->contents  = strip_tags($entry['content']);
+        $doc->url       = glossary_make_link($entry['itemid']);
         
         // module specific information; optional
         $data->glossary = $glossary_id;
@@ -104,6 +104,7 @@
 */
 function glossary_make_link($entry_id) {
     global $CFG;
+    require_once($CFG->dirroot.'/search/querylib.php');
 
     //links directly to entry
     // return $CFG->wwwroot.'/mod/glossary/showentry.php?eid='.$entry_id;
@@ -158,7 +159,14 @@
     
     // index comments
     if (count($entryIds)){
-        $comments = $DB->get_records_list('glossary_comments', 'entryid', $entryIds);
\ No newline at end of file
+        list($entryidssql, $params) = $DB->get_in_or_equal($entryIds, SQL_PARAMS_NAMED);
+        $params['ctxid'] = $context->id;
+        $sql = "SELECT *
+                  FROM {comments}
+                 WHERE contextid = :ctxid 
+                    AND itemid $entryidssql";
+        $comments = $DB->get_recordset_sql($sql, $params);
+
\ No newline at end of file
         if ($comments){
             foreach($comments as $comment) {
                 if (strlen($comment->entrycomment) > 0) {
Index: moodle/search/indexer.php
--- moodle/search/indexer.php Base (1.30)
+++ moodle/search/indexer.php Locally Modified (Based On 1.30)
@@ -158,6 +158,10 @@
                                 foreach($documents as $document) {
                                     $counter++;
                                     
+                                    // temporary fix until MDL-24822 is resolved
+                                    if ($document->group_id == -1 and $mod->name ='forum') {
+                                        $document->group_id = 0;
+                                    }
\ No newline at end of file
                                     //object to insert into db
                                     $dbid = $dbcontrol->addDocument($document);
                                     
