[add] model method to fetch one entry by id

This commit is contained in:
Nicolas Lœuillet 2014-01-08 10:56:54 +01:00
parent 9bc4e790b4
commit d85620383d
2 changed files with 13 additions and 1 deletions

View File

@ -15,6 +15,10 @@ class EntryApi
return $this->entryRepository->getEntries();
}
public function getEntryById($id) {
return $this->entryRepository->getEntryById($id);
}
public function createEntryFromUrl($url) {
//TODO: Fetch all what we need, fill the title, content …

View File

@ -12,7 +12,7 @@ class EntryRepository
//TODO don't hardcode the user ;)
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));
return $entries ? $entries : array();
@ -23,5 +23,13 @@ class EntryRepository
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();
}
}