diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-10-18 00:18:33 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-10-18 00:18:57 -0400 |
commit | b3baecc30eb02cc62b31ba85a95b2eca0730c620 (patch) | |
tree | 8761c641b7b348b6388aa42856724bb15a25380d /lib | |
parent | 138de85e03495a08250773541ab74b3410f6ce8f (diff) |
almost-working search provider
Diffstat (limited to 'lib')
-rw-r--r-- | lib/feedmapper.php | 6 | ||||
-rw-r--r-- | lib/search.php | 28 |
2 files changed, 31 insertions, 3 deletions
diff --git a/lib/feedmapper.php b/lib/feedmapper.php index 4220f99d7..27c1276a8 100644 --- a/lib/feedmapper.php +++ b/lib/feedmapper.php @@ -47,7 +47,6 @@ class FeedMapper { /** * @brief as a list that can be easily parsed using JSON - * @param userid * @returns */ public function findAll() { @@ -66,13 +65,14 @@ class FeedMapper { $id = $row['id']; $folderid = $row['folder_id']; $userid = $row['user_id']; - $feeds[] = array("url" => $url, "id" => $id, "folderid" => $folderid, 'userid' => $userid ); + $title = $row['title']; + $feeds[] = array("url" => $url, "id" => $id, "folderid" => $folderid, + 'userid' => $userid, 'title' => $title ); } return $feeds; } - /** * @brief returns the number of feeds that a user has * @returns the number of feeds that a user has diff --git a/lib/search.php b/lib/search.php new file mode 100644 index 000000000..d9d5d89f3 --- /dev/null +++ b/lib/search.php @@ -0,0 +1,28 @@ +<?php + +class OC_Search_Provider_News extends OC_Search_Provider{ + + function search($query) { + if (!OCP\App::isEnabled('news')) { + return array(); + } + + $feedMapper = new OCA\News\FeedMapper(OCP\USER::getUser()); + $results=array(); + + if($feedMapper->feedCount() > 0) { + $allFeeds = $feedMapper->findAll(); + + $l = new OC_l10n('news'); + + foreach($allFeeds as $feed) { + if(substr_count(strtolower($feed['title']), strtolower($query)) > 0) { + $link = OCP\Util::linkTo('news', 'index.php').'&lastViewedFeedId='.urlencode($feed['id']); + $results[]=new OC_Search_Result($feed['title'], '', $link, (string)$l->t('News')); + } + } + } + return $results; + + } +} |