]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Entity/Tag.php
4ed588be867be0a3b38227dce42b863999721bee
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Tag.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Entity;
4
5 use Doctrine\ORM\Mapping as ORM;
6 use JMS\Serializer\Annotation\XmlRoot;
7 use JMS\Serializer\Annotation\ExclusionPolicy;
8 use JMS\Serializer\Annotation\Expose;
9 use Doctrine\Common\Collections\ArrayCollection;
10 use Gedmo\Mapping\Annotation as Gedmo;
11
12 /**
13 * Tag.
14 *
15 * @XmlRoot("tag")
16 * @ORM\Table(name="`tag`")
17 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
18 * @ExclusionPolicy("all")
19 */
20 class Tag
21 {
22 /**
23 * @var int
24 *
25 * @Expose
26 * @ORM\Column(name="id", type="integer")
27 * @ORM\Id
28 * @ORM\GeneratedValue(strategy="AUTO")
29 */
30 private $id;
31
32 /**
33 * @var string
34 *
35 * @Expose
36 * @ORM\Column(name="label", type="text")
37 */
38 private $label;
39
40 /**
41 * @Gedmo\Slug(fields={"label"})
42 * @ORM\Column(length=128, unique=true)
43 */
44 private $slug;
45
46 /**
47 * @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"})
48 */
49 private $entries;
50
51 /**
52 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="tags")
53 */
54 private $user;
55
56 public function __construct(\Wallabag\UserBundle\Entity\User $user)
57 {
58 $this->user = $user;
59 $this->entries = new ArrayCollection();
60 }
61
62 public function __toString()
63 {
64 return $this->label;
65 }
66
67 /**
68 * Get id.
69 *
70 * @return int
71 */
72 public function getId()
73 {
74 return $this->id;
75 }
76
77 /**
78 * Set label.
79 *
80 * @param string $label
81 *
82 * @return Tag
83 */
84 public function setLabel($label)
85 {
86 $this->label = $label;
87
88 return $this;
89 }
90
91 /**
92 * Get label.
93 *
94 * @return string
95 */
96 public function getLabel()
97 {
98 return $this->label;
99 }
100
101 public function getSlug()
102 {
103 return $this->slug;
104 }
105
106 public function addEntry(Entry $entry)
107 {
108 $this->entries[] = $entry;
109 }
110
111 public function hasEntry($entry)
112 {
113 return $this->entries->contains($entry);
114 }
115
116 /**
117 * @return User
118 */
119 public function getUser()
120 {
121 return $this->user;
122 }
123 }