Slightly more helpful message if no courses can be shown.
[moodle-linuxchix.git] / search / documents / resource_document.php
blobbf1f6dd44dc7a011ead033f5cc830ef4ecdc112f
1 <?php
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'];
12 $doc->author = '';
13 $doc->contents = strip_tags($resource['summary']).' '.strip_tags($resource['alltext']);
14 $doc->url = resource_make_link($resource['id']);
16 // module specific information; optional
17 $data = array();
19 // construct the parent class
20 parent::__construct($doc, $data, SEARCH_TYPE_RESOURCE, $resource['course'], -1);
21 } //constructor
22 } //ResourceSearchDocument
24 function resource_make_link($resource_id) {
25 global $CFG;
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
32 //to be searched
33 return array(true);
34 } //resource_iterator
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) {
39 $documents = array();
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 "&nbsp;"
46 AND TYPE != "file"');
48 while (!$resources->EOF) {
49 $resource = $resources->fields;
51 if ($resource) {
52 $documents[] = new ResourceSearchDocument($resource);
53 } //if
55 $resources->MoveNext();
56 } //foreach
58 return $documents;
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 "&nbsp;"
68 AND TYPE != "file",
69 AND id = '.$id);
71 $resource = $resources->fields;
73 return new ResourceSearchDocument($resource);
74 } //resource_single_document
76 function resource_delete($info) {
77 return $info;
78 } //resource_delete
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 '&nbsp;' AND TYPE != 'file'");
84 } //resource_db_names