Permalink
Browse files

sync with HEAD/1.8 compatible

  • Loading branch information...
diml
diml committed Apr 7, 2008
1 parent ab42d25 commit ee95c70444a74fb1a9ad20a6528573fac39f6f35
@@ -1,28 +1,36 @@
<?php
/**
* Global Search Engine for Moodle
-* add-on 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr]
-* 2007/08/02
+*
+* @package search
+* @category core
+* @subpackage document_wrappers
+* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @date 2008/03/31
+* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
* document handling for chat activity module
* This file contains the mapping between a chat history and it's indexable counterpart,
*
* Functions for iterating and retrieving the necessary records are now also included
* in this file, rather than mod/chat/lib.php
-**/
+*
+*/
+/**
+* includes and requires
+*/
require_once("$CFG->dirroot/search/documents/document.php");
require_once("$CFG->dirroot/mod/chat/lib.php");
-/*
+/**
* a class for representing searchable information
*
-**/
+*/
class ChatTrackSearchDocument extends SearchDocument {
/**
* constructor
- *
*/
public function __construct(&$chatsession, $chat_module_id, $course_id, $group_id, $context_id) {
// generic information; required
@@ -46,28 +54,32 @@ public function __construct(&$chatsession, $chat_module_id, $course_id, $group_i
// construct the parent class
parent::__construct($doc, $data, $course_id, $group_id, 0, PATH_FOR_SEARCH_TYPE_CHAT);
- } //constructor
-} //ChatTrackSearchDocument
+ }
+}
/**
* constructs a valid link to a chat content
* @param cm_id the chat course module
* @param start the start time of the session
* @param end th end time of the session
+* @uses CFG
* @return a well formed link to session display
*/
function chat_make_link($cm_id, $start, $end) {
global $CFG;
return $CFG->wwwroot.'/mod/chat/report.php?id='.$cm_id.'&amp;start='.$start.'&amp;end='.$end;
-} //chat_make_link
+}
/**
* fetches all the records for a given session and assemble them as a unique track
* we revamped here the code of report.php for making sessions, but without any output.
* note that we should collect sessions "by groups" if groupmode() is SEPARATEGROUPS.
-* @param chat_id the database
+* @param int $chat_id the database
+* @param int $fromtime
+* @param int $totime
+* @uses CFG
* @return an array of objects representing the chat sessions.
*/
function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
@@ -90,8 +102,7 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
foreach($messages as $aMessage){
$groupedMessages[$aMessage->groupid][] = $aMessage;
}
- }
- else{
+ } else {
$groupedMessages[-1] = &$messages;
}
$sessiongap = 5 * 60; // 5 minutes silence means a new session
@@ -118,9 +129,8 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
$tracks[count($tracks) - 1]->content .= ' '.$message->message;
$tracks[count($tracks) - 1]->sessionstart = $message->timestamp;
}
- }
+ } else {
// we initiate a new session track (backwards)
- else {
$track = new Object();
$track->sessionend = $message->timestamp;
$track->sessionstart = $message->timestamp;
@@ -136,7 +146,7 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
}
}
return $tracks;
-} //chat_get_session_tracks
+}
/**
* part of search engine API
@@ -145,7 +155,7 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
function chat_iterator() {
$chatrooms = get_records('chat');
return $chatrooms;
-} //chat_iterator
+}
/**
* part of search engine API
@@ -155,22 +165,25 @@ function chat_get_content_for_index(&$chat) {
$documents = array();
$course = get_record('course', 'id', $chat->course);
$coursemodule = get_field('modules', 'id', 'name', 'chat');
- $cm = get_record('course_modules', 'course', $course->id, 'module', $coursemodule, 'instance', $chat->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- // getting records for indexing
- $sessionTracks = chat_get_session_tracks($chat->id);
- if ($sessionTracks){
- foreach($sessionTracks as $aTrackId => $aTrack) {
- foreach($aTrack->sessionusers as $aUserId){
- $user = get_record('user', 'id', $aUserId);
- $aTrack->authors = ($user) ? $user->firstname.' '.$user->lastname : '' ;
- $documents[] = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
+ $cm = get_record('course_modules', 'course', $chat->course, 'module', $coursemodule, 'instance', $chat->id);
+ if ($cm){
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ // getting records for indexing
+ $sessionTracks = chat_get_session_tracks($chat->id);
+ if ($sessionTracks){
+ foreach($sessionTracks as $aTrackId => $aTrack) {
+ 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);
+ }
}
}
+ return $documents;
}
- return $documents;
-} //chat_get_content_for_index
+ return array();
+}
/**
* returns a single data search document based on a chat_session id
@@ -187,15 +200,19 @@ function chat_single_document($id, $itemtype) {
$course = get_record('course', 'id', $chat->course);
$coursemodule = get_field('modules', 'id', 'name', 'chat');
$cm = get_record('course_modules', 'course', $course->id, 'module', $coursemodule, 'instance', $chat->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- // should be only one
- $tracks = chat_get_session_tracks($chat->id, $sessionstart, $sessionstart);
- if ($tracks){
- $aTrack = $tracks[0];
- $documents[] = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
+ if ($cm){
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ // should be only one
+ $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);
+ return $document;
+ }
}
-} //chat_single_document
+ return null;
+}
/**
* dummy delete function that packs id with itemtype.
@@ -206,7 +223,7 @@ function chat_delete($info, $itemtype) {
$object->id = $info;
$object->itemtype = $itemtype;
return $object;
-} //chat_delete
+}
/**
* returns the var names needed to build a sql query for addition/deletions
@@ -215,7 +232,7 @@ function chat_delete($info, $itemtype) {
function chat_db_names() {
//[primary id], [table name], [time created field name], [time modified field name]
return null;
-} //chat_db_names
+}
/**
* this function handles the access policy to contents indexed as searchable documents. If this
@@ -230,6 +247,7 @@ function chat_db_names() {
* points out a session history which is a close sequence of messages.
* @param user the user record denoting the user who searches
* @param group_id the current group used by the user when searching
+* @uses CFG
* @return true if access is allowed, false elsewhere
*/
function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
@@ -241,23 +259,35 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
// get the chat session and all related stuff
$chat = get_record('chat', 'id', $chat_id);
- $course = get_record('course', 'id', $chat->course);
- $module_context = get_record('context', 'id', $context_id);
- $cm = get_record('course_modules', 'id', $module_context->instanceid);
- if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)) return false;
+ $context = get_record('context', 'id', $context_id);
+ $cm = get_record('course_modules', 'id', $context->instanceid);
+ // $cm = get_coursemodule_from_instance('chat', $chat->id, $chat->course);
+ // $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
+ if (!empty($CFG->search_access_debug)) echo "search reject : hidden chat ";
+ return false;
+ }
//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);
- if ((groupmode($course) == SEPARATEGROUPS) && !groups_is_member($group_id) && !has_capability('moodle/site:accessallgroups', $module_context)) return false;
+ $course = get_record('course', 'id', $chat->course);
+ 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;
+ }
//ownership check : checks the following situations about user
// trap if user is not owner and has cannot see other's entries
// TODO : typically may be stored into indexing cache
- if (!has_capability('mod/chat:readlog', $module_context)) return false;
+ if (!has_capability('mod/chat:readlog', $context)){
+ if (!empty($CFG->search_access_debug)) echo "search reject : cannot read past sessions ";
+ return false;
+ }
return true;
-} //chat_check_text_access
+}
/**
* this call back is called when displaying the link for some last post processing
@@ -267,5 +297,5 @@ function chat_link_post_processing($title){
setLocale(LC_TIME, substr(current_language(), 0, 2));
$title = preg_replace('/TT_(.*)_TT/e', "userdate(\\1)", $title);
return $title;
-} //chat_link_post_processing
+}
?>
Oops, something went wrong.

0 comments on commit ee95c70

Please sign in to comment.