1
0
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:
Vincent Jousse 2013-12-13 17:21:50 +01:00
parent 6fe342d0e9
commit 56071a0c81
4 changed files with 27 additions and 10 deletions

View File

@ -6,9 +6,9 @@ use Symfony\Component\HttpFoundation\Request;
$front = $app['controllers_factory']; $front = $app['controllers_factory'];
$front->get('/', function () use ($app) { $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) { $front->match('/add', function (Request $request) use ($app) {
@ -23,7 +23,7 @@ $front->match('/add', function (Request $request) use ($app) {
if ($form->isValid()) { if ($form->isValid()) {
$data = $form->getData(); $data = $form->getData();
// do something with the url $entry = $app['entry_api']->createAndSaveEntryFromUrl($data['url']);
return $app->redirect('/'); return $app->redirect('/');
} }

View File

@ -1,6 +1,8 @@
{% extends layout %} {% extends layout %}
{% block content %} {% 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> <p><a href="index.php/add">poche a new link</a></p>
{% endblock %} {% endblock %}

View File

@ -29,4 +29,11 @@ class EntryApi
return $entry; return $entry;
} }
public function createAndSaveEntryFromUrl($url) {
$entry = $this->createEntryFromUrl($url);
return $this->entryRepository->saveEntry($entry);
}
} }

View File

@ -10,12 +10,20 @@ class EntryRepository
$this->db = $db; $this->db = $db;
} }
public function getEntries() { //TODO don't hardcode the user ;)
$sql = "SELECT * FROM entries"; public function getEntries($userId = 1) {
$entries = $this->db->fetchAssoc($sql); $sql = "SELECT * FROM entries where user_id = :userId";
return ($entries ? $entries : array()); $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)));
}
} }