3 require_once("$CFG->dirroot/search/documents/document.php");
5 class ResourceSearchDocument
extends SearchDocument
{
6 public function __construct(&$resource) {
7 // generic information; required
8 $doc->docid
= $resource['id'];
9 $doc->title
= strip_tags($resource['name']);
10 $doc->date
= $resource['timemodified'];
13 $doc->contents
= strip_tags($resource['summary']).' '.strip_tags($resource['alltext']);
14 $doc->url
= resource_make_link($resource['id']);
16 // module specific information; optional
19 // construct the parent class
20 parent
::__construct($doc, $data, SEARCH_TYPE_RESOURCE
, $resource['course'], -1);
22 } //ResourceSearchDocument
24 function resource_make_link($resource_id) {
26 return $CFG->wwwroot
.'/mod/resource/view.php?r='.$resource_id;
27 } //resource_make_link
29 function resource_iterator() {
30 //trick to leave search indexer functionality intact, but allow
31 //this document to only use the below function to return info
36 //this function does not need a content iterator, returns all the info
37 //itself; remember to fake the iterator array though
38 function resource_get_content_for_index(&$notneeded) {
41 $resources = get_recordset_sql('SELECT *
42 FROM {$CFG->prefix}resource
43 WHERE alltext NOT LIKE ""
44 AND alltext NOT LIKE " "
45 AND alltext NOT LIKE " "
48 while (!$resources->EOF
) {
49 $resource = $resources->fields
;
52 $documents[] = new ResourceSearchDocument($resource);
55 $resources->MoveNext();
59 } //resource_get_content_for_index
61 //returns a single resource search document based on a resource_entry id
62 function resource_single_document($id) {
63 $resources = get_recordset_sql('SELECT *
64 FROM {$CFG->prefix}resource
65 WHERE alltext NOT LIKE ""
66 AND alltext NOT LIKE " "
67 AND alltext NOT LIKE " "
71 $resource = $resources->fields
;
73 return new ResourceSearchDocument($resource);
74 } //resource_single_document
76 function resource_delete($info) {
80 //returns the var names needed to build a sql query for addition/deletions
81 function resource_db_names() {
82 //[primary id], [table name], [time created field name], [time modified field name], [additional where conditions for sql]
83 return array('id', 'resource', 'timemodified', 'timemodified', "WHERE alltext NOT LIKE '' AND alltext NOT LIKE ' ' AND alltext NOT LIKE ' ' AND TYPE != 'file'");