aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Entity
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity')
-rw-r--r--src/Wallabag/CoreBundle/Entity/Config.php28
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php4
-rw-r--r--src/Wallabag/CoreBundle/Entity/TaggingRule.php133
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
3namespace Wallabag\CoreBundle\Entity; 3namespace Wallabag\CoreBundle\Entity;
4 4
5use Doctrine\Common\Collections\ArrayCollection;
5use Doctrine\ORM\Mapping as ORM; 6use Doctrine\ORM\Mapping as ORM;
6use Symfony\Component\Validator\Constraints as Assert; 7use 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
3namespace Wallabag\CoreBundle\Entity;
4
5use Doctrine\ORM\Mapping as ORM;
6use Symfony\Component\Validator\Constraints as Assert;
7use 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 */
16class 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}