aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php2
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php6
-rw-r--r--src/Wallabag/CoreBundle/Filter/EntryFilterType.php23
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php27
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig8
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig10
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php23
7 files changed, 91 insertions, 8 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index b9e4e67e..a9f35c36 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -192,7 +192,7 @@ class EntryController extends Controller
192 throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); 192 throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
193 } 193 }
194 194
195 $form = $this->get('form.factory')->create(new EntryFilterType()); 195 $form = $this->get('form.factory')->create(new EntryFilterType($repository, $this->getUser()));
196 196
197 if ($request->query->has($form->getName())) { 197 if ($request->query->has($form->getName())) {
198 // manually bind values from the request 198 // manually bind values from the request
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
index 6cd24d44..dd316194 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
@@ -19,6 +19,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
19 $entry1->setUrl('http://0.0.0.0'); 19 $entry1->setUrl('http://0.0.0.0');
20 $entry1->setTitle('test title entry1'); 20 $entry1->setTitle('test title entry1');
21 $entry1->setContent('This is my content /o/'); 21 $entry1->setContent('This is my content /o/');
22 $entry1->setLanguage('en');
22 23
23 $manager->persist($entry1); 24 $manager->persist($entry1);
24 25
@@ -28,6 +29,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
28 $entry2->setUrl('http://0.0.0.0'); 29 $entry2->setUrl('http://0.0.0.0');
29 $entry2->setTitle('test title entry2'); 30 $entry2->setTitle('test title entry2');
30 $entry2->setContent('This is my content /o/'); 31 $entry2->setContent('This is my content /o/');
32 $entry2->setLanguage('fr');
31 33
32 $manager->persist($entry2); 34 $manager->persist($entry2);
33 35
@@ -37,6 +39,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
37 $entry3->setUrl('http://0.0.0.0'); 39 $entry3->setUrl('http://0.0.0.0');
38 $entry3->setTitle('test title entry3'); 40 $entry3->setTitle('test title entry3');
39 $entry3->setContent('This is my content /o/'); 41 $entry3->setContent('This is my content /o/');
42 $entry3->setLanguage('en');
40 43
41 $tag1 = new Tag($this->getReference('bob-user')); 44 $tag1 = new Tag($this->getReference('bob-user'));
42 $tag1->setLabel('foo'); 45 $tag1->setLabel('foo');
@@ -54,6 +57,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
54 $entry4->setUrl('http://0.0.0.0'); 57 $entry4->setUrl('http://0.0.0.0');
55 $entry4->setTitle('test title entry4'); 58 $entry4->setTitle('test title entry4');
56 $entry4->setContent('This is my content /o/'); 59 $entry4->setContent('This is my content /o/');
60 $entry4->setLanguage('en');
57 61
58 $tag1 = new Tag($this->getReference('admin-user')); 62 $tag1 = new Tag($this->getReference('admin-user'));
59 $tag1->setLabel('foo'); 63 $tag1->setLabel('foo');
@@ -72,6 +76,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
72 $entry5->setTitle('test title entry5'); 76 $entry5->setTitle('test title entry5');
73 $entry5->setContent('This is my content /o/'); 77 $entry5->setContent('This is my content /o/');
74 $entry5->setStarred(true); 78 $entry5->setStarred(true);
79 $entry5->setLanguage('fr');
75 80
76 $manager->persist($entry5); 81 $manager->persist($entry5);
77 82
@@ -82,6 +87,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
82 $entry6->setTitle('test title entry6'); 87 $entry6->setTitle('test title entry6');
83 $entry6->setContent('This is my content /o/'); 88 $entry6->setContent('This is my content /o/');
84 $entry6->setArchived(true); 89 $entry6->setArchived(true);
90 $entry6->setLanguage('de');
85 91
86 $manager->persist($entry6); 92 $manager->persist($entry6);
87 93
diff --git a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php
index 024486e6..f40c1c2d 100644
--- a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php
+++ b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php
@@ -6,9 +6,26 @@ use Symfony\Component\Form\AbstractType;
6use Symfony\Component\Form\FormBuilderInterface; 6use Symfony\Component\Form\FormBuilderInterface;
7use Symfony\Component\OptionsResolver\OptionsResolver; 7use Symfony\Component\OptionsResolver\OptionsResolver;
8use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface; 8use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
9use Doctrine\ORM\EntityRepository;
10use Wallabag\CoreBundle\Entity\User;
9 11
10class EntryFilterType extends AbstractType 12class EntryFilterType extends AbstractType
11{ 13{
14 private $user;
15 private $repository;
16
17 /**
18 * Repository & user are used to get a list of language entries for this user
19 *
20 * @param EntityRepository $entryRepository
21 * @param User $user
22 */
23 public function __construct(EntityRepository $entryRepository, User $user)
24 {
25 $this->repository = $entryRepository;
26 $this->user = $user;
27 }
28
12 public function buildForm(FormBuilderInterface $builder, array $options) 29 public function buildForm(FormBuilderInterface $builder, array $options)
13 { 30 {
14 $builder 31 $builder
@@ -53,7 +70,11 @@ class EntryFilterType extends AbstractType
53 70
54 return $filterQuery->createCondition($expression); 71 return $filterQuery->createCondition($expression);
55 }, 72 },
56 )); 73 ))
74 ->add('language', 'filter_choice', array(
75 'choices' => $this->repository->findDistinctLanguageByUser($this->user->getId()),
76 ))
77 ;
57 } 78 }
58 79
59 public function getName() 80 public function getName()
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index e764e8f7..87b9befe 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -134,4 +134,31 @@ class EntryRepository extends EntityRepository
134 134
135 return $qb->getQuery()->getResult(); 135 return $qb->getQuery()->getResult();
136 } 136 }
137
138 /**
139 * Find distinct language for a given user.
140 * Used to build the filter language list.
141 *
142 * @param int $userId User id
143 *
144 * @return array
145 */
146 public function findDistinctLanguageByUser($userId)
147 {
148 $results = $this->createQueryBuilder('e')
149 ->select('e.language')
150 ->where('e.user = :userId')->setParameter('userId', $userId)
151 ->andWhere('e.language IS NOT NULL')
152 ->groupBy('e.language')
153 ->orderBy('e.language', ' ASC')
154 ->getQuery()
155 ->getResult();
156
157 $languages = array();
158 foreach ($results as $result) {
159 $languages[$result['language']] = $result['language'];
160 }
161
162 return $languages;
163 }
137} 164}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
index 176290e4..08f3fe60 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
@@ -71,6 +71,14 @@
71 <label for="entry_filter_previewPicture">{% trans %}Has a preview picture{% endtrans %}</label> 71 <label for="entry_filter_previewPicture">{% trans %}Has a preview picture{% endtrans %}</label>
72 </div> 72 </div>
73 </div> 73 </div>
74
75 <div id="filter-language" class="filter-group">
76 <label for="entry_filter_language">{% trans %}Language{% endtrans %}</label>
77 <div class="input-field ">
78 {{ form_widget(form.language) }}
79 </div>
80 </div>
81
74 <div id="filter-reading-time" class="filter-group"> 82 <div id="filter-reading-time" class="filter-group">
75 <div class=""> 83 <div class="">
76 <label>{% trans %}Reading time in minutes{% endtrans %}</label> 84 <label>{% trans %}Reading time in minutes{% endtrans %}</label>
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
index c2157db5..dcdf7c09 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
@@ -121,14 +121,12 @@
121 <label for="entry_filter_previewPicture">{% trans %}Has a preview picture{% endtrans %}</label> 121 <label for="entry_filter_previewPicture">{% trans %}Has a preview picture{% endtrans %}</label>
122 </div> 122 </div>
123 123
124 <div class="input-field col s6"> 124 <div class="col s12">
125 {{ form_widget(form.isArchived) }} 125 <label>{% trans %}Language{% endtrans %}</label>
126 <label for="entry_filter_isArchived">{% trans %}Archived{% endtrans %}</label>
127 </div> 126 </div>
128 127
129 <div class="input-field col s6"> 128 <div class="input-field col s12">
130 {{ form_widget(form.isStarred) }} 129 {{ form_widget(form.language) }}
131 <label for="entry_filter_isStarred">{% trans %}Starred{% endtrans %}</label>
132 </div> 130 </div>
133 131
134 <div class="col s12"> 132 <div class="col s12">
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
index 77b57884..cbd84a97 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
@@ -382,4 +382,27 @@ class EntryControllerTest extends WallabagCoreTestCase
382 $crawler = $client->submit($form); 382 $crawler = $client->submit($form);
383 $this->assertCount(1, $crawler->filter('div[class=entry]')); 383 $this->assertCount(1, $crawler->filter('div[class=entry]'));
384 } 384 }
385
386 public function testFilterOnLanguage()
387 {
388 $this->logInAs('admin');
389 $client = $this->getClient();
390
391 $crawler = $client->request('GET', '/unread/list');
392 $form = $crawler->filter('button[id=submit-filter]')->form();
393 $data = array(
394 'entry_filter[language]' => 'de',
395 );
396
397 $crawler = $client->submit($form, $data);
398 $this->assertCount(1, $crawler->filter('div[class=entry]'));
399
400 $form = $crawler->filter('button[id=submit-filter]')->form();
401 $data = array(
402 'entry_filter[language]' => 'en',
403 );
404
405 $crawler = $client->submit($form, $data);
406 $this->assertCount(2, $crawler->filter('div[class=entry]'));
407 }
385} 408}