Beispiel #1
0
/**
* part of search engine API
* @uses $DB
* @param reference $database the database instance
* @return an array of searchable documents
*/
function data_get_content_for_index(&$database)
{
    global $DB;
    $documents = array();
    $recordTitles = array();
    $coursemodule = $DB->get_field('modules', 'id', array('name' => 'data'));
    $cm = $DB->get_record('course_modules', array('course' => $database->course, 'module' => $coursemodule, 'instance' => $database->id));
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    // getting records for indexing
    $records_content = data_get_records($database->id, 'text,textarea');
    if ($records_content) {
        foreach (array_keys($records_content) as $arecordid) {
            // extract title as first record in order
            $first = $records_content[$arecordid]['_first'];
            unset($records_content[$arecordid]['_first']);
            // concatenates all other texts
            $content = '';
            foreach ($records_content[$arecordid] as $afield) {
                $content = @$content . ' ' . $afield;
            }
            unset($recordMetaData);
            $recordMetaData = $DB->get_record('data_records', array('id' => $arecordid));
            $recordMetaData->title = $first;
            $recordTitles[$arecordid] = $first;
            $recordMetaData->content = $content;
            $documents[] = new DataSearchDocument(get_object_vars($recordMetaData), $database->course, $context->id);
        }
    }
    // getting comments for indexing
    $records_comments = data_get_comments($database->id);
    if ($records_comments) {
        foreach ($records_comments as $aComment) {
            $aComment->title = $recordsTitle[$aComment->itemid];
            $authoruser = $DB->get_record('user', array('id' => $aComment->userid));
            $aComment->author = fullname($authoruser);
            $documents[] = new DataCommentSearchDocument(get_object_vars($aComment), $database->course, $context->id);
        }
    }
    return $documents;
}
/**
* part of search engine API
* @param database the database instance
* @return an array of searchable documents
*/
function data_get_content_for_index(&$database)
{
    $documents = array();
    $recordTitles = array();
    $coursemodule = get_field('modules', 'id', 'name', 'data');
    $cm = get_record('course_modules', 'course', $database->course, 'module', $coursemodule, 'instance', $database->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    // getting records for indexing
    $records_content = data_get_records($database->id, 'text');
    if ($records_content) {
        foreach (array_keys($records_content) as $aRecordId) {
            // extract title as first record in order
            $first = $records_content[$aRecordId]['_first'];
            unset($records_content[$aRecordId]['_first']);
            // concatenates all other texts
            foreach ($records_content[$aRecordId] as $aField) {
                $content = @$content . ' ' . $aField;
            }
            if (strlen($content) > 0) {
                unset($recordMetaData);
                $recordMetaData = get_record('data_records', 'id', $aRecordId);
                $recordMetaData->title = $first;
                $recordTitles[$aRecordId] = $first;
                $recordMetaData->content = $content;
                $documents[] = new DataSearchDocument(get_object_vars($recordMetaData), $database->course, $context->id);
            }
        }
    }
    // getting comments for indexing
    $records_comments = data_get_comments($database->id);
    if ($records_comments) {
        foreach ($records_comments as $aComment) {
            $aComment->title = $recordsTitle[$aComment->recordid];
            $documents[] = new DataCommentSearchDocument(get_object_vars($aComment), $database->course, $context->id);
        }
    }
    return $documents;
}