Search::search()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 4
nop 1
dl 0
loc 20
ccs 0
cts 16
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * ownCloud - bookmarks plugin
5
 *
6
 * @author David Iwanowitsch
7
 * @copyright 2012 David Iwanowitsch <david at unclouded dot de>
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
 * License as published by the Free Software Foundation; either
12
 * version 3 of the License, or any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public
20
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Bookmarks\Controller\Lib;
25
26
use \OCA\Bookmarks\Controller\Lib\Bookmarks;
27
28
class Search extends \OCP\Search\Provider{
29
30
	function search($query) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
31
		$results = array();
32
33
		if (substr_count($query, ' ') > 0) {
34
			$search_words = explode(' ', $query);
35
		} else {
36
			$search_words = $query;
37
		}
38
39
		$db = \OC::$server->getDb();
40
		$user = \OCP\User::getUser();
41
42
		$bookmarks = Bookmarks::findBookmarks($user, $db, 0, 'id', $search_words, false);
43
		$l = new \OC_l10n('bookmarks'); //resulttype can't be localized, javascript relies on that type
44
		foreach ($bookmarks as $bookmark) {
45
			$results[] = new \OC_Search_Result($bookmark['title'], $bookmark['title'], $bookmark['url'], (string) $l->t('Bookm.'));
46
		}
47
48
		return $results;
49
	}
50
51
}
52