diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 26 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/EntriesExport.php | 3 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php | 34 |
3 files changed, 56 insertions, 7 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..0c627dcd 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php | |||
@@ -302,7 +302,7 @@ class EntriesExport | |||
302 | $enclosure = '"'; | 302 | $enclosure = '"'; |
303 | $handle = fopen('php://memory', 'rb+'); | 303 | $handle = fopen('php://memory', 'rb+'); |
304 | 304 | ||
305 | fputcsv($handle, ['Title', 'URL', 'Content', 'Tags', 'MIME Type', 'Language'], $delimiter, $enclosure); | 305 | fputcsv($handle, ['Title', 'URL', 'Content', 'Tags', 'MIME Type', 'Language', 'Creation date'], $delimiter, $enclosure); |
306 | 306 | ||
307 | foreach ($this->entries as $entry) { | 307 | foreach ($this->entries as $entry) { |
308 | fputcsv( | 308 | fputcsv( |
@@ -315,6 +315,7 @@ class EntriesExport | |||
315 | implode(', ', $entry->getTags()->toArray()), | 315 | implode(', ', $entry->getTags()->toArray()), |
316 | $entry->getMimetype(), | 316 | $entry->getMimetype(), |
317 | $entry->getLanguage(), | 317 | $entry->getLanguage(), |
318 | $entry->getCreatedAt()->format('d/m/Y h:i:s'), | ||
318 | ], | 319 | ], |
319 | $delimiter, | 320 | $delimiter, |
320 | $enclosure | 321 | $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 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Pagerfanta\Adapter\AdapterInterface; | ||
6 | use Pagerfanta\Pagerfanta; | ||
7 | use Symfony\Component\Routing\Router; | ||
8 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
9 | |||
10 | class 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 | } | ||