]>
Commit | Line | Data |
---|---|---|
9d50517c NL |
1 | <?php |
2 | ||
ad4d1caa | 3 | namespace Wallabag\CoreBundle\Entity; |
9d50517c NL |
4 | |
5 | use Doctrine\ORM\Mapping as ORM; | |
6d37a7e6 | 6 | use JMS\Serializer\Annotation\XmlRoot; |
0a018fe0 NL |
7 | use JMS\Serializer\Annotation\ExclusionPolicy; |
8 | use JMS\Serializer\Annotation\Expose; | |
46bbd8d3 | 9 | use Doctrine\Common\Collections\ArrayCollection; |
3c65dfb7 | 10 | use Gedmo\Mapping\Annotation as Gedmo; |
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 NL |
40 | /** |
41 | * @Gedmo\Slug(fields={"label"}) | |
42 | * @ORM\Column(length=128, unique=true) | |
43 | */ | |
44 | private $slug; | |
45 | ||
0a018fe0 | 46 | /** |
46bbd8d3 | 47 | * @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"}) |
0a018fe0 NL |
48 | */ |
49 | private $entries; | |
50 | ||
092ca707 | 51 | /** |
1210dae1 | 52 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="tags") |
092ca707 NL |
53 | */ |
54 | private $user; | |
55 | ||
0a878469 | 56 | public function __construct(\Wallabag\UserBundle\Entity\User $user) |
46bbd8d3 | 57 | { |
8ce32af6 | 58 | $this->user = $user; |
46bbd8d3 NL |
59 | $this->entries = new ArrayCollection(); |
60 | } | |
82d6d9cb JB |
61 | |
62 | public function __toString() | |
63 | { | |
64 | return $this->label; | |
65 | } | |
66 | ||
9d50517c | 67 | /** |
4346a860 | 68 | * Get id. |
9d50517c | 69 | * |
4346a860 | 70 | * @return int |
9d50517c NL |
71 | */ |
72 | public function getId() | |
73 | { | |
74 | return $this->id; | |
75 | } | |
76 | ||
77 | /** | |
4346a860 JB |
78 | * Set label. |
79 | * | |
80 | * @param string $label | |
9d50517c | 81 | * |
653e8be4 | 82 | * @return Tag |
9d50517c | 83 | */ |
653e8be4 | 84 | public function setLabel($label) |
9d50517c | 85 | { |
653e8be4 | 86 | $this->label = $label; |
9d50517c NL |
87 | |
88 | return $this; | |
89 | } | |
90 | ||
91 | /** | |
4346a860 | 92 | * Get label. |
9d50517c | 93 | * |
7df80cb3 | 94 | * @return string |
9d50517c | 95 | */ |
653e8be4 | 96 | public function getLabel() |
9d50517c | 97 | { |
2691cf04 | 98 | return $this->label; |
9d50517c | 99 | } |
46bbd8d3 | 100 | |
3c65dfb7 NL |
101 | public function getSlug() |
102 | { | |
103 | return $this->slug; | |
104 | } | |
105 | ||
46bbd8d3 NL |
106 | public function addEntry(Entry $entry) |
107 | { | |
108 | $this->entries[] = $entry; | |
109 | } | |
48b67328 | 110 | |
7244d6cb NL |
111 | public function hasEntry($entry) |
112 | { | |
113 | return $this->entries->contains($entry); | |
114 | } | |
115 | ||
48b67328 NL |
116 | /** |
117 | * @return User | |
118 | */ | |
119 | public function getUser() | |
120 | { | |
121 | return $this->user; | |
122 | } | |
9d50517c | 123 | } |