aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php26
-rw-r--r--src/Wallabag/CoreBundle/Helper/EntriesExport.php16
-rw-r--r--src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php34
-rw-r--r--src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php8
4 files changed, 67 insertions, 17 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index 5dd684f2..8019df42 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -95,14 +95,24 @@ class ContentProxy
95 * Assign some tags to an entry. 95 * Assign some tags to an entry.
96 * 96 *
97 * @param Entry $entry 97 * @param Entry $entry
98 * @param array|string $tags An array of tag or a string coma separated of tag 98 * @param array|string $tags An array of tag or a string coma separated of tag
99 * @param array $entitiesReady Entities from the EntityManager which are persisted but not yet flushed
100 * It is mostly to fix duplicate tag on import @see http://stackoverflow.com/a/7879164/569101
99 */ 101 */
100 public function assignTagsToEntry(Entry $entry, $tags) 102 public function assignTagsToEntry(Entry $entry, $tags, array $entitiesReady = [])
101 { 103 {
102 if (!is_array($tags)) { 104 if (!is_array($tags)) {
103 $tags = explode(',', $tags); 105 $tags = explode(',', $tags);
104 } 106 }
105 107
108 // keeps only Tag entity from the "not yet flushed entities"
109 $tagsNotYetFlushed = [];
110 foreach ($entitiesReady as $entity) {
111 if ($entity instanceof Tag) {
112 $tagsNotYetFlushed[$entity->getLabel()] = $entity;
113 }
114 }
115
106 foreach ($tags as $label) { 116 foreach ($tags as $label) {
107 $label = trim($label); 117 $label = trim($label);
108 118
@@ -111,11 +121,15 @@ class ContentProxy
111 continue; 121 continue;
112 } 122 }
113 123
114 $tagEntity = $this->tagRepository->findOneByLabel($label); 124 if (isset($tagsNotYetFlushed[$label])) {
125 $tagEntity = $tagsNotYetFlushed[$label];
126 } else {
127 $tagEntity = $this->tagRepository->findOneByLabel($label);
115 128
116 if (is_null($tagEntity)) { 129 if (is_null($tagEntity)) {
117 $tagEntity = new Tag(); 130 $tagEntity = new Tag();
118 $tagEntity->setLabel($label); 131 $tagEntity->setLabel($label);
132 }
119 } 133 }
120 134
121 // only add the tag on the entry if the relation doesn't exist 135 // only add the tag on the entry if the relation doesn't exist
diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php
index ccf4e4f3..e50c68a6 100644
--- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php
+++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php
@@ -21,7 +21,6 @@ class EntriesExport
21 private $entries = []; 21 private $entries = [];
22 private $authors = ['wallabag']; 22 private $authors = ['wallabag'];
23 private $language = ''; 23 private $language = '';
24 private $tags = [];
25 private $footerTemplate = '<div style="text-align:center;"> 24 private $footerTemplate = '<div style="text-align:center;">
26 <p>Produced by wallabag with %EXPORT_METHOD%</p> 25 <p>Produced by wallabag with %EXPORT_METHOD%</p>
27 <p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p> 26 <p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p>
@@ -53,10 +52,6 @@ class EntriesExport
53 52
54 $this->entries = $entries; 53 $this->entries = $entries;
55 54
56 foreach ($entries as $entry) {
57 $this->tags[] = $entry->getTags();
58 }
59
60 return $this; 55 return $this;
61 } 56 }
62 57
@@ -159,8 +154,8 @@ class EntriesExport
159 154
160 // set tags as subjects 155 // set tags as subjects
161 foreach ($this->entries as $entry) { 156 foreach ($this->entries as $entry) {
162 foreach ($this->tags as $tag) { 157 foreach ($entry->getTags() as $tag) {
163 $book->setSubject($tag['value']); 158 $book->setSubject($tag->getLabel());
164 } 159 }
165 160
166 // the reader in Kobo Devices doesn't likes special caracters 161 // the reader in Kobo Devices doesn't likes special caracters
@@ -265,8 +260,8 @@ class EntriesExport
265 * Adding actual entries 260 * Adding actual entries
266 */ 261 */
267 foreach ($this->entries as $entry) { 262 foreach ($this->entries as $entry) {
268 foreach ($this->tags as $tag) { 263 foreach ($entry->getTags() as $tag) {
269 $pdf->SetKeywords($tag['value']); 264 $pdf->SetKeywords($tag->getLabel());
270 } 265 }
271 266
272 $pdf->AddPage(); 267 $pdf->AddPage();
@@ -302,7 +297,7 @@ class EntriesExport
302 $enclosure = '"'; 297 $enclosure = '"';
303 $handle = fopen('php://memory', 'rb+'); 298 $handle = fopen('php://memory', 'rb+');
304 299
305 fputcsv($handle, ['Title', 'URL', 'Content', 'Tags', 'MIME Type', 'Language'], $delimiter, $enclosure); 300 fputcsv($handle, ['Title', 'URL', 'Content', 'Tags', 'MIME Type', 'Language', 'Creation date'], $delimiter, $enclosure);
306 301
307 foreach ($this->entries as $entry) { 302 foreach ($this->entries as $entry) {
308 fputcsv( 303 fputcsv(
@@ -315,6 +310,7 @@ class EntriesExport
315 implode(', ', $entry->getTags()->toArray()), 310 implode(', ', $entry->getTags()->toArray()),
316 $entry->getMimetype(), 311 $entry->getMimetype(),
317 $entry->getLanguage(), 312 $entry->getLanguage(),
313 $entry->getCreatedAt()->format('d/m/Y h:i:s'),
318 ], 314 ],
319 $delimiter, 315 $delimiter,
320 $enclosure 316 $enclosure
diff --git a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php
new file mode 100644
index 00000000..f9066bee
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php
@@ -0,0 +1,34 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Pagerfanta\Adapter\AdapterInterface;
6use Pagerfanta\Pagerfanta;
7use Symfony\Component\Routing\Router;
8use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
9
10class PreparePagerForEntries
11{
12 private $user;
13 private $router;
14
15 public function __construct(TokenStorage $token, Router $router)
16 {
17 $this->user = $token->getToken()->getUser();
18 $this->router = $router;
19 }
20
21 /**
22 * @param AdapterInterface $adapter
23 * @param int $page
24 *
25 * @return null|Pagerfanta
26 */
27 public function prepare(AdapterInterface $adapter, $page = 1)
28 {
29 $entries = new Pagerfanta($adapter);
30 $entries->setMaxPerPage($this->user->getConfig()->getItemsPerPage());
31
32 return $entries;
33 }
34}
diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
index 239d09ae..b490e209 100644
--- a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
+++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
@@ -55,6 +55,7 @@ class RuleBasedTagger
55 { 55 {
56 $rules = $this->getRulesForUser($user); 56 $rules = $this->getRulesForUser($user);
57 $entries = []; 57 $entries = [];
58 $tagsCache = [];
58 59
59 foreach ($rules as $rule) { 60 foreach ($rules as $rule) {
60 $qb = $this->entryRepository->getBuilderForAllByUser($user->getId()); 61 $qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
@@ -62,7 +63,12 @@ class RuleBasedTagger
62 63
63 foreach ($entries as $entry) { 64 foreach ($entries as $entry) {
64 foreach ($rule->getTags() as $label) { 65 foreach ($rule->getTags() as $label) {
65 $tag = $this->getTag($label); 66 // avoid new tag duplicate by manually caching them
67 if (!isset($tagsCache[$label])) {
68 $tagsCache[$label] = $this->getTag($label);
69 }
70
71 $tag = $tagsCache[$label];
66 72
67 $entry->addTag($tag); 73 $entry->addTag($tag);
68 } 74 }