mirror of
https://github.com/moparisthebest/wallabag
synced 2024-12-18 05:32:23 -05:00
WIP: Display and save entries
This commit is contained in:
parent
6fe342d0e9
commit
56071a0c81
@ -6,9 +6,9 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
$front = $app['controllers_factory'];
|
||||
$front->get('/', function () use ($app) {
|
||||
|
||||
$entry = new Entry(1, "Titre de test");
|
||||
$entries = $app['entry_api']->getEntries();
|
||||
|
||||
return $app['twig']->render('index.twig', array('entry' => $entry));
|
||||
return $app['twig']->render('index.twig', array('entries' => $entries));
|
||||
});
|
||||
|
||||
$front->match('/add', function (Request $request) use ($app) {
|
||||
@ -23,7 +23,7 @@ $front->match('/add', function (Request $request) use ($app) {
|
||||
if ($form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// do something with the url
|
||||
$entry = $app['entry_api']->createAndSaveEntryFromUrl($data['url']);
|
||||
|
||||
return $app->redirect('/');
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
{% extends layout %}
|
||||
|
||||
{% block content %}
|
||||
{{ entry.id }} - {{ entry.title }}
|
||||
{% for entry in entries %}
|
||||
{{ entry.id }} - {{ entry.title }}
|
||||
{% endfor %}
|
||||
<p><a href="index.php/add">poche a new link</a></p>
|
||||
{% endblock %}
|
@ -29,4 +29,11 @@ class EntryApi
|
||||
return $entry;
|
||||
}
|
||||
|
||||
|
||||
public function createAndSaveEntryFromUrl($url) {
|
||||
|
||||
$entry = $this->createEntryFromUrl($url);
|
||||
return $this->entryRepository->saveEntry($entry);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,20 @@ class EntryRepository
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function getEntries() {
|
||||
$sql = "SELECT * FROM entries";
|
||||
$entries = $this->db->fetchAssoc($sql);
|
||||
return ($entries ? $entries : array());
|
||||
//TODO don't hardcode the user ;)
|
||||
public function getEntries($userId = 1) {
|
||||
$sql = "SELECT * FROM entries where user_id = :userId";
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->bindValue('userId', $userId);
|
||||
$entries = $stmt->fetchAll();
|
||||
return $entries;
|
||||
}
|
||||
|
||||
//TODO don't hardcode the user ;)
|
||||
public function saveEntry($entry, $userId = 1) {
|
||||
|
||||
$sql = "INSERT INTO entries (url, title, content, user_id) values (:url, :title, :content, :user_id)";
|
||||
return $this->db->insert('entries', array_merge($entry, array('user_id' => $userId)));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user