aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper/ContentProxy.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-02-19 14:22:20 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-02-19 14:22:20 +0100
commitc2656f96d4776c86b13d8a4c93a78ee7c4d3824c (patch)
treee7aaddb8e35197420db96bb067fe410e40c0025c /src/Wallabag/CoreBundle/Helper/ContentProxy.php
parentfa64d861105bd0713acd7ac5d116353273524b4f (diff)
downloadwallabag-c2656f96d4776c86b13d8a4c93a78ee7c4d3824c.tar.gz
wallabag-c2656f96d4776c86b13d8a4c93a78ee7c4d3824c.tar.zst
wallabag-c2656f96d4776c86b13d8a4c93a78ee7c4d3824c.zip
Move assignTagsToEntry in ContentProxy helper
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/ContentProxy.php')
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index bd8b993a..ba90b731 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -5,7 +5,9 @@ namespace Wallabag\CoreBundle\Helper;
5use Graby\Graby; 5use Graby\Graby;
6use Psr\Log\LoggerInterface as Logger; 6use Psr\Log\LoggerInterface as Logger;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Entity\Tag;
8use Wallabag\CoreBundle\Tools\Utils; 9use Wallabag\CoreBundle\Tools\Utils;
10use Wallabag\CoreBundle\Repository\TagRepository;
9 11
10/** 12/**
11 * This kind of proxy class take care of getting the content from an url 13 * This kind of proxy class take care of getting the content from an url
@@ -16,12 +18,14 @@ class ContentProxy
16 protected $graby; 18 protected $graby;
17 protected $tagger; 19 protected $tagger;
18 protected $logger; 20 protected $logger;
21 protected $tagRepository;
19 22
20 public function __construct(Graby $graby, RuleBasedTagger $tagger, Logger $logger) 23 public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, Logger $logger)
21 { 24 {
22 $this->graby = $graby; 25 $this->graby = $graby;
23 $this->tagger = $tagger; 26 $this->tagger = $tagger;
24 $this->logger = $logger; 27 $this->logger = $logger;
28 $this->tagRepository = $tagRepository;
25 } 29 }
26 30
27 /** 31 /**
@@ -75,4 +79,38 @@ class ContentProxy
75 79
76 return $entry; 80 return $entry;
77 } 81 }
82
83 /**
84 * Assign some tags to an entry.
85 *
86 * @param Entry $entry
87 * @param array|string $tags An array of tag or a string coma separated of tag
88 */
89 public function assignTagsToEntry(Entry $entry, $tags)
90 {
91 if (!is_array($tags)) {
92 $tags = explode(',', $tags);
93 }
94
95 foreach ($tags as $label) {
96 $label = trim($label);
97
98 // avoid empty tag
99 if (0 === strlen($label)) {
100 continue;
101 }
102
103 $tagEntity = $this->tagRepository->findOneByLabel($label);
104
105 if (is_null($tagEntity)) {
106 $tagEntity = new Tag();
107 $tagEntity->setLabel($label);
108 }
109
110 // only add the tag on the entry if the relation doesn't exist
111 if (false === $entry->getTags()->contains($tagEntity)) {
112 $entry->addTag($tagEntity);
113 }
114 }
115 }
78} 116}