diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2014-10-24 08:54:35 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2014-10-24 08:54:35 +0200 |
| commit | 2b5ff5d48b4ec80e0e0e18188689edefaeefe91d (patch) | |
| tree | 48c56752ddba48451fb10bed7e463adf531d037d | |
| parent | 93298095b3c4455aa1a4c676d6e2f9915ca06caa (diff) | |
| download | grauphel-2b5ff5d48b4ec80e0e0e18188689edefaeefe91d.tar.gz grauphel-2b5ff5d48b4ec80e0e0e18188689edefaeefe91d.zip | |
Implement note search
| -rwxr-xr-x | appinfo/app.php | 2 | ||||
| -rw-r--r-- | js/loader.js | 4 | ||||
| -rw-r--r-- | lib/notestorage.php | 23 | ||||
| -rw-r--r-- | lib/search/note.php | 36 | ||||
| -rw-r--r-- | lib/search/provider.php | 58 |
5 files changed, 123 insertions, 0 deletions
diff --git a/appinfo/app.php b/appinfo/app.php index b3c2b46..c80d95b 100755 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -10,4 +10,6 @@ OCP\App::addNavigationEntry( 'name' => 'Tomboy notes' ) ); +\OC_Search::registerProvider('OCA\Grauphel\Search\Provider'); +\OCP\Util::addscript('grauphel', 'loader'); ?> diff --git a/js/loader.js b/js/loader.js new file mode 100644 index 0000000..84c2342 --- /dev/null +++ b/js/loader.js @@ -0,0 +1,4 @@ +$(document).ready(function() { + // translate search result type + OC.search.resultTypes.note = 'Note'; +});
\ No newline at end of file diff --git a/lib/notestorage.php b/lib/notestorage.php index 0aeef9e..951bf06 100644 --- a/lib/notestorage.php +++ b/lib/notestorage.php @@ -272,6 +272,29 @@ class NoteStorage } /** + * Search for a note + * + * @param string $query Query string + * + * @return array Database rows with note_guid and note_title + */ + public function search($query) + { + $result = \OC_DB::executeAudited( + 'SELECT `note_guid`, `note_title`' + . ' FROM `*PREFIX*grauphel_notes`' + . ' WHERE note_user = ? AND note_title LIKE ?', + array($this->username, '%' . $query . '%') + ); + + $notes = array(); + while ($row = $result->fetchRow()) { + $notes[] = $row; + } + return $notes; + } + + /** * Save a note into storage. * * @param object $note Note to save diff --git a/lib/search/note.php b/lib/search/note.php new file mode 100644 index 0000000..333fa8f --- /dev/null +++ b/lib/search/note.php @@ -0,0 +1,36 @@ +<?php +/** + * Part of grauphel + * + * PHP version 5 + * + * @category Tools + * @package Grauphel + * @author Christian Weiske <cweiske@cweiske.de> + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/grauphel.htm + */ +namespace OCA\Grauphel\Search; + +/** + * Note search result + * + * @category Tools + * @package Grauphel + * @author Christian Weiske <cweiske@cweiske.de> + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @version Release: @package_version@ + * @link http://cweiske.de/grauphel.htm + */ +class Note extends \OCP\Search\Result +{ + /** + * Type name; translated in templates + * + * @var string + */ + public $type = 'note'; +} +?> diff --git a/lib/search/provider.php b/lib/search/provider.php new file mode 100644 index 0000000..5b42bb7 --- /dev/null +++ b/lib/search/provider.php @@ -0,0 +1,58 @@ +<?php +/** + * Part of grauphel + * + * PHP version 5 + * + * @category Tools + * @package Grauphel + * @author Christian Weiske <cweiske@cweiske.de> + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/grauphel.htm + */ +namespace OCA\Grauphel\Search; + +use \OCA\Grauphel\Lib\NoteStorage; + +/** + * Hook for the site-wide owncloud search. + * + * @category Tools + * @package Grauphel + * @author Christian Weiske <cweiske@cweiske.de> + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @version Release: @package_version@ + * @link http://cweiske.de/grauphel.htm + */ +class Provider extends \OCP\Search\Provider +{ + /** + * Search for notes + * + * @param string $query + * + * @return array list of \OCA\Grauphel\Search\Note + */ + public function search($query) + { + $urlGen = \OC::$server->getURLGenerator(); + $notes = new NoteStorage($urlGen); + $notes->setUsername(\OC_User::getUser()); + $rows = $notes->search($query); + + $results = array(); + foreach ($rows as $row) { + $res = new Note(); + $res->id = $row['note_guid']; + $res->name = $row['note_title']; + $res->link = $urlGen->linkToRoute( + 'grauphel.gui.note', array('guid' => $row['note_guid']) + ); + $results[] = $res; + } + return $results; + } +} +?> |
