diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-12-06 14:31:26 +0100 |
---|---|---|
committer | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-12-06 14:31:26 +0100 |
commit | a7f1921f7db312b5def3839393357f443dcbb52c (patch) | |
tree | 0522e03891433e9fdc9eb64d52b2d9651aadf1f7 /src/Wallabag/CoreBundle/Entity | |
parent | 2e15e30bf0e634bbbc3a9678904953d015490ed2 (diff) | |
parent | 752b90d1f2e279d3662d5431b09c7587df2937ca (diff) | |
download | wallabag-a7f1921f7db312b5def3839393357f443dcbb52c.tar.gz wallabag-a7f1921f7db312b5def3839393357f443dcbb52c.tar.zst wallabag-a7f1921f7db312b5def3839393357f443dcbb52c.zip |
Merge pull request #1478 from K-Phoen/rule-based-tags
Rule based tags
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity')
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Config.php | 28 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 4 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/TaggingRule.php | 133 |
3 files changed, 165 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index b2a1915a..2ca4182e 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Entity; | 3 | namespace Wallabag\CoreBundle\Entity; |
4 | 4 | ||
5 | use Doctrine\Common\Collections\ArrayCollection; | ||
5 | use Doctrine\ORM\Mapping as ORM; | 6 | use Doctrine\ORM\Mapping as ORM; |
6 | use Symfony\Component\Validator\Constraints as Assert; | 7 | use Symfony\Component\Validator\Constraints as Assert; |
7 | 8 | ||
@@ -76,12 +77,19 @@ class Config | |||
76 | */ | 77 | */ |
77 | private $user; | 78 | private $user; |
78 | 79 | ||
80 | /** | ||
81 | * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\TaggingRule", mappedBy="config", cascade={"remove"}) | ||
82 | * @ORM\OrderBy({"id" = "ASC"}) | ||
83 | */ | ||
84 | private $taggingRules; | ||
85 | |||
79 | /* | 86 | /* |
80 | * @param User $user | 87 | * @param User $user |
81 | */ | 88 | */ |
82 | public function __construct(\Wallabag\UserBundle\Entity\User $user) | 89 | public function __construct(\Wallabag\UserBundle\Entity\User $user) |
83 | { | 90 | { |
84 | $this->user = $user; | 91 | $this->user = $user; |
92 | $this->taggingRules = new ArrayCollection(); | ||
85 | } | 93 | } |
86 | 94 | ||
87 | /** | 95 | /** |
@@ -237,4 +245,24 @@ class Config | |||
237 | { | 245 | { |
238 | return $this->rssLimit; | 246 | return $this->rssLimit; |
239 | } | 247 | } |
248 | |||
249 | /** | ||
250 | * @param TaggingRule $rule | ||
251 | * | ||
252 | * @return Config | ||
253 | */ | ||
254 | public function addTaggingRule(TaggingRule $rule) | ||
255 | { | ||
256 | $this->taggingRules[] = $rule; | ||
257 | |||
258 | return $this; | ||
259 | } | ||
260 | |||
261 | /** | ||
262 | * @return ArrayCollection<TaggingRule> | ||
263 | */ | ||
264 | public function getTaggingRules() | ||
265 | { | ||
266 | return $this->taggingRules; | ||
267 | } | ||
240 | } | 268 | } |
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 5aa582f8..608ed2f0 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -458,6 +458,10 @@ class Entry | |||
458 | */ | 458 | */ |
459 | public function addTag(Tag $tag) | 459 | public function addTag(Tag $tag) |
460 | { | 460 | { |
461 | if ($this->tags->contains($tag)) { | ||
462 | return; | ||
463 | } | ||
464 | |||
461 | $this->tags[] = $tag; | 465 | $this->tags[] = $tag; |
462 | $tag->addEntry($this); | 466 | $tag->addEntry($this); |
463 | } | 467 | } |
diff --git a/src/Wallabag/CoreBundle/Entity/TaggingRule.php b/src/Wallabag/CoreBundle/Entity/TaggingRule.php new file mode 100644 index 00000000..4eab590f --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/TaggingRule.php | |||
@@ -0,0 +1,133 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Entity; | ||
4 | |||
5 | use Doctrine\ORM\Mapping as ORM; | ||
6 | use Symfony\Component\Validator\Constraints as Assert; | ||
7 | use KPhoen\RulerZBundle\Validator\Constraints as RulerZAssert; | ||
8 | |||
9 | /** | ||
10 | * Tagging rule. | ||
11 | * | ||
12 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TaggingRuleRepository") | ||
13 | * @ORM\Table | ||
14 | * @ORM\Entity | ||
15 | */ | ||
16 | class TaggingRule | ||
17 | { | ||
18 | /** | ||
19 | * @var int | ||
20 | * | ||
21 | * @ORM\Column(name="id", type="integer") | ||
22 | * @ORM\Id | ||
23 | * @ORM\GeneratedValue(strategy="AUTO") | ||
24 | */ | ||
25 | private $id; | ||
26 | |||
27 | /** | ||
28 | * @var string | ||
29 | * | ||
30 | * @Assert\NotBlank() | ||
31 | * @RulerZAssert\ValidRule( | ||
32 | * allowed_variables={"title", "url", "isArchived", "isStared", "content", "language", "mimetype", "readingTime", "domainName"}, | ||
33 | * allowed_operators={">", "<", ">=", "<=", "=", "is", "!=", "and", "not", "or", "matches"} | ||
34 | * ) | ||
35 | * @ORM\Column(name="rule", type="string", nullable=false) | ||
36 | */ | ||
37 | private $rule; | ||
38 | |||
39 | /** | ||
40 | * @var array | ||
41 | * | ||
42 | * @Assert\NotBlank() | ||
43 | * @ORM\Column(name="tags", type="simple_array", nullable=false) | ||
44 | */ | ||
45 | private $tags = []; | ||
46 | |||
47 | /** | ||
48 | * @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", inversedBy="taggingRules") | ||
49 | */ | ||
50 | private $config; | ||
51 | |||
52 | /** | ||
53 | * Get id. | ||
54 | * | ||
55 | * @return int | ||
56 | */ | ||
57 | public function getId() | ||
58 | { | ||
59 | return $this->id; | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Set rule. | ||
64 | * | ||
65 | * @param string $rule | ||
66 | * | ||
67 | * @return TaggingRule | ||
68 | */ | ||
69 | public function setRule($rule) | ||
70 | { | ||
71 | $this->rule = $rule; | ||
72 | |||
73 | return $this; | ||
74 | } | ||
75 | |||
76 | /** | ||
77 | * Get rule. | ||
78 | * | ||
79 | * @return string | ||
80 | */ | ||
81 | public function getRule() | ||
82 | { | ||
83 | return $this->rule; | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * Set tags. | ||
88 | * | ||
89 | * @param array<string> $tags | ||
90 | * | ||
91 | * @return TaggingRule | ||
92 | */ | ||
93 | public function setTags(array $tags) | ||
94 | { | ||
95 | $this->tags = $tags; | ||
96 | |||
97 | return $this; | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * Get tags. | ||
102 | * | ||
103 | * @return array<string> | ||
104 | */ | ||
105 | public function getTags() | ||
106 | { | ||
107 | return $this->tags; | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * Set config. | ||
112 | * | ||
113 | * @param Config $config | ||
114 | * | ||
115 | * @return TaggingRule | ||
116 | */ | ||
117 | public function setConfig(Config $config) | ||
118 | { | ||
119 | $this->config = $config; | ||
120 | |||
121 | return $this; | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * Get config. | ||
126 | * | ||
127 | * @return Config | ||
128 | */ | ||
129 | public function getConfig() | ||
130 | { | ||
131 | return $this->config; | ||
132 | } | ||
133 | } | ||