mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Addresses MDL-18638 (Search code does not follow coding guidelines) and MDL-18474 (global search should use of PATH_SEPARATOR)
This commit is contained in:
parent
cbc5cd4140
commit
8fe956133f
20 changed files with 790 additions and 350 deletions
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
*
|
*
|
||||||
* document handling for assignment activity module
|
* document handling for assignment activity module
|
||||||
*
|
*
|
||||||
|
@ -16,8 +17,8 @@
|
||||||
/**
|
/**
|
||||||
* includes and requires
|
* includes and requires
|
||||||
*/
|
*/
|
||||||
require_once("$CFG->dirroot/search/documents/document.php");
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
require_once("$CFG->dirroot/mod/assignment/lib.php");
|
require_once($CFG->dirroot.'/mod/assignment/lib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a class for representing searchable information
|
* a class for representing searchable information
|
||||||
|
@ -71,24 +72,30 @@ function assignment_make_link($cm_id, $itemtype, $owner) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
|
* @uses $DB
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function assignment_iterator() {
|
function assignment_iterator() {
|
||||||
$assignments = get_records('assignment');
|
global $DB;
|
||||||
return $assignments;
|
|
||||||
|
if ($assignments = $DB->get_records('assignment'))
|
||||||
|
return $assignments;
|
||||||
|
else
|
||||||
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
|
* @uses $CFG, $DB
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function assignment_get_content_for_index(&$assignment) {
|
function assignment_get_content_for_index(&$assignment) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$documents = array();
|
$documents = array();
|
||||||
$course = get_record('course', 'id', $assignment->course);
|
$course = $DB->get_record('course', array('id' => $assignment->course));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'assignment');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'assignment'));
|
||||||
$cm = get_record('course_modules', 'course', $assignment->course, 'module', $coursemodule, 'instance', $assignment->id);
|
$cm = $DB->get_record('course_modules', array('course' => $assignment->course, 'module' => $coursemodule, 'instance' => $assignment->id));
|
||||||
if ($cm){
|
if ($cm){
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
|
||||||
|
@ -99,7 +106,7 @@ function assignment_get_content_for_index(&$assignment) {
|
||||||
$submissions = assignment_get_all_submissions($assignment);
|
$submissions = assignment_get_all_submissions($assignment);
|
||||||
if ($submissions){
|
if ($submissions){
|
||||||
foreach($submissions as $submission){
|
foreach($submissions as $submission){
|
||||||
$owner = get_record('user', 'id', $submission->userid);
|
$owner = $DB->get_record('user', array('id' => $submission->userid));
|
||||||
$submission->authors = fullname($owner);
|
$submission->authors = fullname($owner);
|
||||||
$submission->assignmenttype = $assignment->assignmenttype;
|
$submission->assignmenttype = $assignment->assignmenttype;
|
||||||
$submission->date = $submission->timemodified;
|
$submission->date = $submission->timemodified;
|
||||||
|
@ -154,16 +161,17 @@ function assignment_get_content_for_index(&$assignment) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get text from a physical file in an assignment submission
|
* get text from a physical file in an assignment submission
|
||||||
|
* @uses $CFG, $DB
|
||||||
* @param object $submission a submission for which to fetch some representative text
|
* @param object $submission a submission for which to fetch some representative text
|
||||||
* @param object $assignment the relevant assignment as a context
|
* @param object $assignment the relevant assignment as a context
|
||||||
* @param object $cm the corresponding coursemodule
|
* @param object $cm the corresponding coursemodule
|
||||||
* @param string $path a file from which to fetch some representative text
|
* @param string $path a file from which to fetch some representative text
|
||||||
* @param int $contextid the moodle context if needed
|
* @param int $contextid the moodle context if needed
|
||||||
* @param documents the array of documents, by ref, where to add the new document.
|
* @param array $documents the array of documents, by ref, where to add the new document.
|
||||||
* @return a search document when unique or false.
|
* @return a search document when unique or false.
|
||||||
*/
|
*/
|
||||||
function assignment_get_physical_file(&$submission, &$assignment, &$cm, $path, $context_id, &$documents = null){
|
function assignment_get_physical_file(&$submission, &$assignment, &$cm, $path, $context_id, &$documents = null){
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$fileparts = pathinfo($path);
|
$fileparts = pathinfo($path);
|
||||||
// cannot index unknown or masked types
|
// cannot index unknown or masked types
|
||||||
|
@ -185,7 +193,7 @@ function assignment_get_physical_file(&$submission, &$assignment, &$cm, $path, $
|
||||||
$submission->description = $function_name(null, $path);
|
$submission->description = $function_name(null, $path);
|
||||||
|
|
||||||
// get authors
|
// get authors
|
||||||
$user = get_record('user', 'id', $submission->userid);
|
$user = $DB->get_record('user', array('id' => $submission->userid));
|
||||||
$submission->authors = fullname($user);
|
$submission->authors = fullname($user);
|
||||||
|
|
||||||
// we need a real id on file
|
// we need a real id on file
|
||||||
|
@ -209,24 +217,27 @@ function assignment_get_physical_file(&$submission, &$assignment, &$cm, $path, $
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a single data search document based on an assignment
|
* returns a single data search document based on an assignment
|
||||||
|
* @uses $DB
|
||||||
* @param string $id the id of the searchable item
|
* @param string $id the id of the searchable item
|
||||||
* @param string $itemtype the type of information
|
* @param string $itemtype the type of information
|
||||||
*/
|
*/
|
||||||
function assignment_single_document($id, $itemtype) {
|
function assignment_single_document($id, $itemtype) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
if ($itemtype == 'requirement'){
|
if ($itemtype == 'requirement'){
|
||||||
if (!$assignment = get_record('assignment', 'id', $id)){
|
if (!$assignment = $DB->get_record('assignment', 'id', $id)){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} elseif ($itemtype == 'submission') {
|
} elseif ($itemtype == 'submission') {
|
||||||
if ($submission = get_record('assignment_submissions', 'id', $id)){
|
if ($submission = $DB->get_record('assignment_submissions', array('id' => $id))){
|
||||||
$assignment = get_record('assignment', 'id', $submission->assignment);
|
$assignment = $DB->get_record('assignment', array('id' => $submission->assignment));
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$course = get_record('course', 'id', $assignment->course);
|
$course = $DB->get_record('course', array('id' => $assignment->course));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'assignment');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'assignment'));
|
||||||
$cm = get_record('course_modules', 'course', $course->id, 'module', $coursemodule, 'instance', $assignment->id);
|
$cm = $DB->get_record('course_modules', array('course' => $course->id, 'module' => $coursemodule, 'instance' => $assignment->id));
|
||||||
if ($cm){
|
if ($cm){
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
|
||||||
|
@ -273,29 +284,29 @@ function assignment_db_names() {
|
||||||
* - user is legitimate in the surrounding context
|
* - user is legitimate in the surrounding context
|
||||||
* - user may be guest and guest access is allowed to the module
|
* - user may be guest and guest access is allowed to the module
|
||||||
* - the function may perform local checks within the module information logic
|
* - the function may perform local checks within the module information logic
|
||||||
* @param path the access path to the module script code
|
* @uses $CFG, $USER, $DB
|
||||||
* @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
* @param string $path the access path to the module script code
|
||||||
* @param this_id the item id within the information class denoted by entry_type. In chats, this id
|
* @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
||||||
|
* @param int $this_id the item id within the information class denoted by entry_type. In chats, this id
|
||||||
* points out a session history which is a close sequence of messages.
|
* points out a session history which is a close sequence of messages.
|
||||||
* @param user the user record denoting the user who searches
|
* @param int $user the user record denoting the user who searches
|
||||||
* @param group_id the current group used by the user when searching
|
* @param int $group_id the current group used by the user when searching
|
||||||
* @uses CFG
|
|
||||||
* @return true if access is allowed, false elsewhere
|
* @return true if access is allowed, false elsewhere
|
||||||
*/
|
*/
|
||||||
function assignment_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
function assignment_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
global $CFG, $USER;
|
global $CFG, $USER, $DB;
|
||||||
|
|
||||||
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
||||||
|
|
||||||
// get the chat session and all related stuff
|
// get the chat session and all related stuff
|
||||||
if ($itemtype == 'description'){
|
if ($itemtype == 'description'){
|
||||||
$assignment = get_record('assignment', 'id', $this_id);
|
$assignment = $DB->get_record('assignment', array('id' => $this_id));
|
||||||
} elseif ($itemtype == 'submitted'){
|
} elseif ($itemtype == 'submitted'){
|
||||||
$submission = get_record('assignment_submissions', 'id', $this_id);
|
$submission = $DB->get_record('assignment_submissions', array('id' => $this_id));
|
||||||
$assignment = get_record('assignment', 'id', $submission->assignment);
|
$assignment = $DB->get_record('assignment', array('id' => $submission->assignment));
|
||||||
}
|
}
|
||||||
$context = get_record('context', 'id', $context_id);
|
$context = $DB->get_record('context', array('id' => $context_id));
|
||||||
$cm = get_record('course_modules', 'id', $context->instanceid);
|
$cm = $DB->get_record('course_modules', array('id' => $context->instanceid));
|
||||||
|
|
||||||
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
|
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
|
||||||
if (!empty($CFG->search_access_debug)) echo "search reject : hidden assignment ";
|
if (!empty($CFG->search_access_debug)) echo "search reject : hidden assignment ";
|
||||||
|
@ -342,6 +353,7 @@ function assignment_check_text_access($path, $itemtype, $this_id, $user, $group_
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function assignment_link_post_processing($title){
|
function assignment_link_post_processing($title){
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
if (!function_exists('search_assignment_getstring')){
|
if (!function_exists('search_assignment_getstring')){
|
||||||
function search_assignment_getstring($matches){
|
function search_assignment_getstring($matches){
|
||||||
|
@ -349,7 +361,11 @@ function assignment_link_post_processing($title){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = preg_replace_callback('/^(description|submitted)/', 'search_assignment_getstring', $title);
|
$title = preg_replace_callback('/^(description|submitted)/', 'search_assignment_getstring', $title);
|
||||||
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
|
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
*
|
*
|
||||||
* document handling for chat activity module
|
* document handling for chat activity module
|
||||||
* This file contains the mapping between a chat history and it's indexable counterpart,
|
* This file contains the mapping between a chat history and it's indexable counterpart,
|
||||||
|
@ -20,8 +21,8 @@
|
||||||
/**
|
/**
|
||||||
* includes and requires
|
* includes and requires
|
||||||
*/
|
*/
|
||||||
require_once("$CFG->dirroot/search/documents/document.php");
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
require_once("$CFG->dirroot/mod/chat/lib.php");
|
require_once($CFG->dirroot.'/mod/chat/lib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a class for representing searchable information
|
* a class for representing searchable information
|
||||||
|
@ -61,9 +62,9 @@ class ChatTrackSearchDocument extends SearchDocument {
|
||||||
/**
|
/**
|
||||||
* constructs a valid link to a chat content
|
* constructs a valid link to a chat content
|
||||||
* @param cm_id the chat course module
|
* @param cm_id the chat course module
|
||||||
* @param start the start time of the session
|
* @param int $start the start time of the session
|
||||||
* @param end th end time of the session
|
* @param int $end th end time of the session
|
||||||
* @uses CFG
|
* @uses $CFG
|
||||||
* @return a well formed link to session display
|
* @return a well formed link to session display
|
||||||
*/
|
*/
|
||||||
function chat_make_link($cm_id, $start, $end) {
|
function chat_make_link($cm_id, $start, $end) {
|
||||||
|
@ -79,22 +80,22 @@ function chat_make_link($cm_id, $start, $end) {
|
||||||
* @param int $chat_id the database
|
* @param int $chat_id the database
|
||||||
* @param int $fromtime
|
* @param int $fromtime
|
||||||
* @param int $totime
|
* @param int $totime
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
* @return an array of objects representing the chat sessions.
|
* @return an array of objects representing the chat sessions.
|
||||||
*/
|
*/
|
||||||
function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
|
function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$chat = get_record('chat', 'id', $chat_id);
|
$chat = $DB->get_record('chat', array('id' => $chat_id));
|
||||||
$course = get_record('course', 'id', $chat->course);
|
$course = $DB->get_record('course', array('id' => $chat->course));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'data');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'data'));
|
||||||
$cm = get_record('course_modules', 'course', $course->id, 'module', $coursemodule, 'instance', $chat->id);
|
$cm = $DB->get_record('course_modules', array('course' => $course->id, 'module' => $coursemodule, 'instance' => $chat->id));
|
||||||
$groupmode = groupmode($course, $cm);
|
$groupmode = groupmode($course, $cm);
|
||||||
|
|
||||||
$fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : '';
|
$fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : '';
|
||||||
$totimeclause = ($totime) ? "AND timestamp <= {$totime}" : '';
|
$totimeclause = ($totime) ? "AND timestamp <= {$totime}" : '';
|
||||||
$tracks = array();
|
$tracks = array();
|
||||||
$messages = get_records_select('chat_messages', "chatid = '{$chat_id}' $fromtimeclause $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){
|
if ($messages){
|
||||||
// splits discussions against groups
|
// splits discussions against groups
|
||||||
$groupedMessages = array();
|
$groupedMessages = array();
|
||||||
|
@ -150,22 +151,29 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
|
* @uses $DB
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function chat_iterator() {
|
function chat_iterator() {
|
||||||
$chatrooms = get_records('chat');
|
global $DB;
|
||||||
|
|
||||||
|
$chatrooms = $DB->get_records('chat');
|
||||||
return $chatrooms;
|
return $chatrooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
|
* @uses $DB
|
||||||
|
* @param reference $chat
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function chat_get_content_for_index(&$chat) {
|
function chat_get_content_for_index(&$chat) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
$documents = array();
|
$documents = array();
|
||||||
$course = get_record('course', 'id', $chat->course);
|
$course = $DB->get_record('course', array('id' => $chat->course));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'chat');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'chat'));
|
||||||
$cm = get_record('course_modules', 'course', $chat->course, 'module', $coursemodule, 'instance', $chat->id);
|
$cm = $DB->get_record('course_modules', array('course' => $chat->course, 'module' => $coursemodule, 'instance' => $chat->id));
|
||||||
if ($cm){
|
if ($cm){
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
|
||||||
|
@ -174,7 +182,7 @@ function chat_get_content_for_index(&$chat) {
|
||||||
if ($sessionTracks){
|
if ($sessionTracks){
|
||||||
foreach($sessionTracks as $aTrackId => $aTrack) {
|
foreach($sessionTracks as $aTrackId => $aTrack) {
|
||||||
foreach($aTrack->sessionusers as $aUserId){
|
foreach($aTrack->sessionusers as $aUserId){
|
||||||
$user = get_record('user', 'id', $aUserId);
|
$user = $DB->get_record('user', array('id' => $aUserId));
|
||||||
$aTrack->authors = ($user) ? fullname($user) : '' ;
|
$aTrack->authors = ($user) ? fullname($user) : '' ;
|
||||||
$documents[] = new ChatTrackSearchDocument(get_object_vars($aTrack), $chat->id, $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);
|
||||||
}
|
}
|
||||||
|
@ -191,15 +199,18 @@ function chat_get_content_for_index(&$chat) {
|
||||||
* - the chat id
|
* - the chat id
|
||||||
* - the timestamp when the session starts
|
* - the timestamp when the session starts
|
||||||
* - the timestamp when the session ends
|
* - the timestamp when the session ends
|
||||||
|
* @uses $DB
|
||||||
* @param id the multipart chat session id
|
* @param id the multipart chat session id
|
||||||
* @param itemtype the type of information (session is the only type)
|
* @param itemtype the type of information (session is the only type)
|
||||||
*/
|
*/
|
||||||
function chat_single_document($id, $itemtype) {
|
function chat_single_document($id, $itemtype) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
list($chat_id, $sessionstart, $sessionend) = split('-', $id);
|
list($chat_id, $sessionstart, $sessionend) = split('-', $id);
|
||||||
$chat = get_record('chat', 'id', $chat_id);
|
$chat = $DB->get_record('chat', array('id' => $chat_id));
|
||||||
$course = get_record('course', 'id', $chat->course);
|
$course = $DB->get_record('course', array('id' => $chat->course));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'chat');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'chat'));
|
||||||
$cm = get_record('course_modules', 'course', $course->id, 'module', $coursemodule, 'instance', $chat->id);
|
$cm = $DB->get_record('course_modules', array('course' => $course->id, 'module' => $coursemodule, 'instance' => $chat->id));
|
||||||
if ($cm){
|
if ($cm){
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
|
||||||
|
@ -241,27 +252,25 @@ function chat_db_names() {
|
||||||
* - user is legitimate in the surrounding context
|
* - user is legitimate in the surrounding context
|
||||||
* - user may be guest and guest access is allowed to the module
|
* - user may be guest and guest access is allowed to the module
|
||||||
* - the function may perform local checks within the module information logic
|
* - the function may perform local checks within the module information logic
|
||||||
* @param path the access path to the module script code
|
* @param string $path the access path to the module script code
|
||||||
* @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
* @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
||||||
* @param this_id the item id within the information class denoted by entry_type. In chats, this id
|
* @param int $this_id the item id within the information class denoted by entry_type. In chats, this id
|
||||||
* points out a session history which is a close sequence of messages.
|
* points out a session history which is a close sequence of messages.
|
||||||
* @param user the user record denoting the user who searches
|
* @param int $user the user record denoting the user who searches
|
||||||
* @param group_id the current group used by the user when searching
|
* @param int $group_id the current group used by the user when searching
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
* @return true if access is allowed, false elsewhere
|
* @return true if access is allowed, false elsewhere
|
||||||
*/
|
*/
|
||||||
function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
||||||
|
|
||||||
list($chat_id, $sessionstart, $sessionend) = split('-', $this_id);
|
list($chat_id, $sessionstart, $sessionend) = split('-', $this_id);
|
||||||
// get the chat session and all related stuff
|
// get the chat session and all related stuff
|
||||||
$chat = get_record('chat', 'id', $chat_id);
|
$chat = $DB->get_record('chat', array('id' => $chat_id));
|
||||||
$context = get_record('context', 'id', $context_id);
|
$context = $DB->get_record('context', array('id' => $context_id));
|
||||||
$cm = get_record('course_modules', 'id', $context->instanceid);
|
$cm = $DB->get_record('course_modules', array('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 (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
|
||||||
if (!empty($CFG->search_access_debug)) echo "search reject : hidden chat ";
|
if (!empty($CFG->search_access_debug)) echo "search reject : hidden chat ";
|
||||||
|
@ -270,7 +279,7 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
|
||||||
|
|
||||||
//group consistency check : checks the following situations about groups
|
//group consistency check : checks the following situations about groups
|
||||||
// trap if user is not same group and groups are separated
|
// trap if user is not same group and groups are separated
|
||||||
$course = get_record('course', 'id', $chat->course);
|
$course = $DB->get_record('course', array('id' => $chat->course));
|
||||||
if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($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 ";
|
if (!empty($CFG->search_access_debug)) echo "search reject : chat element is in separated group ";
|
||||||
return false;
|
return false;
|
||||||
|
@ -289,11 +298,18 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this call back is called when displaying the link for some last post processing
|
* this call back is called when displaying the link for some last post processing
|
||||||
|
* @uses $CFG
|
||||||
|
* @param string $title
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function chat_link_post_processing($title){
|
function chat_link_post_processing($title){
|
||||||
setLocale(LC_TIME, substr(current_language(), 0, 2));
|
global $CFG;
|
||||||
$title = preg_replace('/TT_(.*)_TT/e', "userdate(\\1)", $title);
|
setLocale(LC_TIME, substr(current_language(), 0, 2));
|
||||||
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
$title = preg_replace('/TT_(.*)_TT/e', "userdate(\\1)", $title);
|
||||||
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
|
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
*
|
*
|
||||||
* document handling for data activity module
|
* document handling for data activity module
|
||||||
* This file contains the mapping between a database object and it's indexable counterpart,
|
* This file contains the mapping between a database object and it's indexable counterpart,
|
||||||
|
@ -20,8 +21,8 @@
|
||||||
/**
|
/**
|
||||||
* includes and requires
|
* includes and requires
|
||||||
*/
|
*/
|
||||||
require_once("$CFG->dirroot/search/documents/document.php");
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
require_once("$CFG->dirroot/mod/data/lib.php");
|
require_once($CFG->dirroot.'/mod/data/lib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a class for representing searchable information (data records)
|
* a class for representing searchable information (data records)
|
||||||
|
@ -33,6 +34,8 @@ class DataSearchDocument extends SearchDocument {
|
||||||
* constructor
|
* constructor
|
||||||
*/
|
*/
|
||||||
public function __construct(&$record, $course_id, $context_id) {
|
public function __construct(&$record, $course_id, $context_id) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
// generic information; required
|
// generic information; required
|
||||||
$doc->docid = $record['id'];
|
$doc->docid = $record['id'];
|
||||||
$doc->documenttype = SEARCH_TYPE_DATA;
|
$doc->documenttype = SEARCH_TYPE_DATA;
|
||||||
|
@ -43,7 +46,7 @@ class DataSearchDocument extends SearchDocument {
|
||||||
$doc->date = $record['timemodified'];
|
$doc->date = $record['timemodified'];
|
||||||
//remove '(ip.ip.ip.ip)' from data record author field
|
//remove '(ip.ip.ip.ip)' from data record author field
|
||||||
if ($record['userid']){
|
if ($record['userid']){
|
||||||
$user = get_record('user', 'id', $record['userid']);
|
$user = $DB->get_record('user', array('id' => $record['userid']));
|
||||||
}
|
}
|
||||||
$doc->author = (isset($user)) ? $user->firstname.' '.$user->lastname : '' ;
|
$doc->author = (isset($user)) ? $user->firstname.' '.$user->lastname : '' ;
|
||||||
$doc->contents = $record['content'];
|
$doc->contents = $record['content'];
|
||||||
|
@ -91,9 +94,9 @@ class DataCommentSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructs a valid link to a data record content
|
* constructs a valid link to a data record content
|
||||||
* @param database_id the database reference
|
* @param int $database_id the database reference
|
||||||
* @param record_id the record reference
|
* @param int $record_id the record reference
|
||||||
* @uses CFG
|
* @uses $CFG
|
||||||
* @return a valid url top access the information as a string
|
* @return a valid url top access the information as a string
|
||||||
*/
|
*/
|
||||||
function data_make_link($database_id, $record_id) {
|
function data_make_link($database_id, $record_id) {
|
||||||
|
@ -104,28 +107,28 @@ function data_make_link($database_id, $record_id) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches all the records for a given database
|
* fetches all the records for a given database
|
||||||
* @param database_id the database
|
* @param int $database_id the database
|
||||||
* @param typematch a comma separated list of types that should be considered for searching or *
|
* @param string $typematch a comma separated list of types that should be considered for searching or *
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
* @return an array of objects representing the data records.
|
* @return an array of objects representing the data records.
|
||||||
*/
|
*/
|
||||||
function data_get_records($database_id, $typematch = '*') {
|
function data_get_records($database_id, $typematch = '*') {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$fieldset = get_records('data_fields', 'dataid', $database_id);
|
$fieldset = $DB->get_records('data_fields', array('dataid' => $database_id));
|
||||||
$query = "
|
$query = "
|
||||||
SELECT
|
SELECT
|
||||||
c.*
|
c.*
|
||||||
FROM
|
FROM
|
||||||
{data_content} as c,
|
{data_content} c,
|
||||||
{data_records} as r
|
{data_records} r
|
||||||
WHERE
|
WHERE
|
||||||
c.recordid = r.id AND
|
c.recordid = r.id AND
|
||||||
r.dataid = {$database_id}
|
r.dataid = ?
|
||||||
ORDER BY
|
ORDER BY
|
||||||
c.fieldid
|
c.fieldid
|
||||||
";
|
";
|
||||||
$data = get_records_sql($query);
|
$data = $DB->get_records_sql($query, array($database_id));
|
||||||
$records = array();
|
$records = array();
|
||||||
if ($data){
|
if ($data){
|
||||||
foreach($data as $aDatum){
|
foreach($data as $aDatum){
|
||||||
|
@ -143,12 +146,12 @@ function data_get_records($database_id, $typematch = '*') {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches all the comments for a given database
|
* fetches all the comments for a given database
|
||||||
* @param database_id the database
|
* @param int $database_id the database
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
* @return an array of objects representing the data record comments.
|
* @return an array of objects representing the data record comments.
|
||||||
*/
|
*/
|
||||||
function data_get_comments($database_id) {
|
function data_get_comments($database_id) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$query = "
|
$query = "
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -161,56 +164,63 @@ function data_get_comments($database_id) {
|
||||||
c.modified,
|
c.modified,
|
||||||
r.dataid
|
r.dataid
|
||||||
FROM
|
FROM
|
||||||
{data_comments} as c,
|
{data_comments} c,
|
||||||
{data_records} as r
|
{data_records} r
|
||||||
WHERE
|
WHERE
|
||||||
c.recordid = r.id
|
c.recordid = r.id AND
|
||||||
|
r.dataid = ?
|
||||||
";
|
";
|
||||||
$comments = get_records_sql($query);
|
$comments = $DB->get_records_sql($query, array($database_id));
|
||||||
return $comments;
|
return $comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
|
* @uses $DB
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function data_iterator() {
|
function data_iterator() {
|
||||||
$databases = get_records('data');
|
global $DB;
|
||||||
|
|
||||||
|
$databases = $DB->get_records('data');
|
||||||
return $databases;
|
return $databases;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
* @param database the database instance
|
* @uses $DB
|
||||||
|
* @param reference $database the database instance
|
||||||
* @return an array of searchable documents
|
* @return an array of searchable documents
|
||||||
*/
|
*/
|
||||||
function data_get_content_for_index(&$database) {
|
function data_get_content_for_index(&$database) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
$documents = array();
|
$documents = array();
|
||||||
$recordTitles = array();
|
$recordTitles = array();
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'data');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'data'));
|
||||||
$cm = get_record('course_modules', 'course', $database->course, 'module', $coursemodule, 'instance', $database->id);
|
$cm = $DB->get_record('course_modules', array('course' => $database->course, 'module' => $coursemodule, 'instance' => $database->id));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
|
||||||
// getting records for indexing
|
// getting records for indexing
|
||||||
$records_content = data_get_records($database->id, 'text');
|
$records_content = data_get_records($database->id, 'text');
|
||||||
if ($records_content){
|
if ($records_content){
|
||||||
foreach(array_keys($records_content) as $aRecordId) {
|
foreach(array_keys($records_content) as $arecordid) {
|
||||||
|
|
||||||
// extract title as first record in order
|
// extract title as first record in order
|
||||||
$first = $records_content[$aRecordId]['_first'];
|
$first = $records_content[$arecordid]['_first'];
|
||||||
unset($records_content[$aRecordId]['_first']);
|
unset($records_content[$arecordid]['_first']);
|
||||||
|
|
||||||
// concatenates all other texts
|
// concatenates all other texts
|
||||||
foreach($records_content[$aRecordId] as $aField){
|
$content = '';
|
||||||
$content = @$content.' '.$aField;
|
foreach($records_content[$arecordid] as $afield){
|
||||||
|
$content = @$content.' '.$afield;
|
||||||
}
|
}
|
||||||
if (strlen($content) > 0) {
|
if (strlen($content) > 0) {
|
||||||
unset($recordMetaData);
|
unset($recordMetaData);
|
||||||
$recordMetaData = get_record('data_records', 'id', $aRecordId);
|
$recordMetaData = $DB->get_record('data_records', array('id' => $arecordid));
|
||||||
$recordMetaData->title = $first;
|
$recordMetaData->title = $first;
|
||||||
$recordTitles[$aRecordId] = $first;
|
$recordTitles[$arecordid] = $first;
|
||||||
$recordMetaData->content = $content;
|
$recordMetaData->content = $content;
|
||||||
$documents[] = new DataSearchDocument(get_object_vars($recordMetaData), $database->course, $context->id);
|
$documents[] = new DataSearchDocument(get_object_vars($recordMetaData), $database->course, $context->id);
|
||||||
}
|
}
|
||||||
|
@ -230,22 +240,24 @@ function data_get_content_for_index(&$database) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a single data search document based on a data entry id
|
* returns a single data search document based on a data entry id
|
||||||
* @param id the id of the record
|
* @uses $DB
|
||||||
* @param the type of the information
|
* @param in $id the id of the record
|
||||||
|
* @param string $itemtype the type of the information
|
||||||
* @return a single searchable document
|
* @return a single searchable document
|
||||||
*/
|
*/
|
||||||
function data_single_document($id, $itemtype) {
|
function data_single_document($id, $itemtype) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
if ($itemtype == 'record'){
|
if ($itemtype == 'record'){
|
||||||
// get main record
|
// get main record
|
||||||
$recordMetaData = get_record('data_records', 'id', $id);
|
$recordMetaData = $DB->get_record('data_records', array('id' => $id));
|
||||||
// get context
|
// get context
|
||||||
$record_course = get_field('data', 'course', 'id', $recordMetaData->dataid);
|
$record_course = $DB->get_field('data', 'course', array('id' => $recordMetaData->dataid));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'data');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'data'));
|
||||||
$cm = get_record('course_modules', 'course', $record_course, 'module', $coursemodule, 'instance', $recordMetaData->dataid);
|
$cm = $DB->get_record('course_modules', array('course' => $record_course, 'module' => $coursemodule, 'instance' => $recordMetaData->dataid));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
// compute text
|
// compute text
|
||||||
$recordData = get_records_select('data_content', "recordid = $id AND type = 'text'", 'recordid');
|
$recordData = $DB->get_records_select('data_content', "recordid = ? AND type = 'text'", array($id), 'recordid');
|
||||||
$accumulator = '';
|
$accumulator = '';
|
||||||
if ($recordData){
|
if ($recordData){
|
||||||
$first = $recordData[0];
|
$first = $recordData[0];
|
||||||
|
@ -263,15 +275,15 @@ function data_single_document($id, $itemtype) {
|
||||||
$documents[] = new DataSearchDocument(get_object_vars($recordMetaData), $record_course, $context->id);
|
$documents[] = new DataSearchDocument(get_object_vars($recordMetaData), $record_course, $context->id);
|
||||||
} elseif($itemtype == 'comment') {
|
} elseif($itemtype == 'comment') {
|
||||||
// get main records
|
// get main records
|
||||||
$comment = get_record('data_comments', 'id', $id);
|
$comment = $DB->get_record('data_comments', array('id' => $id));
|
||||||
$record = get_record('data_records', 'id', $comment->recordid);
|
$record = $DB->get_record('data_records', array('id' => $comment->recordid));
|
||||||
// get context
|
// get context
|
||||||
$record_course = get_field('data', 'course', 'id', $record->dataid);
|
$record_course = $DB->get_field('data', 'course', array('id' => $record->dataid));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'data');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'data'));
|
||||||
$cm = get_record('course_modules', 'course', $record_course, 'module', $coursemodule, 'instance', $recordMetaData->dataid);
|
$cm = $DB->get_record('course_modules', array('course' => $record_course, 'module' => $coursemodule, 'instance' => $recordMetaData->dataid));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
// add extra fields
|
// add extra fields
|
||||||
$comment->title = get_field('search_document', 'title', 'docid', $record->id, 'itemtype', 'record');
|
$comment->title = $DB->get_field('search_document', 'title', array('docid' => $record->id, 'itemtype' => 'record'));
|
||||||
$comment->dataid = $record->dataid;
|
$comment->dataid = $record->dataid;
|
||||||
$comment->groupid = $record->groupid;
|
$comment->groupid = $record->groupid;
|
||||||
// make document
|
// make document
|
||||||
|
@ -311,44 +323,42 @@ function data_db_names() {
|
||||||
* - user is legitimate in the surrounding context
|
* - user is legitimate in the surrounding context
|
||||||
* - user may be guest and guest access is allowed to the module
|
* - user may be guest and guest access is allowed to the module
|
||||||
* - the function may perform local checks within the module information logic
|
* - the function may perform local checks within the module information logic
|
||||||
* @param path the access path to the module script code
|
* @param string $path the access path to the module script code
|
||||||
* @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
* @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
||||||
* @param this_id the item id within the information class denoted by itemtype. In databases, this id
|
* @param int $this_id the item id within the information class denoted by itemtype. In databases, this id
|
||||||
* points out an indexed data record page.
|
* points out an indexed data record page.
|
||||||
* @param user the user record denoting the user who searches
|
* @param object $user the user record denoting the user who searches
|
||||||
* @param group_id the current group used by the user when searching
|
* @param int $group_id the current group used by the user when searching
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
* @return true if access is allowed, false elsewhere
|
* @return true if access is allowed, false elsewhere
|
||||||
*/
|
*/
|
||||||
function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// get the database object and all related stuff
|
// get the database object and all related stuff
|
||||||
if ($itemtype == 'record'){
|
if ($itemtype == 'record'){
|
||||||
$record = get_record('data_records', 'id', $this_id);
|
$record = $DB->get_record('data_records', array('id' => $this_id));
|
||||||
}
|
}
|
||||||
elseif($itemtype == 'comment'){
|
elseif($itemtype == 'comment'){
|
||||||
$comment = get_record('data_comments', 'id', $this_id);
|
$comment = $DB->get_record('data_comments', array('id' => $this_id));
|
||||||
$record = get_record('data_records', 'id', $comment->recordid);
|
$record = $DB->get_record('data_records', array('id' => $comment->recordid));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// we do not know what type of information is required
|
// we do not know what type of information is required
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$data = get_record('data', 'id', $record->dataid);
|
$data = $DB->get_record('data', array('id' => $record->dataid));
|
||||||
$context = get_record('context', 'id', $context_id);
|
$context = $DB->get_record('context', array('id' => $context_id));
|
||||||
$cm = get_record('course_modules', 'id', $context->instanceid);
|
$cm = $DB->get_record('course_modules', array('id' => $context->instanceid));
|
||||||
// $cm = get_coursemodule_from_instance('data', $data->id, $data->course);
|
|
||||||
// $context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
||||||
|
|
||||||
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
||||||
if (!empty($CFG->search_access_debug)) echo "search reject : hidden database ";
|
if (!empty($CFG->search_access_debug)) echo "search reject : hidden database ";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//group consistency check : checks the following situations about groups
|
//group consistency check : checks the following situations about groups
|
||||||
// trap if user is not same group and groups are separated
|
// trap if user is not same group and groups are separated
|
||||||
$course = get_record('course', 'id', $data->course);
|
$course = $DB->get_record('course', 'id', $data->course);
|
||||||
if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($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 ";
|
if (!empty($CFG->search_access_debug)) echo "search reject : separated group owned resource ";
|
||||||
return false;
|
return false;
|
||||||
|
@ -366,7 +376,7 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
|
||||||
//approval check
|
//approval check
|
||||||
// trap if unapproved and has not approval capabilities
|
// trap if unapproved and has not approval capabilities
|
||||||
// TODO : report a potential capability lack of : mod/data:approve
|
// TODO : report a potential capability lack of : mod/data:approve
|
||||||
$approval = get_field('data_records', 'approved', 'id', $record->id);
|
$approval = $DB->get_field('data_records', 'approved', array('id' => $record->id));
|
||||||
if (!$approval && !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 ";
|
if (!empty($CFG->search_access_debug)) echo "search reject : unapproved resource ";
|
||||||
return false;
|
return false;
|
||||||
|
@ -375,7 +385,7 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
|
||||||
//minimum records to view check
|
//minimum records to view check
|
||||||
// trap if too few records
|
// trap if too few records
|
||||||
// TODO : report a potential capability lack of : mod/data:viewhiddenentries
|
// TODO : report a potential capability lack of : mod/data:viewhiddenentries
|
||||||
$recordsAmount = count_records('data_records', 'dataid', $data->id);
|
$recordsAmount = $DB->count_records('data_records', array('dataid' => $data->id));
|
||||||
if ($data->requiredentriestoview > $recordsAmount && !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 ";
|
if (!empty($CFG->search_access_debug)) echo "search reject : not enough records to view ";
|
||||||
return false;
|
return false;
|
||||||
|
@ -404,7 +414,12 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
|
||||||
* @param string $title
|
* @param string $title
|
||||||
*/
|
*/
|
||||||
function data_link_post_processing($title){
|
function data_link_post_processing($title){
|
||||||
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
global $CFG;
|
||||||
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
|
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
abstract class SearchDocument extends Zend_Search_Lucene_Document {
|
abstract class SearchDocument extends Zend_Search_Lucene_Document {
|
||||||
public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $path) {
|
public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $path, $additional_keyset = null) {
|
||||||
//document identification and indexing
|
//document identification and indexing
|
||||||
$this->addField(Zend_Search_Lucene_Field::Keyword('docid', $doc->docid));
|
$this->addField(Zend_Search_Lucene_Field::Keyword('docid', $doc->docid));
|
||||||
//document type : the name of the Moodle element that manages it
|
//document type : the name of the Moodle element that manages it
|
||||||
|
@ -59,6 +59,16 @@ abstract class SearchDocument extends Zend_Search_Lucene_Document {
|
||||||
// of multiple capabilities in their code. This possibility should be left open here.
|
// of multiple capabilities in their code. This possibility should be left open here.
|
||||||
$this->addField(Zend_Search_Lucene_Field::UnIndexed('capabilities', $caps));
|
$this->addField(Zend_Search_Lucene_Field::UnIndexed('capabilities', $caps));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Additional key set allows a module to ask for extensible criteria based search
|
||||||
|
// depending on the module internal needs.
|
||||||
|
*/
|
||||||
|
if (!empty($additional_keyset)){
|
||||||
|
foreach($additional_keyset as $keyname => $keyvalue){
|
||||||
|
$this->addField(Zend_Search_Lucene_Field::Keyword($keyname, $keyvalue));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
*
|
*
|
||||||
* document handling for forum activity module
|
* document handling for forum activity module
|
||||||
* This file contains the mapping between a forum post and it's indexable counterpart,
|
* This file contains the mapping between a forum post and it's indexable counterpart,
|
||||||
|
@ -20,8 +21,8 @@
|
||||||
/**
|
/**
|
||||||
* includes and requires
|
* includes and requires
|
||||||
*/
|
*/
|
||||||
require_once("$CFG->dirroot/search/documents/document.php");
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
require_once("$CFG->dirroot/mod/forum/lib.php");
|
require_once($CFG->dirroot.'/mod/forum/lib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a class for representing searchable information
|
* a class for representing searchable information
|
||||||
|
@ -31,8 +32,11 @@ class ForumSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
|
* @uses $DB;
|
||||||
*/
|
*/
|
||||||
public function __construct(&$post, $forum_id, $course_id, $itemtype, $context_id) {
|
public function __construct(&$post, $forum_id, $course_id, $itemtype, $context_id) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
// generic information
|
// generic information
|
||||||
$doc->docid = $post['id'];
|
$doc->docid = $post['id'];
|
||||||
$doc->documenttype = SEARCH_TYPE_FORUM;
|
$doc->documenttype = SEARCH_TYPE_FORUM;
|
||||||
|
@ -41,7 +45,7 @@ class ForumSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
$doc->title = $post['subject'];
|
$doc->title = $post['subject'];
|
||||||
|
|
||||||
$user = get_record('user', 'id', $post['userid']);
|
$user = $DB->get_record('user', array('id' => $post['userid']));
|
||||||
$doc->author = fullname($user);
|
$doc->author = fullname($user);
|
||||||
$doc->contents = $post['message'];
|
$doc->contents = $post['message'];
|
||||||
$doc->date = $post['created'];
|
$doc->date = $post['created'];
|
||||||
|
@ -57,8 +61,9 @@ class ForumSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructs a valid link to a chat content
|
* constructs a valid link to a chat content
|
||||||
* @param discussion_id the discussion
|
* @uses $CFG
|
||||||
* @param post_id the id of a single post
|
* @param int $discussion_id the discussion
|
||||||
|
* @param int $post_id the id of a single post
|
||||||
* @return a well formed link to forum message display
|
* @return a well formed link to forum message display
|
||||||
*/
|
*/
|
||||||
function forum_make_link($discussion_id, $post_id) {
|
function forum_make_link($discussion_id, $post_id) {
|
||||||
|
@ -69,19 +74,24 @@ function forum_make_link($discussion_id, $post_id) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search standard API
|
* search standard API
|
||||||
|
* @uses $DB;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function forum_iterator() {
|
function forum_iterator() {
|
||||||
$forums = get_records('forum');
|
global $DB;
|
||||||
|
|
||||||
|
$forums = $DB->get_records('forum');
|
||||||
return $forums;
|
return $forums;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search standard API
|
* search standard API
|
||||||
* @param forum a forum instance
|
* @uses $DB
|
||||||
|
* @param reference $forum a forum instance
|
||||||
* @return an array of searchable documents
|
* @return an array of searchable documents
|
||||||
*/
|
*/
|
||||||
function forum_get_content_for_index(&$forum) {
|
function forum_get_content_for_index(&$forum) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
$documents = array();
|
$documents = array();
|
||||||
if (!$forum) return $documents;
|
if (!$forum) return $documents;
|
||||||
|
@ -90,8 +100,8 @@ function forum_get_content_for_index(&$forum) {
|
||||||
mtrace("Found ".count($posts)." discussions to analyse in forum ".$forum->name);
|
mtrace("Found ".count($posts)." discussions to analyse in forum ".$forum->name);
|
||||||
if (!$posts) return $documents;
|
if (!$posts) return $documents;
|
||||||
|
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'forum');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'forum'));
|
||||||
$cm = get_record('course_modules', 'course', $forum->course, 'module', $coursemodule, 'instance', $forum->id);
|
$cm = $DB->get_record('course_modules', array('course' => $forum->course, 'module' => $coursemodule, 'instance' => $forum->id));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
|
||||||
foreach($posts as $aPost) {
|
foreach($posts as $aPost) {
|
||||||
|
@ -118,16 +128,18 @@ function forum_get_content_for_index(&$forum) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a single forum search document based on a forum entry id
|
* returns a single forum search document based on a forum entry id
|
||||||
* @param id an id for a single information stub
|
* @uses $DB
|
||||||
* @param itemtype the type of information
|
* @param int $id an id for a single information stub
|
||||||
|
* @param string $itemtype the type of information
|
||||||
*/
|
*/
|
||||||
function forum_single_document($id, $itemtype) {
|
function forum_single_document($id, $itemtype) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
// both known item types are posts so get them the same way
|
// both known item types are posts so get them the same way
|
||||||
$post = get_record('forum_posts', 'id', $id);
|
$post = $DB->get_record('forum_posts', array('id' => $id));
|
||||||
$discussion = get_record('forum_discussions', 'id', $post->discussion);
|
$discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'forum');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'forum'));
|
||||||
$cm = get_record('course_modules', 'course', $discussion->course, 'module', $coursemodule, 'instance', $discussion->forum);
|
$cm = $DB->get_record('course_modules', array('course' => $discussion->course, 'module' => $coursemodule, 'instance' => $discussion->forum));
|
||||||
if ($cm){
|
if ($cm){
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
$post->groupid = $discussion->groupid;
|
$post->groupid = $discussion->groupid;
|
||||||
|
@ -161,17 +173,18 @@ function forum_db_names() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reworked faster version from /mod/forum/lib.php
|
* reworked faster version from /mod/forum/lib.php
|
||||||
* @param forum_id a forum identifier
|
* @param int $forum_id a forum identifier
|
||||||
* @uses CFG, USER
|
* @uses $CFG, $USER, $DB
|
||||||
* @return an array of posts
|
* @return an array of posts
|
||||||
|
* @todo get rid of old isteacher() call
|
||||||
*/
|
*/
|
||||||
function forum_get_discussions_fast($forum_id) {
|
function forum_get_discussions_fast($forum_id) {
|
||||||
global $CFG, $USER;
|
global $CFG, $USER, $DB;
|
||||||
|
|
||||||
$timelimit='';
|
$timelimit='';
|
||||||
if (!empty($CFG->forum_enabletimedposts)) {
|
if (!empty($CFG->forum_enabletimedposts)) {
|
||||||
if (!((has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))
|
if (!((has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))
|
||||||
and !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) {
|
&& !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) {
|
||||||
$now = time();
|
$now = time();
|
||||||
$timelimit = " AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')";
|
$timelimit = " AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')";
|
||||||
if (!empty($USER->id)) {
|
if (!empty($USER->id)) {
|
||||||
|
@ -182,7 +195,7 @@ function forum_get_discussions_fast($forum_id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = "
|
$query = "
|
||||||
SELECT
|
SELECT
|
||||||
p.id,
|
p.id,
|
||||||
p.subject,
|
p.subject,
|
||||||
p.discussion,
|
p.discussion,
|
||||||
|
@ -203,24 +216,24 @@ function forum_get_discussions_fast($forum_id) {
|
||||||
ON
|
ON
|
||||||
p.userid = u.id
|
p.userid = u.id
|
||||||
WHERE
|
WHERE
|
||||||
d.forum = '{$forum_id}' AND
|
d.forum = ? AND
|
||||||
p.parent = 0
|
p.parent = 0
|
||||||
$timelimit
|
$timelimit
|
||||||
ORDER BY
|
ORDER BY
|
||||||
d.timemodified DESC
|
d.timemodified DESC
|
||||||
";
|
";
|
||||||
return get_records_sql($query);
|
return $DB->get_records_sql($query, array($forum_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reworked faster version from /mod/forum/lib.php
|
* reworked faster version from /mod/forum/lib.php
|
||||||
* @param parent the id of the first post within the discussion
|
* @param int $parent the id of the first post within the discussion
|
||||||
* @param forum_id the forum identifier
|
* @param int $forum_id the forum identifier
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
* @return an array of posts
|
* @return an array of posts
|
||||||
*/
|
*/
|
||||||
function forum_get_child_posts_fast($parent, $forum_id) {
|
function forum_get_child_posts_fast($parent, $forum_id) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$query = "
|
$query = "
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -229,7 +242,7 @@ function forum_get_child_posts_fast($parent, $forum_id) {
|
||||||
p.discussion,
|
p.discussion,
|
||||||
p.message,
|
p.message,
|
||||||
p.created,
|
p.created,
|
||||||
{$forum_id} AS forum,
|
? AS forum,
|
||||||
p.userid,
|
p.userid,
|
||||||
d.groupid,
|
d.groupid,
|
||||||
u.firstname,
|
u.firstname,
|
||||||
|
@ -245,11 +258,11 @@ function forum_get_child_posts_fast($parent, $forum_id) {
|
||||||
ON
|
ON
|
||||||
p.userid = u.id
|
p.userid = u.id
|
||||||
WHERE
|
WHERE
|
||||||
p.parent = '{$parent}'
|
p.parent = ?
|
||||||
ORDER BY
|
ORDER BY
|
||||||
p.created ASC
|
p.created ASC
|
||||||
";
|
";
|
||||||
return get_records_sql($query);
|
return $DB->get_records_sql($query, array($forum_id, $parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -259,25 +272,25 @@ function forum_get_child_posts_fast($parent, $forum_id) {
|
||||||
* - user is legitimate in the surrounding context
|
* - user is legitimate in the surrounding context
|
||||||
* - user may be guest and guest access is allowed to the module
|
* - user may be guest and guest access is allowed to the module
|
||||||
* - the function may perform local checks within the module information logic
|
* - the function may perform local checks within the module information logic
|
||||||
* @param path the access path to the module script code
|
* @param string $path the access path to the module script code
|
||||||
* @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
* @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
||||||
* @param this_id the item id within the information class denoted by itemtype. In forums, this id
|
* @param int $this_id the item id within the information class denoted by itemtype. In forums, this id
|
||||||
* points out the individual post.
|
* points out the individual post.
|
||||||
* @param user the user record denoting the user who searches
|
* @param object $user the user record denoting the user who searches
|
||||||
* @param group_id the current group used by the user when searching
|
* @param int $group_id the current group used by the user when searching
|
||||||
* @uses CFG, USER
|
* @uses $CFG, $USER, $DB
|
||||||
* @return true if access is allowed, false elsewhere
|
* @return true if access is allowed, false elsewhere
|
||||||
*/
|
*/
|
||||||
function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
global $CFG, $USER;
|
global $CFG, $USER, $DB;
|
||||||
|
|
||||||
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
||||||
|
|
||||||
// get the forum post and all related stuff
|
// get the forum post and all related stuff
|
||||||
$post = get_record('forum_posts', 'id', $this_id);
|
$post = $DB->get_record('forum_posts', array('id' => $this_id));
|
||||||
$discussion = get_record('forum_discussions', 'id', $post->discussion);
|
$discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion));
|
||||||
$context = get_record('context', 'id', $context_id);
|
$context = $DB->get_record('context', array('id' => $context_id));
|
||||||
$cm = get_record('course_modules', 'id', $context->instanceid);
|
$cm = $DB->get_record('course_modules', array('id' => $context->instanceid));
|
||||||
// $cm = get_coursemodule_from_instance('forum', $discussion->forum, $discussion->course);
|
// $cm = get_coursemodule_from_instance('forum', $discussion->forum, $discussion->course);
|
||||||
// $context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
// $context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
|
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
|
||||||
|
@ -293,7 +306,7 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $
|
||||||
|
|
||||||
// group check : entries should be in accessible groups
|
// group check : entries should be in accessible groups
|
||||||
$current_group = get_current_group($discussion->course);
|
$current_group = get_current_group($discussion->course);
|
||||||
$course = get_record('course', 'id', $discussion->course);
|
$course = $DB->get_record('course', array('id' => $discussion->course));
|
||||||
if ($group_id >= 0 && (groupmode($course, $cm) == SEPARATEGROUPS) && ($group_id != $current_group) && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)){
|
if ($group_id >= 0 && (groupmode($course, $cm) == SEPARATEGROUPS) && ($group_id != $current_group) && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)){
|
||||||
if (!empty($CFG->search_access_debug)) echo "search reject : separated grouped forum item";
|
if (!empty($CFG->search_access_debug)) echo "search reject : separated grouped forum item";
|
||||||
return false;
|
return false;
|
||||||
|
@ -304,10 +317,15 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* post processes the url for cleaner output.
|
* post processes the url for cleaner output.
|
||||||
|
* @uses $CFG
|
||||||
* @param string $title
|
* @param string $title
|
||||||
*/
|
*/
|
||||||
function forum_link_post_processing($title){
|
function forum_link_post_processing($title){
|
||||||
// return mb_convert_encoding($title, 'UTF-8', 'auto');
|
global $CFG;
|
||||||
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
*
|
*
|
||||||
* document handling for glossary activity module
|
* document handling for glossary activity module
|
||||||
* This file contains a mapping between a glossary entry and it's indexable counterpart,
|
* This file contains a mapping between a glossary entry and it's indexable counterpart,
|
||||||
|
@ -20,7 +21,7 @@
|
||||||
/**
|
/**
|
||||||
* includes and requires
|
* includes and requires
|
||||||
*/
|
*/
|
||||||
require_once("$CFG->dirroot/search/documents/document.php");
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a class for representing searchable information
|
* a class for representing searchable information
|
||||||
|
@ -33,6 +34,8 @@ class GlossarySearchDocument extends SearchDocument {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(&$entry, $course_id, $context_id) {
|
public function __construct(&$entry, $course_id, $context_id) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
// generic information; required
|
// generic information; required
|
||||||
$doc->docid = $entry['id'];
|
$doc->docid = $entry['id'];
|
||||||
$doc->documenttype = SEARCH_TYPE_GLOSSARY;
|
$doc->documenttype = SEARCH_TYPE_GLOSSARY;
|
||||||
|
@ -43,7 +46,7 @@ class GlossarySearchDocument extends SearchDocument {
|
||||||
$doc->date = $entry['timecreated'];
|
$doc->date = $entry['timecreated'];
|
||||||
|
|
||||||
if ($entry['userid'])
|
if ($entry['userid'])
|
||||||
$user = get_record('user', 'id', $entry['userid']);
|
$user = $DB->get_record('user', array('id' => $entry['userid']));
|
||||||
$doc->author = ($user ) ? $user->firstname.' '.$user->lastname : '' ;
|
$doc->author = ($user ) ? $user->firstname.' '.$user->lastname : '' ;
|
||||||
$doc->contents = strip_tags($entry['definition']);
|
$doc->contents = strip_tags($entry['definition']);
|
||||||
$doc->url = glossary_make_link($entry['id']);
|
$doc->url = glossary_make_link($entry['id']);
|
||||||
|
@ -64,8 +67,11 @@ class GlossaryCommentSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* document constructor
|
* document constructor
|
||||||
|
* @uses $DB
|
||||||
*/
|
*/
|
||||||
public function __construct(&$entry, $glossary_id, $course_id, $context_id) {
|
public function __construct(&$entry, $glossary_id, $course_id, $context_id) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
// generic information; required
|
// generic information; required
|
||||||
$doc->docid = $entry['id'];
|
$doc->docid = $entry['id'];
|
||||||
$doc->documenttype = SEARCH_TYPE_GLOSSARY;
|
$doc->documenttype = SEARCH_TYPE_GLOSSARY;
|
||||||
|
@ -76,7 +82,7 @@ class GlossaryCommentSearchDocument extends SearchDocument {
|
||||||
$doc->date = $entry['timemodified'];
|
$doc->date = $entry['timemodified'];
|
||||||
|
|
||||||
if ($entry['userid'])
|
if ($entry['userid'])
|
||||||
$user = get_record('user', 'id', $entry['userid']);
|
$user = $DB->get_record('user', array('id' => $entry['userid']));
|
||||||
$doc->author = ($user ) ? $user->firstname.' '.$user->lastname : '' ;
|
$doc->author = ($user ) ? $user->firstname.' '.$user->lastname : '' ;
|
||||||
$doc->contents = strip_tags($entry['entrycomment']);
|
$doc->contents = strip_tags($entry['entrycomment']);
|
||||||
$doc->url = glossary_make_link($entry['entryid']);
|
$doc->url = glossary_make_link($entry['entryid']);
|
||||||
|
@ -85,13 +91,14 @@ class GlossaryCommentSearchDocument extends SearchDocument {
|
||||||
$data->glossary = $glossary_id;
|
$data->glossary = $glossary_id;
|
||||||
|
|
||||||
// construct the parent class
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructs valid access links to information
|
* constructs valid access links to information
|
||||||
* @param entry_id the id of the glossary entry
|
* @uses $CFG
|
||||||
|
* @param int $entry_id the id of the glossary entry
|
||||||
* @return a full featured link element as a string
|
* @return a full featured link element as a string
|
||||||
*/
|
*/
|
||||||
function glossary_make_link($entry_id) {
|
function glossary_make_link($entry_id) {
|
||||||
|
@ -104,7 +111,7 @@ function glossary_make_link($entry_id) {
|
||||||
// Suggestion : bounce on popup within the glossarie's showentry page
|
// Suggestion : bounce on popup within the glossarie's showentry page
|
||||||
// preserve glossary pop-up, be careful where you place your ' and "s
|
// preserve glossary pop-up, be careful where you place your ' and "s
|
||||||
//this function is meant to return a url that is placed between href='[url here]'
|
//this function is meant to return a url that is placed between href='[url here]'
|
||||||
return "$CFG->wwwroot/mod/glossary/showentry.php?eid=$entry_id' onclick='return openpopup(\"/mod/glossary/showentry.php?eid=$entry_id\", \"entry\", DEFAULT_POPUP_SETTINGS, 0);";
|
return "$CFG->wwwroot/mod/glossary/showentry.php?eid=$entry_id' onclick='return openpopup(\"/mod/glossary/showentry.php?eid={$entry_id}\", \"entry\", DEFAULT_POPUP_SETTINGS, 0);";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,27 +119,30 @@ function glossary_make_link($entry_id) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function glossary_iterator() {
|
function glossary_iterator() {
|
||||||
$glossaries = get_records('glossary');
|
global $DB;
|
||||||
return $glossaries;
|
|
||||||
|
$glossaries = $DB->get_records('glossary');
|
||||||
|
return $glossaries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
* @glossary a glossary instance
|
* @uses $DB
|
||||||
|
* @param object $glossary a glossary instance
|
||||||
* @return an array of searchable documents
|
* @return an array of searchable documents
|
||||||
*/
|
*/
|
||||||
function glossary_get_content_for_index(&$glossary) {
|
function glossary_get_content_for_index(&$glossary) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// get context
|
// get context
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'glossary');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'glossary'));
|
||||||
$cm = get_record('course_modules', 'course', $glossary->course, 'module', $coursemodule, 'instance', $glossary->id);
|
$cm = $DB->get_record('course_modules', array('course' => $glossary->course, 'module' => $coursemodule, 'instance' => $glossary->id));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
|
||||||
$documents = array();
|
$documents = array();
|
||||||
$entryIds = array();
|
$entryIds = array();
|
||||||
// index entries
|
// index entries
|
||||||
$entries = get_records('glossary_entries', 'glossaryid', $glossary->id);
|
$entries = $DB->get_records('glossary_entries', array('glossaryid' => $glossary->id));
|
||||||
if ($entries){
|
if ($entries){
|
||||||
foreach($entries as $entry) {
|
foreach($entries as $entry) {
|
||||||
$concepts[$entry->id] = $entry->concept;
|
$concepts[$entry->id] = $entry->concept;
|
||||||
|
@ -160,21 +170,24 @@ function glossary_get_content_for_index(&$glossary) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
* @param id the glossary entry identifier
|
* @uses $DB
|
||||||
* @itemtype the type of information
|
* @param int $id the glossary entry identifier
|
||||||
|
* @param string $itemtype the type of information
|
||||||
* @return a single search document based on a glossary entry
|
* @return a single search document based on a glossary entry
|
||||||
*/
|
*/
|
||||||
function glossary_single_document($id, $itemtype) {
|
function glossary_single_document($id, $itemtype) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
if ($itemtype == 'standard'){
|
if ($itemtype == 'standard'){
|
||||||
$entry = get_record('glossary_entries', 'id', $id);
|
$entry = $DB->get_record('glossary_entries', array('id' => $id));
|
||||||
}
|
}
|
||||||
elseif ($itemtype == 'comment'){
|
elseif ($itemtype == 'comment'){
|
||||||
$comment = get_record('glossary_comments', 'id', $id);
|
$comment = $DB->get_record('glossary_comments', array('id' => $id));
|
||||||
$entry = get_record('glossary_entries', 'id', $comment->entryid);
|
$entry = $DB->get_record('glossary_entries', array('id' => $comment->entryid));
|
||||||
}
|
}
|
||||||
$glossary_course = get_field('glossary', 'course', 'id', $entry->glossaryid);
|
$glossary_course = $DB->get_field('glossary', 'course', array('id' => $entry->glossaryid));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'glossary');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'glossary'));
|
||||||
$cm = get_record('course_modules', 'course', $glossary_course, 'module', $coursemodule, 'instance', $entry->glossaryid);
|
$cm = $DB->get_record('course_modules', array('course' => $glossary_course, 'module' => $coursemodule, 'instance' => $entry->glossaryid));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
if ($itemtype == 'standard'){
|
if ($itemtype == 'standard'){
|
||||||
return new GlossarySearchDocument(get_object_vars($entry), $glossary_course, $context->id);
|
return new GlossarySearchDocument(get_object_vars($entry), $glossary_course, $context->id);
|
||||||
|
@ -214,6 +227,7 @@ function glossary_db_names() {
|
||||||
* - user is legitimate in the surrounding context
|
* - user is legitimate in the surrounding context
|
||||||
* - user may be guest and guest access is allowed to the module
|
* - user may be guest and guest access is allowed to the module
|
||||||
* - the function may perform local checks within the module information logic
|
* - the function may perform local checks within the module information logic
|
||||||
|
* @uses $CFG, $DB
|
||||||
* @param string $path the access path to the module script code
|
* @param string $path the access path to the module script code
|
||||||
* @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
* @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
||||||
* @param int $this_id the item id within the information class denoted by itemtype. In glossaries, this id
|
* @param int $this_id the item id within the information class denoted by itemtype. In glossaries, this id
|
||||||
|
@ -224,15 +238,13 @@ function glossary_db_names() {
|
||||||
* @return true if access is allowed, false elsewhere
|
* @return true if access is allowed, false elsewhere
|
||||||
*/
|
*/
|
||||||
function glossary_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
function glossary_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// get the glossary object and all related stuff
|
// get the glossary object and all related stuff
|
||||||
$entry = get_record('glossary_entries', 'id', $this_id);
|
$entry = $DB->get_record('glossary_entries', array('id' => $this_id));
|
||||||
$glossary = get_record('glossary', 'id', $entry->glossaryid);
|
$glossary = $DB->get_record('glossary', array('id' => $entry->glossaryid));
|
||||||
$context = get_record('context', 'id', $context_id);
|
$context = $DB->get_record('context', array('id' => $context_id));
|
||||||
$cm = get_record('course_modules', 'id', $context->instanceid);
|
$cm = $DB->get_record('course_modules', array('id' => $context->instanceid));
|
||||||
// $cm = get_coursemodule_from_instance('glossary', $glossary->id, $glossary->course);
|
|
||||||
// $context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
||||||
|
|
||||||
if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -251,6 +263,11 @@ function glossary_check_text_access($path, $itemtype, $this_id, $user, $group_id
|
||||||
* @param string $title
|
* @param string $title
|
||||||
*/
|
*/
|
||||||
function glossary_link_post_processing($title){
|
function glossary_link_post_processing($title){
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
188
search/documents/label_document.php
Normal file
188
search/documents/label_document.php
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Global Search Engine for Moodle
|
||||||
|
*
|
||||||
|
* @package search
|
||||||
|
* @category core
|
||||||
|
* @subpackage document_wrappers
|
||||||
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.9
|
||||||
|
* @date 2008/03/31
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
|
*
|
||||||
|
* document handling for all resources
|
||||||
|
* This file contains the mapping between a resource and it's indexable counterpart,
|
||||||
|
*
|
||||||
|
* Functions for iterating and retrieving the necessary records are now also included
|
||||||
|
* in this file, rather than mod/resource/lib.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* requires and includes
|
||||||
|
*/
|
||||||
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
|
require_once($CFG->dirroot.'/mod/resource/lib.php');
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* a class for representing searchable information
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class LabelSearchDocument extends SearchDocument {
|
||||||
|
public function __construct(&$label, $context_id) {
|
||||||
|
// generic information; required
|
||||||
|
$doc->docid = $label['id'];
|
||||||
|
$doc->documenttype = SEARCH_TYPE_LABEL;
|
||||||
|
$doc->itemtype = 'label';
|
||||||
|
$doc->contextid = $context_id;
|
||||||
|
|
||||||
|
$doc->title = strip_tags($label['name']);
|
||||||
|
$doc->date = $label['timemodified'];
|
||||||
|
$doc->author = '';
|
||||||
|
$doc->contents = strip_tags($label['content']);
|
||||||
|
$doc->url = label_make_link($label['course']);
|
||||||
|
|
||||||
|
// module specific information; optional
|
||||||
|
$data = array();
|
||||||
|
|
||||||
|
// construct the parent class
|
||||||
|
parent::__construct($doc, $data, $label['course'], 0, 0, 'mod/'.SEARCH_TYPE_LABEL);
|
||||||
|
} //constructor
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructs valid access links to information
|
||||||
|
* @param int $resourceId the of the resource
|
||||||
|
* @return a full featured link element as a string
|
||||||
|
*/
|
||||||
|
function label_make_link($course_id) {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
return $CFG->wwwroot.'/course/view.php?id='.$course_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* part of standard API
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function label_iterator() {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
//trick to leave search indexer functionality intact, but allow
|
||||||
|
//this document to only use the below function to return info
|
||||||
|
//to be searched
|
||||||
|
$labels = $DB->get_records('label');
|
||||||
|
return $labels;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* part of standard API
|
||||||
|
* this function does not need a content iterator, returns all the info
|
||||||
|
* itself;
|
||||||
|
* @param $label notneeded to comply API, remember to fake the iterator array though
|
||||||
|
* @uses $CFG, $DB
|
||||||
|
* @return an array of searchable documents
|
||||||
|
*/
|
||||||
|
function label_get_content_for_index(&$label) {
|
||||||
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
// starting with Moodle native resources
|
||||||
|
$documents = array();
|
||||||
|
|
||||||
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'label'));
|
||||||
|
$cm = $DB->get_record('course_modules', array('course' => $label->course, 'module' => $coursemodule, 'instance' => $label->id));
|
||||||
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
|
||||||
|
$documents[] = new LabelSearchDocument(get_object_vars($label), $context->id);
|
||||||
|
|
||||||
|
mtrace("finished label {$label->id}");
|
||||||
|
return $documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* part of standard API.
|
||||||
|
* returns a single resource search document based on a label id
|
||||||
|
* @uses $CFG, $DB
|
||||||
|
* @param int $id the id of the accessible document
|
||||||
|
* @param string $itemtype the nature of the information making the document
|
||||||
|
* @return a searchable object or null if failure
|
||||||
|
*/
|
||||||
|
function label_single_document($id, $itemtype) {
|
||||||
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
$label = $DB->get_record('label', array('id' => $id));
|
||||||
|
|
||||||
|
if ($label){
|
||||||
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'label'));
|
||||||
|
$cm = $DB->get_record('course_modules', array('id' => $label->id));
|
||||||
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
return new LabelSearchDocument(get_object_vars($label), $context->id);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dummy delete function that aggregates id with itemtype.
|
||||||
|
* this was here for a reason, but I can't remember it at the moment.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function label_delete($info, $itemtype) {
|
||||||
|
$object->id = $info;
|
||||||
|
$object->itemtype = $itemtype;
|
||||||
|
return $object;
|
||||||
|
} //resource_delete
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the var names needed to build a sql query for addition/deletions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function label_db_names() {
|
||||||
|
//[primary id], [table name], [time created field name], [time modified field name], [docsubtype], [additional where conditions for sql]
|
||||||
|
return array(array('id', 'label', 'timemodified', 'timemodified', 'label', ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this function handles the access policy to contents indexed as searchable documents. If this
|
||||||
|
* function does not exist, the search engine assumes access is allowed.
|
||||||
|
* @uses $CFG, $DB
|
||||||
|
* @param string $path the access path to the module script code
|
||||||
|
* @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
||||||
|
* @param int $this_id the item id within the information class denoted by itemtype. In resources, this id
|
||||||
|
* points to the resource record and not to the module that shows it.
|
||||||
|
* @param object $user the user record denoting the user who searches
|
||||||
|
* @param int $group_id the current group used by the user when searching
|
||||||
|
* @return true if access is allowed, false elsewhere
|
||||||
|
*/
|
||||||
|
function label_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
$r = $DB->get_record('label', array('id' => $this_id));
|
||||||
|
$module_context = $DB->get_record('context', array('id' => $context_id));
|
||||||
|
$cm = $DB->get_record('course_modules', array('id' => $module_context->instanceid));
|
||||||
|
$course_context = get_context_instance(CONTEXT_COURSE, $r->course);
|
||||||
|
|
||||||
|
//check if englobing course is visible
|
||||||
|
if (!has_capability('moodle/course:view', $course_context)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check if found course module is visible
|
||||||
|
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post processes the url for cleaner output.
|
||||||
|
* @param string $title
|
||||||
|
*/
|
||||||
|
function label_link_post_processing($title){
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding("(".shorten_text(clean_text($title), 60)."...) ", 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
|
return mb_convert_encoding("(".shorten_text(clean_text($title), 60)."...) ", 'auto', 'UTF-8');
|
||||||
|
}
|
||||||
|
?>
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
*
|
*
|
||||||
* document handling for lesson activity module
|
* document handling for lesson activity module
|
||||||
* This file contains the mapping between a lesson page and it's indexable counterpart,
|
* This file contains the mapping between a lesson page and it's indexable counterpart,
|
||||||
|
@ -19,8 +20,8 @@
|
||||||
/**
|
/**
|
||||||
* includes and requires
|
* includes and requires
|
||||||
*/
|
*/
|
||||||
require_once("$CFG->dirroot/search/documents/document.php");
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
require_once("$CFG->dirroot/mod/lesson/lib.php");
|
require_once($CFG->dirroot.'/mod/lesson/lib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a class for representing searchable information
|
* a class for representing searchable information
|
||||||
|
@ -57,40 +58,49 @@ class LessonPageSearchDocument extends SearchDocument {
|
||||||
* constructs a valid link to a chat content
|
* constructs a valid link to a chat content
|
||||||
* @param int $lessonid the lesson module
|
* @param int $lessonid the lesson module
|
||||||
* @param int $itemid the id of a single page
|
* @param int $itemid the id of a single page
|
||||||
|
* @param string $itemtype the nature of the indexed object
|
||||||
* @return a well formed link to lesson page
|
* @return a well formed link to lesson page
|
||||||
*/
|
*/
|
||||||
function lesson_make_link($lessonmoduleid, $itemid, $itemtype) {
|
function lesson_make_link($lessonmoduleid, $itemid, $itemtype) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
if ($itemtype == 'page'){
|
if ($itemtype == 'page'){
|
||||||
return "{$CFG->wwwroot}/mod/lesson/view.php?id={$lessonmoduleid}&pageid={$itemid}";
|
return $CFG->wwwroot."/mod/lesson/view.php?id={$lessonmoduleid}&pageid={$itemid}";
|
||||||
}
|
}
|
||||||
return $CFG->wwwroot.'/mod/lesson/view.php?id='.$lessonmoduleid;
|
return $CFG->wwwroot.'/mod/lesson/view.php?id='.$lessonmoduleid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search standard API
|
* search standard API
|
||||||
|
* @uses $DB
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function lesson_iterator() {
|
function lesson_iterator() {
|
||||||
$lessons = get_records('lesson');
|
global $DB;
|
||||||
return $lessons;
|
|
||||||
|
if ($lessons = $DB->get_records('lesson')){
|
||||||
|
return $lessons;
|
||||||
|
} else {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search standard API
|
* search standard API
|
||||||
* @param object $lesson a lesson instance (by ref)
|
* @uses $DB
|
||||||
|
* @param reference $lesson a lesson instance (by ref)
|
||||||
* @return an array of searchable documents
|
* @return an array of searchable documents
|
||||||
*/
|
*/
|
||||||
function lesson_get_content_for_index(&$lesson) {
|
function lesson_get_content_for_index(&$lesson) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
$documents = array();
|
$documents = array();
|
||||||
if (!$lesson) return $documents;
|
if (!$lesson) return $documents;
|
||||||
|
|
||||||
$pages = get_records('lesson_pages', 'lessonid', $lesson->id);
|
$pages = $DB->get_records('lesson_pages', array('lessonid' => $lesson->id));
|
||||||
if ($pages){
|
if ($pages){
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'lesson');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'lesson'));
|
||||||
$cm = get_record('course_modules', 'course', $lesson->course, 'module', $coursemodule, 'instance', $lesson->id);
|
$cm = $DB->get_record('course_modules', array('course' => $lesson->course, 'module' => $coursemodule, 'instance' => $lesson->id));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
foreach($pages as $aPage){
|
foreach($pages as $aPage){
|
||||||
$documents[] = new LessonPageSearchDocument(get_object_vars($aPage), $cm->id, $lesson->course, 'page', $context->id);
|
$documents[] = new LessonPageSearchDocument(get_object_vars($aPage), $cm->id, $lesson->course, 'page', $context->id);
|
||||||
|
@ -102,16 +112,18 @@ function lesson_get_content_for_index(&$lesson) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a single lesson search document based on a lesson page id
|
* returns a single lesson search document based on a lesson page id
|
||||||
|
* @uses $DB
|
||||||
* @param int $id an id for a single information item
|
* @param int $id an id for a single information item
|
||||||
* @param string $itemtype the type of information
|
* @param string $itemtype the type of information
|
||||||
*/
|
*/
|
||||||
function lesson_single_document($id, $itemtype) {
|
function lesson_single_document($id, $itemtype) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
// only page is known yet
|
// only page is known yet
|
||||||
$page = get_record('lesson_pages', 'id', $id);
|
$page = $DB->get_record('lesson_pages', array('id' => $id));
|
||||||
$lesson = get_record('lesson', 'id', $page->lessonid);
|
$lesson = $DB->get_record('lesson', array('id' => $page->lessonid));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'lesson');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'lesson'));
|
||||||
$cm = get_record('course_modules', 'course', $lesson->course, 'module', $coursemodule, 'instance', $page->lessonid);
|
$cm = $DB->get_record('course_modules', array('course' => $lesson->course, 'module' => $coursemodule, 'instance' => $page->lessonid));
|
||||||
if ($cm){
|
if ($cm){
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
$lesson->groupid = 0;
|
$lesson->groupid = 0;
|
||||||
|
@ -156,22 +168,19 @@ function lesson_db_names() {
|
||||||
* @param object $user the user record denoting the user who searches
|
* @param object $user the user record denoting the user who searches
|
||||||
* @param int $group_id the current group used by the user when searching
|
* @param int $group_id the current group used by the user when searching
|
||||||
* @param int $context_id the id of the context used when indexing
|
* @param int $context_id the id of the context used when indexing
|
||||||
* @uses CFG, USER
|
* @uses $CFG, $USER, $DB
|
||||||
* @return true if access is allowed, false elsewhere
|
* @return true if access is allowed, false elsewhere
|
||||||
*/
|
*/
|
||||||
function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
global $CFG, $USER;
|
global $CFG, $USER, $DB;
|
||||||
|
|
||||||
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
||||||
|
|
||||||
// get the lesson page
|
// get the lesson page
|
||||||
$page = get_record('lesson_pages', 'id', $this_id);
|
$page = $DB->get_record('lesson_pages', array('id' => $this_id));
|
||||||
$lesson = get_record('lesson', 'id', $page->lessonid);
|
$lesson = $DB->get_record('lesson', array('id' => $page->lessonid));
|
||||||
$context = get_record('context', 'id', $context_id);
|
$context = $DB->get_record('context', array('id' => $context_id));
|
||||||
$cm = get_record('course_modules', 'id', $context->instanceid);
|
$cm = $DB->get_record('course_modules', array('id' => $context->instanceid));
|
||||||
// $lesson = get_record('lesson', 'id', $page->lessonid);
|
|
||||||
// $cm = get_coursemodule_from_instance('lesson', $page->lessonid, $lesson->course);
|
|
||||||
// $context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
||||||
|
|
||||||
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
|
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
|
||||||
if (!empty($CFG->search_access_debug)) echo "search reject : hidden lesson ";
|
if (!empty($CFG->search_access_debug)) echo "search reject : hidden lesson ";
|
||||||
|
@ -210,7 +219,12 @@ function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function lesson_link_post_processing($title){
|
function lesson_link_post_processing($title){
|
||||||
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
global $CFG;
|
||||||
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
|
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version revised for Moodle 2.0
|
||||||
*
|
*
|
||||||
* this is a format handler for getting text out of a proprietary binary format
|
* this is a format handler for getting text out of a proprietary binary format
|
||||||
* so it can be indexed by Lucene search engine
|
* so it can be indexed by Lucene search engine
|
||||||
|
@ -15,7 +16,8 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MS Word extractor
|
* MS Word extractor
|
||||||
* @param object $resource
|
* @param object $resource
|
||||||
|
* @param string $directfile if the resource is given as a direct file path, use it as reference to the file
|
||||||
* @uses $CFG
|
* @uses $CFG
|
||||||
*/
|
*/
|
||||||
function get_text_for_indexing_doc(&$resource, $directfile = ''){
|
function get_text_for_indexing_doc(&$resource, $directfile = ''){
|
||||||
|
@ -24,7 +26,12 @@ function get_text_for_indexing_doc(&$resource, $directfile = ''){
|
||||||
// SECURITY : do not allow non admin execute anything on system !!
|
// SECURITY : do not allow non admin execute anything on system !!
|
||||||
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
||||||
|
|
||||||
$moodleroot = (@$CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ;
|
// adds moodle root switch if none was defined
|
||||||
|
if (!isset($CFG->block_search_usemoodleroot)){
|
||||||
|
set_config('block_search_usemoodleroot', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$moodleroot = ($CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ;
|
||||||
|
|
||||||
// just call pdftotext over stdout and capture the output
|
// just call pdftotext over stdout and capture the output
|
||||||
if (!empty($CFG->block_search_word_to_text_cmd)){
|
if (!empty($CFG->block_search_word_to_text_cmd)){
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version revised for Moodle 2.0
|
||||||
*
|
*
|
||||||
* this is a format handler for getting text out of a proprietary binary format
|
* this is a format handler for getting text out of a proprietary binary format
|
||||||
* so it can be indexed by Lucene search engine
|
* so it can be indexed by Lucene search engine
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $resource
|
* @param object $resource
|
||||||
|
* @param string $directfile if the resource is given as a direct file path, use it as reference to the file
|
||||||
* @uses $CFG
|
* @uses $CFG
|
||||||
*/
|
*/
|
||||||
function get_text_for_indexing_htm(&$resource, $directfile = ''){
|
function get_text_for_indexing_htm(&$resource, $directfile = ''){
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version revised for Moodle 2.0
|
||||||
*
|
*
|
||||||
* this is a format handler for getting text out of a standard html format
|
* this is a format handler for getting text out of a standard html format
|
||||||
* so it can be indexed by Lucene search engine
|
* so it can be indexed by Lucene search engine
|
||||||
|
|
62
search/documents/physical_odt.php
Normal file
62
search/documents/physical_odt.php
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Global Search Engine for Moodle
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* @version revised for Moodle 2.0
|
||||||
|
*
|
||||||
|
* this is a format handler for getting text out of the opensource ODT binary format
|
||||||
|
* so it can be indexed by Lucene search engine
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OpenOffice Odt extractor
|
||||||
|
* @param object $resource
|
||||||
|
* @param string $directfile if the resource is given as a direct file path, use it as reference to the file
|
||||||
|
* @uses $CFG
|
||||||
|
*/
|
||||||
|
function get_text_for_indexing_odt(&$resource, $directfile = ''){
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
// SECURITY : do not allow non admin execute anything on system !!
|
||||||
|
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
||||||
|
|
||||||
|
// adds moodle root switch if none was defined
|
||||||
|
if (!isset($CFG->block_search_usemoodleroot)){
|
||||||
|
set_config('block_search_usemoodleroot', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$moodleroot = ($CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ;
|
||||||
|
|
||||||
|
// just call pdftotext over stdout and capture the output
|
||||||
|
if (!empty($CFG->block_search_odt_to_text_cmd)){
|
||||||
|
if (!file_exists("{$moodleroot}{$CFG->block_search_odt_to_text_cmd}")){
|
||||||
|
mtrace('Error with OpenOffice ODT to text converter command : exectuable not found.');
|
||||||
|
} else {
|
||||||
|
if ($directfile == ''){
|
||||||
|
$file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
|
||||||
|
} else {
|
||||||
|
$file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
|
||||||
|
}
|
||||||
|
$command = trim($CFG->block_search_odt_to_text_cmd);
|
||||||
|
$text_converter_cmd = "{$moodleroot}{$command} --encoding=UTF-8 $file";
|
||||||
|
mtrace("Executing : $text_converter_cmd");
|
||||||
|
$result = shell_exec($text_converter_cmd);
|
||||||
|
if ($result){
|
||||||
|
return $result;
|
||||||
|
} else {
|
||||||
|
mtrace('Error with OpenOffice ODT to text converter command : execution failed. ');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mtrace('Error with OpenOffice ODT to text converter command : command not set up. Execute once search block configuration.');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version revised for Moodle 2.0
|
||||||
*
|
*
|
||||||
* this is a format handler for getting text out of a proprietary binary format
|
* this is a format handler for getting text out of a proprietary binary format
|
||||||
* so it can be indexed by Lucene search engine
|
* so it can be indexed by Lucene search engine
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $resource
|
* @param object $resource
|
||||||
|
* @param string $directfile if the resource is given as a direct file path, use it as reference to the file
|
||||||
* @uses $CFG
|
* @uses $CFG
|
||||||
*/
|
*/
|
||||||
function get_text_for_indexing_pdf(&$resource, $directfile = ''){
|
function get_text_for_indexing_pdf(&$resource, $directfile = ''){
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version revised for Moodle 2.0
|
||||||
*
|
*
|
||||||
* this is a format handler for getting text out of a proprietary binary format
|
* this is a format handler for getting text out of a proprietary binary format
|
||||||
* so it can be indexed by Lucene search engine
|
* so it can be indexed by Lucene search engine
|
||||||
|
@ -29,6 +30,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $resource
|
* @param object $resource
|
||||||
|
* @param string $directfile if the resource is given as a direct file path, use it as reference to the file
|
||||||
* @uses $CFG
|
* @uses $CFG
|
||||||
*/
|
*/
|
||||||
function get_text_for_indexing_ppt(&$resource, $directfile = ''){
|
function get_text_for_indexing_ppt(&$resource, $directfile = ''){
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version revised for Moodle 2.0
|
||||||
*
|
*
|
||||||
* @note : The Adobe SWF Converters library is not GPL, although it can be of free use in some
|
* @note : The Adobe SWF Converters library is not GPL, although it can be of free use in some
|
||||||
* situations. This file is provided for convenience, but should use having a glance at
|
* situations. This file is provided for convenience, but should use having a glance at
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $resource
|
* @param object $resource
|
||||||
|
* @param string $directfile if the resource is given as a direct file path, use it as reference to the file
|
||||||
* @uses $CFG
|
* @uses $CFG
|
||||||
*/
|
*/
|
||||||
function get_text_for_indexing_swf(&$resource, $directfile = ''){
|
function get_text_for_indexing_swf(&$resource, $directfile = ''){
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version revised for Moodle 2.0
|
||||||
*
|
*
|
||||||
* this is a format handler for getting text out of a proprietary binary format
|
* this is a format handler for getting text out of a proprietary binary format
|
||||||
* so it can be indexed by Lucene search engine
|
* so it can be indexed by Lucene search engine
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $resource
|
* @param object $resource
|
||||||
|
* @param string $directfile if the resource is given as a direct file path, use it as reference to the file
|
||||||
* @uses $CFG
|
* @uses $CFG
|
||||||
*/
|
*/
|
||||||
function get_text_for_indexing_txt(&$resource, $directfile = ''){
|
function get_text_for_indexing_txt(&$resource, $directfile = ''){
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version revised for Moodle 2.0
|
||||||
*
|
*
|
||||||
* this is a format handler for getting text out of a proprietary binary format
|
* this is a format handler for getting text out of a proprietary binary format
|
||||||
* so it can be indexed by Lucene search engine
|
* so it can be indexed by Lucene search engine
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $resource
|
* @param object $resource
|
||||||
|
* @param string $directfile if the resource is given as a direct file path, use it as reference to the file
|
||||||
* @uses $CFG
|
* @uses $CFG
|
||||||
*/
|
*/
|
||||||
function get_text_for_indexing_xml(&$resource, $directfile = ''){
|
function get_text_for_indexing_xml(&$resource, $directfile = ''){
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
*
|
*
|
||||||
* document handling for all resources
|
* document handling for all resources
|
||||||
* This file contains the mapping between a resource and it's indexable counterpart,
|
* This file contains the mapping between a resource and it's indexable counterpart,
|
||||||
|
@ -19,8 +20,8 @@
|
||||||
/**
|
/**
|
||||||
* requires and includes
|
* requires and includes
|
||||||
*/
|
*/
|
||||||
require_once("$CFG->dirroot/search/documents/document.php");
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
require_once("$CFG->dirroot/mod/resource/lib.php");
|
require_once($CFG->dirroot.'/mod/resource/lib.php');
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
* a class for representing searchable information
|
* a class for representing searchable information
|
||||||
|
@ -45,8 +46,8 @@ class ResourceSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
// construct the parent class
|
// construct the parent class
|
||||||
parent::__construct($doc, $data, $resource['course'], 0, 0, 'mod/'.SEARCH_TYPE_RESOURCE);
|
parent::__construct($doc, $data, $resource['course'], 0, 0, 'mod/'.SEARCH_TYPE_RESOURCE);
|
||||||
} //constructor
|
}
|
||||||
} //ResourceSearchDocument
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructs valid access links to information
|
* constructs valid access links to information
|
||||||
|
@ -57,7 +58,7 @@ function resource_make_link($resource_id) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
return $CFG->wwwroot.'/mod/resource/view.php?id='.$resource_id;
|
return $CFG->wwwroot.'/mod/resource/view.php?id='.$resource_id;
|
||||||
} //resource_make_link
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of standard API
|
* part of standard API
|
||||||
|
@ -68,18 +69,18 @@ function resource_iterator() {
|
||||||
//this document to only use the below function to return info
|
//this document to only use the below function to return info
|
||||||
//to be searched
|
//to be searched
|
||||||
return array(true);
|
return array(true);
|
||||||
} //resource_iterator
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of standard API
|
* part of standard API
|
||||||
* this function does not need a content iterator, returns all the info
|
* this function does not need a content iterator, returns all the info
|
||||||
* itself;
|
* itself;
|
||||||
* @param notneeded to comply API, remember to fake the iterator array though
|
* @param void $notneeded to comply API, remember to fake the iterator array though
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
* @return an array of searchable documents
|
* @return an array of searchable documents
|
||||||
*/
|
*/
|
||||||
function resource_get_content_for_index(&$notneeded) {
|
function resource_get_content_for_index(&$notneeded) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// starting with Moodle native resources
|
// starting with Moodle native resources
|
||||||
$documents = array();
|
$documents = array();
|
||||||
|
@ -88,22 +89,22 @@ function resource_get_content_for_index(&$notneeded) {
|
||||||
id as trueid,
|
id as trueid,
|
||||||
r.*
|
r.*
|
||||||
FROM
|
FROM
|
||||||
{resource} as r
|
{resource} r
|
||||||
WHERE
|
WHERE
|
||||||
alltext != '' AND
|
alltext != '' AND
|
||||||
alltext != ' ' AND
|
alltext != ' ' AND
|
||||||
alltext != ' ' AND
|
alltext != ' ' AND
|
||||||
type != 'file'
|
type != 'file'
|
||||||
";
|
";
|
||||||
$resources = get_records_sql($query);
|
if ($resources = $DB->get_records_sql($query)){
|
||||||
|
foreach($resources as $aResource){
|
||||||
foreach($resources as $aResource){
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'resource'));
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'resource');
|
$cm = $DB->get_record('course_modules', array('course' => $aResource->course, 'module' => $coursemodule, 'instance' => $aResource->id));
|
||||||
$cm = get_record('course_modules', 'course', $aResource->course, 'module', $coursemodule, 'instance', $aResource->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$aResource->id = $cm->id;
|
||||||
$aResource->id = $cm->id;
|
$documents[] = new ResourceSearchDocument(get_object_vars($aResource), $context->id);
|
||||||
$documents[] = new ResourceSearchDocument(get_object_vars($aResource), $context->id);
|
mtrace("finished $aResource->name");
|
||||||
mtrace("finished $aResource->name");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// special physical files handling
|
// special physical files handling
|
||||||
|
@ -125,9 +126,9 @@ function resource_get_content_for_index(&$notneeded) {
|
||||||
r.type as type,
|
r.type as type,
|
||||||
r.timemodified as timemodified
|
r.timemodified as timemodified
|
||||||
FROM
|
FROM
|
||||||
{resource} as r,
|
{resource} r,
|
||||||
{course_modules} as cm,
|
{course_modules} cm,
|
||||||
{modules} as m
|
{modules} m
|
||||||
WHERE
|
WHERE
|
||||||
r.type = 'file' AND
|
r.type = 'file' AND
|
||||||
cm.instance = r.id AND
|
cm.instance = r.id AND
|
||||||
|
@ -135,28 +136,28 @@ function resource_get_content_for_index(&$notneeded) {
|
||||||
cm.module = m.id AND
|
cm.module = m.id AND
|
||||||
m.name = 'resource'
|
m.name = 'resource'
|
||||||
";
|
";
|
||||||
$resources = get_records_sql($query);
|
if ($resources = $DB->get_records_sql($query)){
|
||||||
|
|
||||||
// invokes external content extractor if exists.
|
// invokes external content extractor if exists.
|
||||||
if ($resources){
|
|
||||||
foreach($resources as $aResource){
|
foreach($resources as $aResource){
|
||||||
// fetches a physical indexable document and adds it to documents passed by ref
|
// fetches a physical indexable document and adds it to documents passed by ref
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'resource');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'resource'));
|
||||||
$cm = get_record('course_modules', 'id', $aResource->id);
|
$cm = $DB->get_record('course_modules', array('id' => $aResource->id));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
resource_get_physical_file($aResource, $context->id, false, $documents);
|
resource_get_physical_file($aResource, $context->id, false, $documents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $documents;
|
return $documents;
|
||||||
} //resource_get_content_for_index
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get text from a physical file
|
* get text from a physical file
|
||||||
* @param resource a resource for which to fetch some representative text
|
* @uses $CFG
|
||||||
* @param getsingle if true, returns a single search document, elsewhere return the array
|
* @param reference $resource a resource for which to fetch some representative text
|
||||||
|
* @param int $context_id the context associated with the resource
|
||||||
|
* @param bool $getsingle if true, returns a single search document, elsewhere return the array
|
||||||
* given as documents increased by one
|
* given as documents increased by one
|
||||||
* @param documents the array of documents, by ref, where to add the new document.
|
* @param array $documents the array of documents, by ref, where to add the new document.
|
||||||
* @return a search document when unique or false.
|
* @return a search document when unique or false.
|
||||||
*/
|
*/
|
||||||
function resource_get_physical_file(&$resource, $context_id, $getsingle, &$documents = null){
|
function resource_get_physical_file(&$resource, $context_id, $getsingle, &$documents = null){
|
||||||
|
@ -218,11 +219,12 @@ function resource_get_physical_file(&$resource, $context_id, $getsingle, &$docum
|
||||||
/**
|
/**
|
||||||
* part of standard API.
|
* part of standard API.
|
||||||
* returns a single resource search document based on a resource_entry id
|
* returns a single resource search document based on a resource_entry id
|
||||||
|
* @uses $CFG, $DB
|
||||||
* @param id the id of the accessible document
|
* @param id the id of the accessible document
|
||||||
* @return a searchable object or null if failure
|
* @return a searchable object or null if failure
|
||||||
*/
|
*/
|
||||||
function resource_single_document($id, $itemtype) {
|
function resource_single_document($id, $itemtype) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// rewriting with legacy moodle databse API
|
// rewriting with legacy moodle databse API
|
||||||
$query = "
|
$query = "
|
||||||
|
@ -237,9 +239,9 @@ function resource_single_document($id, $itemtype) {
|
||||||
r.type as type,
|
r.type as type,
|
||||||
r.timemodified as timemodified
|
r.timemodified as timemodified
|
||||||
FROM
|
FROM
|
||||||
{resource} as r,
|
{resource} r,
|
||||||
{course_modules} as cm,
|
{course_modules} cm,
|
||||||
{modules} as m
|
{modules} m
|
||||||
WHERE
|
WHERE
|
||||||
cm.instance = r.id AND
|
cm.instance = r.id AND
|
||||||
cm.course = r.course AND
|
cm.course = r.course AND
|
||||||
|
@ -250,13 +252,13 @@ function resource_single_document($id, $itemtype) {
|
||||||
r.alltext != ' ' AND
|
r.alltext != ' ' AND
|
||||||
r.alltext != ' ') OR
|
r.alltext != ' ') OR
|
||||||
r.type = 'file') AND
|
r.type = 'file') AND
|
||||||
r.id = '{$id}'
|
r.id = '?'
|
||||||
";
|
";
|
||||||
$resource = get_record_sql($query);
|
$resource = $DB->get_record_sql($query, array($id));
|
||||||
|
|
||||||
if ($resource){
|
if ($resource){
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'resource');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'resource'));
|
||||||
$cm = get_record('course_modules', 'id', $resource->id);
|
$cm = $DB->get_record('course_modules', array('id' => $resource->id));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
if ($resource->type == 'file' && @$CFG->block_search_enable_file_indexing){
|
if ($resource->type == 'file' && @$CFG->block_search_enable_file_indexing){
|
||||||
$document = resource_get_physical_file($resource, true, $context->id);
|
$document = resource_get_physical_file($resource, true, $context->id);
|
||||||
|
@ -266,9 +268,9 @@ function resource_single_document($id, $itemtype) {
|
||||||
return new ResourceSearchDocument(get_object_vars($resource), $context->id);
|
return new ResourceSearchDocument(get_object_vars($resource), $context->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mtrace("null resource");
|
mtrace('null resource');
|
||||||
return null;
|
return null;
|
||||||
} //resource_single_document
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dummy delete function that aggregates id with itemtype.
|
* dummy delete function that aggregates id with itemtype.
|
||||||
|
@ -279,7 +281,7 @@ function resource_delete($info, $itemtype) {
|
||||||
$object->id = $info;
|
$object->id = $info;
|
||||||
$object->itemtype = $itemtype;
|
$object->itemtype = $itemtype;
|
||||||
return $object;
|
return $object;
|
||||||
} //resource_delete
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the var names needed to build a sql query for addition/deletions
|
* returns the var names needed to build a sql query for addition/deletions
|
||||||
|
@ -288,11 +290,12 @@ function resource_delete($info, $itemtype) {
|
||||||
function resource_db_names() {
|
function resource_db_names() {
|
||||||
//[primary id], [table name], [time created field name], [time modified field name], [additional where conditions for sql]
|
//[primary id], [table name], [time created field name], [time modified field name], [additional where conditions for sql]
|
||||||
return array(array('id', 'resource', 'timemodified', 'timemodified', 'any', " (alltext != '' AND alltext != ' ' AND alltext != ' ' AND TYPE != 'file') OR TYPE = 'file' "));
|
return array(array('id', 'resource', 'timemodified', 'timemodified', 'any', " (alltext != '' AND alltext != ' ' AND alltext != ' ' AND TYPE != 'file') OR TYPE = 'file' "));
|
||||||
} //resource_db_names
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this function handles the access policy to contents indexed as searchable documents. If this
|
* this function handles the access policy to contents indexed as searchable documents. If this
|
||||||
* function does not exist, the search engine assumes access is allowed.
|
* function does not exist, the search engine assumes access is allowed.
|
||||||
|
* @uses $CFG, $DB
|
||||||
* @param path the access path to the module script code
|
* @param path the access path to the module script code
|
||||||
* @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
* @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
||||||
* @param this_id the item id within the information class denoted by itemtype. In resources, this id
|
* @param this_id the item id within the information class denoted by itemtype. In resources, this id
|
||||||
|
@ -302,13 +305,26 @@ function resource_db_names() {
|
||||||
* @return true if access is allowed, false elsewhere
|
* @return true if access is allowed, false elsewhere
|
||||||
*/
|
*/
|
||||||
function resource_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
function resource_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
// include_once("{$CFG->dirroot}/{$path}/lib.php");
|
||||||
|
|
||||||
$r = get_record('resource', 'id', $this_id);
|
$r = $DB->get_record('resource', array('id' => $this_id));
|
||||||
$module_context = get_record('context', 'id', $context_id);
|
$module_context = $DB->get_record('context', array('id' => $context_id));
|
||||||
$cm = get_record('course_modules', 'id', $module_context->instanceid);
|
$cm = $DB->get_record('course_modules', array('id' => $module_context->instanceid));
|
||||||
|
$course = $DB->get_record('course', array('id' => $r->course));
|
||||||
|
$course_context = get_context_instance(CONTEXT_COURSE, $r->course);
|
||||||
|
|
||||||
|
//check if course is visible
|
||||||
|
if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $course_context)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check if user is registered in course or course is open to guests
|
||||||
|
if (!$course->guest && !has_capability('moodle/course:view', $course_context)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//check if found course module is visible
|
//check if found course module is visible
|
||||||
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)){
|
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)){
|
||||||
|
@ -323,7 +339,11 @@ function resource_check_text_access($path, $itemtype, $this_id, $user, $group_id
|
||||||
* @param string $title
|
* @param string $title
|
||||||
*/
|
*/
|
||||||
function resource_link_post_processing($title){
|
function resource_link_post_processing($title){
|
||||||
// return mb_convert_encoding($title, 'UTF-8', 'auto');
|
global $CFG;
|
||||||
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
*
|
*
|
||||||
* special (EXTRA) document handling for user related data
|
* special (EXTRA) document handling for user related data
|
||||||
*
|
*
|
||||||
|
@ -16,8 +17,8 @@
|
||||||
/**
|
/**
|
||||||
* includes and requires
|
* includes and requires
|
||||||
*/
|
*/
|
||||||
require_once("$CFG->dirroot/search/documents/document.php");
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
require_once("$CFG->dirroot/blog/lib.php");
|
require_once($CFG->dirroot.'/blog/lib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a class for representing searchable information in user metadata
|
* a class for representing searchable information in user metadata
|
||||||
|
@ -27,8 +28,10 @@ class UserSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
|
* @uses $DB
|
||||||
*/
|
*/
|
||||||
public function __construct(&$userhash, $user_id, $context_id) {
|
public function __construct(&$userhash, $user_id, $context_id) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
// generic information; required
|
// generic information; required
|
||||||
$doc->docid = $userhash['id'];
|
$doc->docid = $userhash['id'];
|
||||||
|
@ -36,12 +39,12 @@ class UserSearchDocument extends SearchDocument {
|
||||||
$doc->itemtype = 'user';
|
$doc->itemtype = 'user';
|
||||||
$doc->contextid = $context_id;
|
$doc->contextid = $context_id;
|
||||||
|
|
||||||
$user = get_record('user', 'id', $user_id);
|
$user = $DB->get_record('user', array('id' => $user_id));
|
||||||
$doc->title = get_string('user').': '.fullname($user);
|
$doc->title = get_string('user').': '.fullname($user);
|
||||||
$doc->date = ($userhash['lastaccess']) ? $userhash['lastaccess'] : time() ;
|
$doc->date = ($userhash['lastaccess']) ? $userhash['lastaccess'] : time() ;
|
||||||
|
|
||||||
//remove '(ip.ip.ip.ip)' from chat author list
|
//remove '(ip.ip.ip.ip)' from chat author list
|
||||||
$doc->author = '';
|
$doc->author = $user->id;
|
||||||
$doc->contents = $userhash['description'];
|
$doc->contents = $userhash['description'];
|
||||||
$doc->url = user_make_link($user_id, 'user');
|
$doc->url = user_make_link($user_id, 'user');
|
||||||
|
|
||||||
|
@ -60,15 +63,18 @@ class UserPostSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
|
* @uses $DB
|
||||||
*/
|
*/
|
||||||
public function __construct(&$post, $user_id, $context_id) {
|
public function __construct(&$post, $user_id, $context_id) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
// generic information; required
|
// generic information; required
|
||||||
$doc->docid = $post['id'];
|
$doc->docid = $post['id'];
|
||||||
$doc->documenttype = SEARCH_TYPE_USER;
|
$doc->documenttype = SEARCH_TYPE_USER;
|
||||||
$doc->itemtype = 'post';
|
$doc->itemtype = 'post';
|
||||||
$doc->contextid = $context_id;
|
$doc->contextid = $context_id;
|
||||||
|
|
||||||
$user = get_record('user', 'id', $user_id);
|
$user = $DB->get_record('user', array('id' => $user_id));
|
||||||
|
|
||||||
// we cannot call userdate with relevant locale at indexing time.
|
// we cannot call userdate with relevant locale at indexing time.
|
||||||
$doc->title = get_string('post').': '.fullname($user);
|
$doc->title = get_string('post').': '.fullname($user);
|
||||||
|
@ -94,15 +100,18 @@ class UserBlogAttachmentSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
|
* @uses $DB
|
||||||
*/
|
*/
|
||||||
public function __construct(&$post, $context_id) {
|
public function __construct(&$post, $context_id) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
// generic information; required
|
// generic information; required
|
||||||
$doc->docid = $post['id'];
|
$doc->docid = $post['id'];
|
||||||
$doc->documenttype = SEARCH_TYPE_USER;
|
$doc->documenttype = SEARCH_TYPE_USER;
|
||||||
$doc->itemtype = 'attachment';
|
$doc->itemtype = 'attachment';
|
||||||
$doc->contextid = $context_id;
|
$doc->contextid = $context_id;
|
||||||
|
|
||||||
$user = get_record('user', 'id', $post['userid']);
|
$user = $DB->get_record('user', 'id', $post['userid']);
|
||||||
|
|
||||||
// we cannot call userdate with relevant locale at indexing time.
|
// we cannot call userdate with relevant locale at indexing time.
|
||||||
$doc->title = get_string('file').' : '.$post['subject'];
|
$doc->title = get_string('file').' : '.$post['subject'];
|
||||||
|
@ -123,20 +132,20 @@ class UserBlogAttachmentSearchDocument extends SearchDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructs a valid link to a user record
|
* constructs a valid link to a user record
|
||||||
* @param userid the user
|
* @param int $userid the user
|
||||||
* @param itemtype
|
* @param string $itemtype
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
* @return a well formed link to user information
|
* @return a well formed link to user information
|
||||||
*/
|
*/
|
||||||
function user_make_link($itemid, $itemtype) {
|
function user_make_link($itemid, $itemtype) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
if ($itemtype == 'user'){
|
if ($itemtype == 'user'){
|
||||||
return $CFG->wwwroot.'/user/view.php?id='.$itemid;
|
return $CFG->wwwroot.'/user/view.php?id='.$itemid;
|
||||||
} elseif ($itemtype == 'post') {
|
} elseif ($itemtype == 'post') {
|
||||||
return $CFG->wwwroot.'/blog/index.php?userid='.$itemid;
|
return $CFG->wwwroot.'/blog/index.php?userid='.$itemid;
|
||||||
} elseif ($itemtype == 'attachment') {
|
} elseif ($itemtype == 'attachment') {
|
||||||
$post = get_record('post', 'id', $itemid);
|
$post = $DB->get_record('post', array('id' => $itemid));
|
||||||
if (!$CFG->slasharguments){
|
if (!$CFG->slasharguments){
|
||||||
return $CFG->wwwroot."/file.php?file=/blog/attachments/{$post->id}/{$post->attachment}";
|
return $CFG->wwwroot."/file.php?file=/blog/attachments/{$post->id}/{$post->attachment}";
|
||||||
} else {
|
} else {
|
||||||
|
@ -149,33 +158,37 @@ function user_make_link($itemid, $itemtype) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
|
* @uses $DB
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function user_iterator() {
|
function user_iterator() {
|
||||||
$users = get_records('user');
|
global $DB;
|
||||||
|
|
||||||
|
$users = $DB->get_records('user');
|
||||||
return $users;
|
return $users;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
|
* @param reference $user a user record
|
||||||
* @return an array of documents generated from data
|
* @return an array of documents generated from data
|
||||||
*/
|
*/
|
||||||
function user_get_content_for_index(&$user) {
|
function user_get_content_for_index(&$user) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$documents = array();
|
$documents = array();
|
||||||
|
|
||||||
$userhash = get_object_vars($user);
|
$userhash = get_object_vars($user);
|
||||||
$documents[] = new UserSearchDocument($userhash, $user->id, null);
|
$documents[] = new UserSearchDocument($userhash, $user->id, null);
|
||||||
|
|
||||||
if ($posts = get_records('post', 'userid', $user->id, 'created')){
|
if ($posts = $DB->get_records('post', array('userid' => $user->id), 'created')){
|
||||||
foreach($posts as $post){
|
foreach($posts as $post){
|
||||||
$texts = array();
|
$texts = array();
|
||||||
$texts[] = $post->subject;
|
$texts[] = $post->subject;
|
||||||
$texts[] = $post->summary;
|
$texts[] = $post->summary;
|
||||||
$texts[] = $post->content;
|
$texts[] = $post->content;
|
||||||
$post->description = implode(" ", $texts);
|
$post->description = implode(' ', $texts);
|
||||||
|
|
||||||
// record the attachment if any and physical files can be indexed
|
// record the attachment if any and physical files can be indexed
|
||||||
if (@$CFG->block_search_enable_file_indexing){
|
if (@$CFG->block_search_enable_file_indexing){
|
||||||
|
@ -193,6 +206,7 @@ function user_get_content_for_index(&$user) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get text from a physical file
|
* get text from a physical file
|
||||||
|
* @uses $CFG
|
||||||
* @param object $post a post to whech the file is attached to
|
* @param object $post a post to whech the file is attached to
|
||||||
* @param boolean $context_id if in future we need recording a context along with the search document, pass it here
|
* @param boolean $context_id if in future we need recording a context along with the search document, pass it here
|
||||||
* @param boolean $getsingle if true, returns a single search document, elsewhere return the array
|
* @param boolean $getsingle if true, returns a single search document, elsewhere return the array
|
||||||
|
@ -254,18 +268,21 @@ function user_get_physical_file(&$post, $context_id, $getsingle, &$documents = n
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a single user search document
|
* returns a single user search document
|
||||||
|
* @uses $DB
|
||||||
* @param composite $id a unique document id made with
|
* @param composite $id a unique document id made with
|
||||||
* @param itemtype the type of information (session is the only type)
|
* @param itemtype the type of information (session is the only type)
|
||||||
*/
|
*/
|
||||||
function user_single_document($id, $itemtype) {
|
function user_single_document($id, $itemtype) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
if ($itemtype == 'user'){
|
if ($itemtype == 'user'){
|
||||||
if ($user = get_record('user', 'id', $id)){
|
if ($user = $DB->get_record('user', array('id' => $id))){
|
||||||
$userhash = get_object_vars($user);
|
$userhash = get_object_vars($user);
|
||||||
return new UserSearchDocument($userhash, $user->id, 'user', null);
|
return new UserSearchDocument($userhash, $user->id, 'user', null);
|
||||||
}
|
}
|
||||||
} elseif ($itemtype == 'post') {
|
} elseif ($itemtype == 'post') {
|
||||||
if ($post = get_records('post', 'id', $id)){
|
if ($post = $DB->get_records('post', array('id' => $id))){
|
||||||
$texts = array();
|
$texts = array();
|
||||||
$texts[] = $post->subject;
|
$texts[] = $post->subject;
|
||||||
$texts[] = $post->summary;
|
$texts[] = $post->summary;
|
||||||
|
@ -275,7 +292,7 @@ function user_single_document($id, $itemtype) {
|
||||||
return new UserPostSearchDocument($posthash, $user->id, 'post', null);
|
return new UserPostSearchDocument($posthash, $user->id, 'post', null);
|
||||||
}
|
}
|
||||||
} elseif ($itemtype == 'attachment' && @$CFG->block_search_enable_file_indexing) {
|
} elseif ($itemtype == 'attachment' && @$CFG->block_search_enable_file_indexing) {
|
||||||
if ($post = get_records('post', 'id', $id)){
|
if ($post = $DB->get_records('post', array('id' => $id))){
|
||||||
if ($post->attachment){
|
if ($post->attachment){
|
||||||
return user_get_physical_file($post, null, true);
|
return user_get_physical_file($post, null, true);
|
||||||
}
|
}
|
||||||
|
@ -315,23 +332,23 @@ function user_db_names() {
|
||||||
* - user is legitimate in the surrounding context
|
* - user is legitimate in the surrounding context
|
||||||
* - user may be guest and guest access is allowed to the module
|
* - user may be guest and guest access is allowed to the module
|
||||||
* - the function may perform local checks within the module information logic
|
* - the function may perform local checks within the module information logic
|
||||||
* @param path the access path to the module script code
|
* @param string $path the access path to the module script code
|
||||||
* @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
* @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
||||||
* @param this_id the item id within the information class denoted by entry_type. In chats, this id
|
* @param int $this_id the item id within the information class denoted by entry_type. In chats, this id
|
||||||
* points out a session history which is a close sequence of messages.
|
* points out a session history which is a close sequence of messages.
|
||||||
* @param user the user record denoting the user who searches
|
* @param object $user the user record denoting the user who searches
|
||||||
* @param group_id the current group used by the user when searching
|
* @param int $group_id the current group used by the user when searching
|
||||||
* @uses CFG
|
* @uses $CFG, $DB
|
||||||
* @return true if access is allowed, false elsewhere
|
* @return true if access is allowed, false elsewhere
|
||||||
*/
|
*/
|
||||||
function user_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
function user_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
include_once("{$CFG->dirroot}/{$path}/lib.php");
|
||||||
|
|
||||||
if ($itemtype == 'user'){
|
if ($itemtype == 'user'){
|
||||||
// get the user
|
// get the user
|
||||||
$userrecord = get_record('user', 'id', $this_id);
|
$userrecord = $DB->get_record('user', array('id' => $this_id));
|
||||||
|
|
||||||
// we cannot see nothing from unconfirmed users
|
// we cannot see nothing from unconfirmed users
|
||||||
if (!$userrecord->confirmed and !has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))){
|
if (!$userrecord->confirmed and !has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))){
|
||||||
|
@ -340,13 +357,13 @@ function user_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
|
||||||
}
|
}
|
||||||
} elseif ($itemtype == 'post' || $itemtype == 'attachment'){
|
} elseif ($itemtype == 'post' || $itemtype == 'attachment'){
|
||||||
// get the post
|
// get the post
|
||||||
$post = get_record('post', 'id', $this_id);
|
$post = $DB->get_record('post', array('id' => $this_id));
|
||||||
$userrecord = get_record('user', 'id', $post->userid);
|
$userrecord = $DB->get_record('user', array('id' => $post->userid));
|
||||||
|
|
||||||
// we can try using blog visibility check
|
// we can try using blog visibility check
|
||||||
return blog_user_can_view_user_post($user->id, $post);
|
return blog_user_can_view_user_post($user->id, $post);
|
||||||
}
|
}
|
||||||
$context = get_record('context', 'id', $context_id);
|
$context = $DB->get_record('context', array('id' => $context_id));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -356,6 +373,11 @@ function user_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function user_link_post_processing($title){
|
function user_link_post_processing($title){
|
||||||
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
global $CFG;
|
||||||
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
|
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -8,6 +8,7 @@
|
||||||
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||||
* @date 2008/03/31
|
* @date 2008/03/31
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
* @version Moodle 2.0
|
||||||
*
|
*
|
||||||
* document handling for wiki activity module
|
* document handling for wiki activity module
|
||||||
* This file contains the mapping between a wiki page and it's indexable counterpart,
|
* This file contains the mapping between a wiki page and it's indexable counterpart,
|
||||||
|
@ -20,8 +21,8 @@
|
||||||
/**
|
/**
|
||||||
* includes and requires
|
* includes and requires
|
||||||
*/
|
*/
|
||||||
require_once("$CFG->dirroot/search/documents/document.php");
|
require_once($CFG->dirroot.'/search/documents/document.php');
|
||||||
require_once("$CFG->dirroot/mod/wiki/lib.php");
|
require_once($CFG->dirroot.'/mod/wiki/lib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the $doc->___ fields are required by the base document class!
|
* All the $doc->___ fields are required by the base document class!
|
||||||
|
@ -68,35 +69,38 @@ function wiki_name_convert($str) {
|
||||||
* @param int $wikiId
|
* @param int $wikiId
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param int $version
|
* @param int $version
|
||||||
* @uses CFG
|
* @uses $CFG
|
||||||
*/
|
*/
|
||||||
function wiki_make_link($wikiId, $title, $version) {
|
function wiki_make_link($wikiId, $title, $version) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
return $CFG->wwwroot.'/mod/wiki/view.php?wid='.$wikiId.'&page='.wiki_name_convert($title).'&version='.$version;
|
return $CFG->wwwroot.'/mod/wiki/view.php?wid='.$wikiId.'&page='.wiki_name_convert($title).'&version='.$version;
|
||||||
} //wiki_make_link
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rescued and converted from ewikimoodlelib.php
|
* rescued and converted from ewikimoodlelib.php
|
||||||
* retrieves latest version of a page
|
* retrieves latest version of a page
|
||||||
|
* @uses $DB
|
||||||
* @param object $entry the wiki object as a reference
|
* @param object $entry the wiki object as a reference
|
||||||
* @param string $pagename the name of the page known by the wiki engine
|
* @param string $pagename the name of the page known by the wiki engine
|
||||||
* @param int $version
|
* @param int $version
|
||||||
*/
|
*/
|
||||||
function wiki_get_latest_page(&$entry, $pagename, $version = 0) {
|
function wiki_get_latest_page(&$entry, $pagename, $version = 0) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
$pagename = "'".addslashes($pagename)."'";
|
$pagename = "'".addslashes($pagename)."'";
|
||||||
|
|
||||||
if ($version > 0 and is_int($version)) {
|
if ($version > 0 && is_int($version)) {
|
||||||
$version = "AND (version=$version)";
|
$versionclause = "AND ( version = '$version' )";
|
||||||
} else {
|
} else {
|
||||||
$version = '';
|
$versionclause = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$select = "(pagename=$pagename) AND wiki=".$entry->id." $version ";
|
$select = "( pagename = ':pagename' ) AND wiki = :wikiid :versionclause ";
|
||||||
$sort = 'version DESC';
|
$sort = 'version DESC';
|
||||||
|
|
||||||
//change this to recordset_select, as per http://docs.moodle.org/en/Datalib_Notes
|
//change this to recordset_select, as per http://docs.moodle.org/en/Datalib_Notes
|
||||||
if ($result_arr = get_records_select('wiki_pages', $select, $sort, '*', 0, 1)) {
|
if ($result_arr = $DB->get_records_select('wiki_pages', $select, array('pagename' => $pagename, 'wikiid' => $entry->id, 'versionclause' => $versionclause), $sort, '*', 0, 1)) {
|
||||||
foreach ($result_arr as $obj) {
|
foreach ($result_arr as $obj) {
|
||||||
$result_obj = $obj;
|
$result_obj = $obj;
|
||||||
}
|
}
|
||||||
|
@ -112,18 +116,24 @@ function wiki_get_latest_page(&$entry, $pagename, $version = 0) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches all pages, including old versions
|
* fetches all pages, including old versions
|
||||||
|
* @uses $DB
|
||||||
* @param object $entry the wiki object as a reference
|
* @param object $entry the wiki object as a reference
|
||||||
* @return an array of record objects that represents pages of this wiki object
|
* @return an array of record objects that represents pages of this wiki object
|
||||||
*/
|
*/
|
||||||
function wiki_get_pages(&$entry) {
|
function wiki_get_pages(&$entry) {
|
||||||
return get_records('wiki_pages', 'wiki', $entry->id);
|
global $DB;
|
||||||
|
|
||||||
|
return $DB->get_records('wiki_pages', array('wiki', $entry->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches all the latest versions of all the pages
|
* fetches all the latest versions of all the pages
|
||||||
* @param object $entry
|
* @uses $DB
|
||||||
|
* @param reference $entry
|
||||||
*/
|
*/
|
||||||
function wiki_get_latest_pages(&$entry) {
|
function wiki_get_latest_pages(&$entry) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
//== (My)SQL for this
|
//== (My)SQL for this
|
||||||
/* select * from wiki_pages
|
/* select * from wiki_pages
|
||||||
inner join
|
inner join
|
||||||
|
@ -135,8 +145,8 @@ function wiki_get_latest_pages(&$entry) {
|
||||||
$pages = array();
|
$pages = array();
|
||||||
|
|
||||||
//http://moodle.org/bugs/bug.php?op=show&bugid=5877&pos=0
|
//http://moodle.org/bugs/bug.php?op=show&bugid=5877&pos=0
|
||||||
if ($ids = get_records('wiki_pages', 'wiki', $entry->id, '', 'distinct pagename')) {
|
if ($ids = $DB->get_records('wiki_pages', array('wiki' => $entry->id), '', 'distinct pagename')) {
|
||||||
if ($pagesets = get_records('wiki_pages', 'wiki', $entry->id, '', 'distinct pagename')) {
|
if ($pagesets = $DB->get_records('wiki_pages', array('wiki' => $entry->id), '', 'distinct pagename')) {
|
||||||
foreach ($pagesets as $aPageset) {
|
foreach ($pagesets as $aPageset) {
|
||||||
$pages[] = wiki_get_latest_page($entry, $aPageset->pagename);
|
$pages[] = wiki_get_latest_page($entry, $aPageset->pagename);
|
||||||
}
|
}
|
||||||
|
@ -149,25 +159,30 @@ function wiki_get_latest_pages(&$entry) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
|
* @uses $DB;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function wiki_iterator() {
|
function wiki_iterator() {
|
||||||
$wikis = get_records('wiki');
|
global $DB;
|
||||||
|
|
||||||
|
$wikis = $DB->get_records('wiki');
|
||||||
return $wikis;
|
return $wikis;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* part of search engine API
|
* part of search engine API
|
||||||
* @param wiki a wiki instance
|
* @uses $DB
|
||||||
|
* @param reference $wiki a wiki instance
|
||||||
* @return an array of searchable deocuments
|
* @return an array of searchable deocuments
|
||||||
*/
|
*/
|
||||||
function wiki_get_content_for_index(&$wiki) {
|
function wiki_get_content_for_index(&$wiki) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
$documents = array();
|
$documents = array();
|
||||||
$entries = wiki_get_entries($wiki);
|
$entries = wiki_get_entries($wiki);
|
||||||
if ($entries){
|
if ($entries){
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'wiki');
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'wiki'));
|
||||||
$cm = get_record('course_modules', 'course', $wiki->course, 'module', $coursemodule, 'instance', $wiki->id);
|
$cm = $DB->get_record('course_modules', array('course' => $wiki->course, 'module' => $coursemodule, 'instance' => $wiki->id));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
foreach($entries as $entry) {
|
foreach($entries as $entry) {
|
||||||
|
|
||||||
|
@ -190,15 +205,18 @@ function wiki_get_content_for_index(&$wiki) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a single wiki search document based on a wiki_entry id
|
* returns a single wiki search document based on a wiki_entry id
|
||||||
* @param id the id of the wiki
|
* @uses $DB;
|
||||||
* @param itemtype the type of information (standard)
|
* @param int $id the id of the wiki
|
||||||
|
* @param string $itemtype the type of information (standard)
|
||||||
* @return a searchable document
|
* @return a searchable document
|
||||||
*/
|
*/
|
||||||
function wiki_single_document($id, $itemtype) {
|
function wiki_single_document($id, $itemtype) {
|
||||||
$page = get_record('wiki_pages', 'id', $id);
|
global $DB;
|
||||||
$entry = get_record('wiki_entries', 'id', $page->wiki);
|
|
||||||
$coursemodule = get_field('modules', 'id', 'name', 'wiki');
|
$page = $DB->get_record('wiki_pages', array('id' => $id));
|
||||||
$cm = get_record('course_modules', 'course', $entry->course, 'module', $coursemodule, 'instance', $entry->wikiid);
|
$entry = $DB->get_record('wiki_entries', array('id' => $page->wiki));
|
||||||
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'wiki'));
|
||||||
|
$cm = $DB->get_record('course_modules', array('course' => $entry->course, 'module' => $coursemodule, 'instance' => $entry->wikiid));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
return new WikiSearchDocument(get_object_vars($page), $entry->wikiid, $entry->course, $entry->groupid, $page->userid, $context->id);
|
return new WikiSearchDocument(get_object_vars($page), $entry->wikiid, $entry->course, $entry->groupid, $page->userid, $context->id);
|
||||||
}
|
}
|
||||||
|
@ -227,27 +245,26 @@ function wiki_db_names() {
|
||||||
* - user is legitimate in the surrounding context
|
* - user is legitimate in the surrounding context
|
||||||
* - user may be guest and guest access is allowed to the module
|
* - user may be guest and guest access is allowed to the module
|
||||||
* - the function may perform local checks within the module information logic
|
* - the function may perform local checks within the module information logic
|
||||||
* @param path the access path to the module script code
|
* @param string $path the access path to the module script code
|
||||||
* @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
* @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
|
||||||
* @param this_id the item id within the information class denoted by itemtype. In wikies, this id
|
* @param int $this_id the item id within the information class denoted by itemtype. In wikies, this id
|
||||||
* points out the indexed wiki page.
|
* points out the indexed wiki page.
|
||||||
* @param user the user record denoting the user who searches
|
* @param object $user the user record denoting the user who searches
|
||||||
* @param group_id the current group used by the user when searching
|
* @param int $group_id the current group used by the user when searching
|
||||||
* @uses CFG
|
* @param int $context_id a context that eventually comes with the object
|
||||||
|
* @uses $CFG, $DB
|
||||||
* @return true if access is allowed, false elsewhere
|
* @return true if access is allowed, false elsewhere
|
||||||
*/
|
*/
|
||||||
function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// get the wiki object and all related stuff
|
// get the wiki object and all related stuff
|
||||||
$page = get_record('wiki_pages', 'id', $id);
|
$page = $DB->get_record('wiki_pages', array('id' => $id));
|
||||||
$entry = get_record('wiki_entries', 'id', $page->wiki);
|
$entry = $DB->get_record('wiki_entries', array('id' => $page->wiki));
|
||||||
$course = get_record('course', 'id', $entry->course);
|
$course = $DB->get_record('course', array('id' => $entry->course));
|
||||||
$context = get_record('context', 'id', $context_id);
|
$context = $DB->get_record('context', array('id' => $context_id));
|
||||||
$cm = get_record('course_modules', 'id', $context->instanceid);
|
$cm = $DB->get_record('course_modules', array('id' => $context->instanceid));
|
||||||
// $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course);
|
if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
||||||
// $context = get_record('context', 'id', $cm->id);
|
|
||||||
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
|
||||||
if (!empty($CFG->search_access_debug)) echo "search reject : hidden wiki ";
|
if (!empty($CFG->search_access_debug)) echo "search reject : hidden wiki ";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -268,7 +285,12 @@ function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function wiki_link_post_processing($title){
|
function wiki_link_post_processing($title){
|
||||||
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
global $CFG;
|
||||||
|
|
||||||
|
if ($CFG->block_search_utf8dir){
|
||||||
|
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||||
|
}
|
||||||
|
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue