1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-08-13 16:54:00 -04: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->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,8 +23,8 @@ $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('/');
}

View File

@ -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 %}
{% endblock %}

View File

@ -29,4 +29,11 @@ class EntryApi
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;
}
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)));
}
}