diff --git a/src/Poche/Api/EntryApi.php b/src/Poche/Api/EntryApi.php index ed9900d..3dcecd0 100644 --- a/src/Poche/Api/EntryApi.php +++ b/src/Poche/Api/EntryApi.php @@ -19,6 +19,10 @@ class EntryApi return $this->entryRepository->getEntryById($id); } + public function markAsRead($id) { + return $this->entryRepository->markAsRead($id); + } + public function createEntryFromUrl($url) { //TODO: Fetch all what we need, fill the title, content … diff --git a/src/Poche/Repository/EntryRepository.php b/src/Poche/Repository/EntryRepository.php index da0418b..4c437a5 100644 --- a/src/Poche/Repository/EntryRepository.php +++ b/src/Poche/Repository/EntryRepository.php @@ -12,7 +12,7 @@ class EntryRepository //TODO don't hardcode the user ;) public function getEntries($userId = 1) { - $sql = "SELECT * FROM entries where user_id = ? ORDER BY id DESC"; + $sql = "SELECT * FROM entries where user_id = ? AND status = 'unread' ORDER BY id DESC"; $entries = $this->db->fetchAll($sql, array($userId)); return $entries ? $entries : array(); @@ -21,7 +21,7 @@ class EntryRepository //TODO don't hardcode the user ;) public function saveEntry($entry, $userId = 1) { - return $this->db->insert('entries', array_merge($entry, array('user_id' => $userId))); + return $this->db->insert('entries', array_merge($entry, array('user_id' => $userId, 'status' => 'unread'))); } //TODO don't hardcode the user ;) @@ -31,5 +31,13 @@ class EntryRepository return $entry ? $entry : array(); } + + //TODO don't hardcode the user ;) + public function markAsRead($id, $userId = 1) { + $sql = "UPDATE entries SET status = 'read' where id = ? AND user_id = ?"; + $entry = $this->db->fetchAll($sql, array($id, $userId)); + + return $entry ? true : false; + } }