Commit 3babb8c2 authored by Robin Appelman's avatar Robin Appelman
Browse files

improve flexibility of search providers a bit

parent 8ed46066
......@@ -20,8 +20,8 @@
*
*/
class OC_Search_Provider_Bookmarks implements OC_Search_Provider{
static function search($query){
class OC_Search_Provider_Bookmarks extends OC_Search_Provider{
function search($query){
$results=array();
$offset = 0;
......
<?php
class OC_Search_Provider_Calendar implements OC_Search_Provider{
static function search($query){
class OC_Search_Provider_Calendar extends OC_Search_Provider{
function search($query){
$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1);
if(count($calendars)==0 || !OC_App::isEnabled('calendar')){
//return false;
......
<?php
class OC_Search_Provider_Contacts implements OC_Search_Provider{
static function search($query){
class OC_Search_Provider_Contacts extends OC_Search_Provider{
function search($query){
$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser(), 1);
// if(count($calendars)==0 || !OC_App::isEnabled('contacts')){
// //return false;
......
......@@ -41,8 +41,8 @@ OC_App::addNavigationEntry( array(
'icon' => OC_Helper::imagePath('core', 'places/picture.svg'),
'name' => $l->t('Pictures')));
class OC_GallerySearchProvider implements OC_Search_Provider{
static function search($query){
class OC_GallerySearchProvider extends OC_Search_Provider{
function search($query){
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ? AND album_name LIKE ?');
$result = $stmt->execute(array(OC_User::getUser(),'%'.$query.'%'));
$results=array();
......
......@@ -82,8 +82,8 @@ class OC_MEDIA{
}
}
class OC_MediaSearchProvider implements OC_Search_Provider{
static function search($query){
class OC_MediaSearchProvider extends OC_Search_Provider{
function search($query){
require_once('lib_collection.php');
$artists=OC_MEDIA_COLLECTION::getArtists($query);
$albums=OC_MEDIA_COLLECTION::getAlbums(0,$query);
......
......@@ -26,13 +26,22 @@
*/
class OC_Search{
static private $providers=array();
static private $registeredProviders=array();
/**
* remove all registered search providers
*/
public static function clearProviders(){
self::$providers=array();
self::$registeredProviders=array();
}
/**
* register a new search provider to be used
* @param string $provider class name of a OC_Search_Provider
*/
public static function registerProvider($provider){
self::$providers[]=$provider;
public static function registerProvider($class,$options=array()){
self::$registeredProviders[]=array('class'=>$class,'options'=>$options);
}
/**
......@@ -41,10 +50,25 @@ class OC_Search{
* @return array An array of OC_Search_Result's
*/
public static function search($query){
self::initProviders();
$results=array();
foreach(self::$providers as $provider){
$results=array_merge($results, $provider::search($query));
$results=array_merge($results, $provider->search($query));
}
return $results;
}
/**
* create instances of all the registered search providers
*/
private static function initProviders(){
if(count(self::$providers)>0){
return;
}
foreach(self::$registeredProviders as $provider){
$class=$provider['class'];
$options=$provider['options'];
self::$providers[]=new $class($options);
}
}
}
......@@ -2,11 +2,13 @@
/**
* provides search functionalty
*/
interface OC_Search_Provider {
class OC_Search_Provider {
public function __construct($options){}
/**
* search for $query
* @param string $query
* @return array An array of OC_Search_Result's
*/
static function search($query);
public function search($query){}
}
<?php
class OC_Search_Provider_File implements OC_Search_Provider{
static function search($query){
class OC_Search_Provider_File extends OC_Search_Provider{
function search($query){
$files=OC_FileCache::search($query,true);
$results=array();
foreach($files as $fileData){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment