'name' => 'Tomboy notes'
)
);
+\OC_Search::registerProvider('OCA\Grauphel\Search\Provider');
+\OCP\Util::addscript('grauphel', 'loader');
?>
--- /dev/null
+$(document).ready(function() {
+ // translate search result type
+ OC.search.resultTypes.note = 'Note';
+});
\ No newline at end of file
return $row['note_guid'];
}
+ /**
+ * 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.
*
--- /dev/null
+<?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';
+}
+?>
--- /dev/null
+<?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;
+ }
+}
+?>