Implement note search
[grauphel.git] / lib / notestorage.php
index 0aeef9e63e86f30a5a27ef7f7446c9e3e6e1c611..951bf06e23647a00aa6adb296ad5ec606cc2577b 100644 (file)
@@ -271,6 +271,29 @@ class NoteStorage
         return $row['note_guid'];
     }
 
         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.
      *
     /**
      * Save a note into storage.
      *