]>
Commit | Line | Data |
---|---|---|
9d50517c NL |
1 | <?php |
2 | ||
ad4d1caa | 3 | namespace Wallabag\CoreBundle\Entity; |
9d50517c | 4 | |
619cc453 | 5 | use Doctrine\Common\Collections\ArrayCollection; |
9d50517c | 6 | use Doctrine\ORM\Mapping as ORM; |
0a018fe0 NL |
7 | use JMS\Serializer\Annotation\ExclusionPolicy; |
8 | use JMS\Serializer\Annotation\Expose; | |
3c65dfb7 | 9 | use Gedmo\Mapping\Annotation as Gedmo; |
619cc453 | 10 | use JMS\Serializer\Annotation\XmlRoot; |
9d50517c NL |
11 | |
12 | /** | |
4346a860 | 13 | * Tag. |
9d50517c | 14 | * |
6d37a7e6 | 15 | * @XmlRoot("tag") |
bd0f3d32 | 16 | * @ORM\Table(name="`tag`") |
6d37a7e6 | 17 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository") |
0a018fe0 | 18 | * @ExclusionPolicy("all") |
9d50517c | 19 | */ |
653e8be4 | 20 | class Tag |
9d50517c NL |
21 | { |
22 | /** | |
4346a860 | 23 | * @var int |
9d50517c | 24 | * |
0a018fe0 | 25 | * @Expose |
653e8be4 | 26 | * @ORM\Column(name="id", type="integer") |
9d50517c | 27 | * @ORM\Id |
653e8be4 | 28 | * @ORM\GeneratedValue(strategy="AUTO") |
9d50517c NL |
29 | */ |
30 | private $id; | |
31 | ||
32 | /** | |
33 | * @var string | |
34 | * | |
0a018fe0 | 35 | * @Expose |
653e8be4 | 36 | * @ORM\Column(name="label", type="text") |
9d50517c | 37 | */ |
653e8be4 | 38 | private $label; |
9d50517c | 39 | |
3c65dfb7 | 40 | /** |
fc732227 | 41 | * @Expose |
3c65dfb7 NL |
42 | * @Gedmo\Slug(fields={"label"}) |
43 | * @ORM\Column(length=128, unique=true) | |
44 | */ | |
45 | private $slug; | |
46 | ||
0a018fe0 | 47 | /** |
46bbd8d3 | 48 | * @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"}) |
0a018fe0 NL |
49 | */ |
50 | private $entries; | |
51 | ||
fc732227 | 52 | public function __construct() |
46bbd8d3 NL |
53 | { |
54 | $this->entries = new ArrayCollection(); | |
55 | } | |
82d6d9cb JB |
56 | |
57 | public function __toString() | |
58 | { | |
59 | return $this->label; | |
60 | } | |
61 | ||
9d50517c | 62 | /** |
4346a860 | 63 | * Get id. |
9d50517c | 64 | * |
4346a860 | 65 | * @return int |
9d50517c NL |
66 | */ |
67 | public function getId() | |
68 | { | |
69 | return $this->id; | |
70 | } | |
71 | ||
72 | /** | |
4346a860 JB |
73 | * Set label. |
74 | * | |
75 | * @param string $label | |
9d50517c | 76 | * |
653e8be4 | 77 | * @return Tag |
9d50517c | 78 | */ |
653e8be4 | 79 | public function setLabel($label) |
9d50517c | 80 | { |
653e8be4 | 81 | $this->label = $label; |
9d50517c NL |
82 | |
83 | return $this; | |
84 | } | |
85 | ||
86 | /** | |
4346a860 | 87 | * Get label. |
9d50517c | 88 | * |
7df80cb3 | 89 | * @return string |
9d50517c | 90 | */ |
653e8be4 | 91 | public function getLabel() |
9d50517c | 92 | { |
2691cf04 | 93 | return $this->label; |
9d50517c | 94 | } |
46bbd8d3 | 95 | |
3c65dfb7 NL |
96 | public function getSlug() |
97 | { | |
98 | return $this->slug; | |
99 | } | |
100 | ||
46bbd8d3 NL |
101 | public function addEntry(Entry $entry) |
102 | { | |
103 | $this->entries[] = $entry; | |
104 | } | |
48b67328 | 105 | |
7244d6cb NL |
106 | public function hasEntry($entry) |
107 | { | |
108 | return $this->entries->contains($entry); | |
109 | } | |
567421af TC |
110 | |
111 | /** | |
112 | * Get entries for this tag. | |
113 | * | |
114 | * @return ArrayCollection<Entry> | |
115 | */ | |
116 | public function getEntries() | |
117 | { | |
118 | return $this->entries; | |
119 | } | |
12c69756 | 120 | |
d9926005 | 121 | public function getEntriesByUserId($userId) |
12c69756 NL |
122 | { |
123 | $filteredEntries = new ArrayCollection(); | |
124 | foreach ($this->entries as $entry) { | |
125 | if ($entry->getUser()->getId() === $userId) { | |
126 | $filteredEntries->add($entry); | |
127 | } | |
128 | } | |
129 | ||
130 | return $filteredEntries; | |
131 | } | |
9d50517c | 132 | } |