[add] un/star entries

This commit is contained in:
Nicolas Lœuillet 2014-01-13 21:47:18 +01:00
parent f1582245fb
commit da14eda026
5 changed files with 61 additions and 1 deletions

View File

@ -55,4 +55,19 @@ $api->get('/mark-unread', function (Request $request) use ($app) {
return $app->json($entry, 201);
});
$api->get('/star', function (Request $request) use ($app) {
$id = $request->request->get('id');
$entry = $app['entry_api']->star($id);
return $app->json($entry, 201);
});
$api->get('/unstar', function (Request $request) use ($app) {
$id = $request->request->get('id');
$entry = $app['entry_api']->unstar($id);
return $app->json($entry, 201);
});
return $api;

View File

@ -39,6 +39,26 @@ $front->get('/mark-unread/{id}', function (Request $request, $id) use ($app) {
})
->bind('mark_entry_unread');
$front->get('/star/{id}', function (Request $request, $id) use ($app) {
$entry = $app['entry_api']->star($id);
$referer = $request->headers->get('referer');
return $app->redirect($referer);
})
->bind('star_entry');
$front->get('/unstar/{id}', function (Request $request, $id) use ($app) {
$entry = $app['entry_api']->unstar($id);
$referer = $request->headers->get('referer');
return $app->redirect($referer);
})
->bind('unstar_entry');
$front->match('/add', function (Request $request) use ($app) {
$data = array('url');

View File

@ -24,7 +24,7 @@
<p>{{ entry.content|striptags|slice(0, 300) }}&hellip;</p>
<ul>
<li>{% if entry.status == "read" %}<a href="{{ path('mark_entry_unread', {'id': entry.id}) }}">{{ 'mark as unread'|trans }}</a>{% else %}<a href="{{ path('mark_entry_read', {'id': entry.id}) }}">{{ 'mark as read'|trans }}</a>{% endif %}</li>
<li><a href="#">{{ 'star'|trans }}</a></li>
<li><a href="#">{% if entry.bookmark == 1 %}<a href="{{ path('unstar_entry', {'id': entry.id}) }}">{{ 'unstar'|trans }}</a>{% else %}<a href="{{ path('star_entry', {'id': entry.id}) }}">{{ 'star'|trans }}</a>{% endif %}</a></li>
<li><a href="#">{{ 'delete'|trans }}</a></li>
<li><a href="{{ entry.url }}">{{ 'view original'|trans }}</a></li>
</ul>

View File

@ -27,6 +27,14 @@ class EntryApi
return $this->entryRepository->markAsUnread($id);
}
public function star($id) {
return $this->entryRepository->star($id);
}
public function unstar($id) {
return $this->entryRepository->unstar($id);
}
public function createEntryFromUrl($url) {
//TODO: Fetch all what we need, fill the title, content …

View File

@ -47,5 +47,22 @@ class EntryRepository
return $count;
}
//TODO don't hardcode the user ;)
public function star($id, $userId = 1) {
$sql = "UPDATE entries SET bookmark = 1 where id = ? AND user_id = ?";
$count = $this->db->executeUpdate($sql, array($id, $userId));
return $count;
}
//TODO don't hardcode the user ;)
public function unstar($id, $userId = 1) {
$sql = "UPDATE entries SET bookmark = 0 where id = ? AND user_id = ?";
$count = $this->db->executeUpdate($sql, array($id, $userId));
return $count;
}
}