2006-08-02 15:31:59 +00:00
< ? php
require_once ( " $CFG->dirroot /search/documents/document.php " );
2006-09-20 21:00:45 +00:00
class ResourceSearchDocument extends SearchDocument {
2006-08-02 15:31:59 +00:00
public function __construct ( & $resource ) {
// generic information; required
$doc -> docid = $resource [ 'id' ];
$doc -> title = strip_tags ( $resource [ 'name' ]);
2006-08-16 13:31:55 +00:00
$doc -> date = $resource [ 'timemodified' ];
2006-09-20 21:00:45 +00:00
2006-08-02 15:31:59 +00:00
$doc -> author = '' ;
$doc -> contents = strip_tags ( $resource [ 'summary' ]) . ' ' . strip_tags ( $resource [ 'alltext' ]);
2006-09-20 21:00:45 +00:00
$doc -> url = resource_make_link ( $resource [ 'id' ]);
2006-08-02 15:31:59 +00:00
// module specific information; optional
$data = array ();
2006-09-20 21:00:45 +00:00
2006-08-02 15:31:59 +00:00
// construct the parent class
parent :: __construct ( $doc , $data , SEARCH_TYPE_RESOURCE , $resource [ 'course' ], - 1 );
2006-09-20 21:00:45 +00:00
} //constructor
} //ResourceSearchDocument
2006-08-02 15:31:59 +00:00
function resource_make_link ( $resource_id ) {
2006-09-20 21:00:45 +00:00
global $CFG ;
return $CFG -> wwwroot . '/mod/resource/view.php?r=' . $resource_id ;
2006-08-02 15:31:59 +00:00
} //resource_make_link
2006-09-20 21:00:45 +00:00
2006-08-02 15:31:59 +00:00
function resource_iterator () {
//trick to leave search indexer functionality intact, but allow
//this document to only use the below function to return info
//to be searched
2006-09-20 21:00:45 +00:00
return array ( true );
2006-08-02 15:31:59 +00:00
} //resource_iterator
2006-09-20 21:00:45 +00:00
2006-08-02 15:31:59 +00:00
//this function does not need a content iterator, returns all the info
//itself; remember to fake the iterator array though
function resource_get_content_for_index ( & $notneeded ) {
$documents = array ();
2006-09-20 21:00:45 +00:00
2006-08-02 15:31:59 +00:00
$resources = get_recordset_sql ( ' SELECT *
2006-09-26 05:09:01 +00:00
FROM { $CFG -> prefix } resource
2006-08-02 15:31:59 +00:00
WHERE alltext NOT LIKE " "
AND alltext NOT LIKE " "
AND alltext NOT LIKE " "
2006-09-20 21:00:45 +00:00
AND TYPE != " file " ' );
2006-08-02 15:31:59 +00:00
while ( ! $resources -> EOF ) {
$resource = $resources -> fields ;
2006-09-20 21:00:45 +00:00
2006-08-02 15:31:59 +00:00
if ( $resource ) {
$documents [] = new ResourceSearchDocument ( $resource );
} //if
2006-09-20 21:00:45 +00:00
2006-08-02 15:31:59 +00:00
$resources -> MoveNext ();
} //foreach
2006-09-20 21:00:45 +00:00
2006-08-02 15:31:59 +00:00
return $documents ;
} //resource_get_content_for_index
2006-09-20 21:00:45 +00:00
2006-08-21 00:50:29 +00:00
//returns a single resource search document based on a resource_entry id
function resource_single_document ( $id ) {
$resources = get_recordset_sql ( ' SELECT *
2006-09-26 05:09:01 +00:00
FROM { $CFG -> prefix } resource
2006-08-21 00:50:29 +00:00
WHERE alltext NOT LIKE " "
AND alltext NOT LIKE " "
AND alltext NOT LIKE " "
AND TYPE != " file " ,
2006-09-20 21:00:45 +00:00
AND id = ' . $id );
2006-08-21 00:50:29 +00:00
$resource = $resources -> fields ;
2006-09-20 21:00:45 +00:00
2006-08-21 00:50:29 +00:00
return new ResourceSearchDocument ( $resource );
2006-09-20 21:00:45 +00:00
} //resource_single_document
2006-08-21 00:50:29 +00:00
function resource_delete ( $info ) {
2006-09-20 21:00:45 +00:00
return $info ;
2006-08-21 00:50:29 +00:00
} //resource_delete
2006-09-20 21:00:45 +00:00
2006-08-21 00:50:29 +00:00
//returns the var names needed to build a sql query for addition/deletions
function resource_db_names () {
//[primary id], [table name], [time created field name], [time modified field name], [additional where conditions for sql]
2006-09-20 21:00:45 +00:00
return array ( 'id' , 'resource' , 'timemodified' , 'timemodified' , " WHERE alltext NOT LIKE '' AND alltext NOT LIKE ' ' AND alltext NOT LIKE ' ' AND TYPE != 'file' " );
} //resource_db_names
2006-08-02 15:31:59 +00:00
?>