mirror of
https://github.com/moparisthebest/wallabag
synced 2024-12-18 13:42:17 -05:00
[add] model method to fetch one entry by id
This commit is contained in:
parent
9bc4e790b4
commit
d85620383d
@ -15,6 +15,10 @@ class EntryApi
|
|||||||
return $this->entryRepository->getEntries();
|
return $this->entryRepository->getEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getEntryById($id) {
|
||||||
|
return $this->entryRepository->getEntryById($id);
|
||||||
|
}
|
||||||
|
|
||||||
public function createEntryFromUrl($url) {
|
public function createEntryFromUrl($url) {
|
||||||
|
|
||||||
//TODO: Fetch all what we need, fill the title, content …
|
//TODO: Fetch all what we need, fill the title, content …
|
||||||
|
@ -12,7 +12,7 @@ class EntryRepository
|
|||||||
|
|
||||||
//TODO don't hardcode the user ;)
|
//TODO don't hardcode the user ;)
|
||||||
public function getEntries($userId = 1) {
|
public function getEntries($userId = 1) {
|
||||||
$sql = "SELECT * FROM entries where user_id = ?";
|
$sql = "SELECT * FROM entries where user_id = ? ORDER BY id DESC";
|
||||||
$entries = $this->db->fetchAll($sql, array($userId));
|
$entries = $this->db->fetchAll($sql, array($userId));
|
||||||
|
|
||||||
return $entries ? $entries : array();
|
return $entries ? $entries : array();
|
||||||
@ -23,5 +23,13 @@ class EntryRepository
|
|||||||
|
|
||||||
return $this->db->insert('entries', array_merge($entry, array('user_id' => $userId)));
|
return $this->db->insert('entries', array_merge($entry, array('user_id' => $userId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO don't hardcode the user ;)
|
||||||
|
public function getEntryById($id, $userId = 1) {
|
||||||
|
$sql = "SELECT * FROM entries where id = ? AND user_id = ?";
|
||||||
|
$entry = $this->db->fetchAll($sql, array($id, $userId));
|
||||||
|
|
||||||
|
return $entry ? $entry[0] : array();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user