aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Entity
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-03-06 21:48:33 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-03-06 21:48:33 +0100
commitf37d1427a1b75f9d7a2e273b2e9fb0e895a769ab (patch)
treee6ea5fb4786e843b970b14d5a96da8c32548a315 /src/Wallabag/CoreBundle/Entity
parent73b774438395d0ed74d0fd863194d2ebfb68d9ce (diff)
parent6e22bd737b2e543c85487864a9a25b0f2d5cc3f2 (diff)
downloadwallabag-f37d1427a1b75f9d7a2e273b2e9fb0e895a769ab.tar.gz
wallabag-f37d1427a1b75f9d7a2e273b2e9fb0e895a769ab.tar.zst
wallabag-f37d1427a1b75f9d7a2e273b2e9fb0e895a769ab.zip
Merge pull request #1110 from wallabag/v2-api-hypermedia
[WIP] API : hypermedia & tags
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity')
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php59
-rw-r--r--src/Wallabag/CoreBundle/Entity/Tag.php40
-rw-r--r--src/Wallabag/CoreBundle/Entity/TagsEntries.php93
-rw-r--r--src/Wallabag/CoreBundle/Entity/User.php34
4 files changed, 105 insertions, 121 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 937213b4..75aeae84 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -2,19 +2,24 @@
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;
8use Hateoas\Configuration\Annotation as Hateoas;
9use JMS\Serializer\Annotation\XmlRoot;
7 10
8/** 11/**
9 * Entry 12 * Entry
10 * 13 *
14 * @XmlRoot("entry")
11 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") 15 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
12 * @ORM\Table(name="entry") 16 * @ORM\Table(name="entry")
13 * @ORM\HasLifecycleCallbacks() 17 * @ORM\HasLifecycleCallbacks()
14 * 18 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
15 */ 19 */
16class Entry 20class Entry
17{ 21{
22 /** @Serializer\XmlAttribute */
18 /** 23 /**
19 * @var integer 24 * @var integer
20 * 25 *
@@ -54,13 +59,6 @@ class Entry
54 private $isStarred = false; 59 private $isStarred = false;
55 60
56 /** 61 /**
57 * @var boolean
58 *
59 * @ORM\Column(name="is_deleted", type="boolean")
60 */
61 private $isDeleted = false;
62
63 /**
64 * @var string 62 * @var string
65 * 63 *
66 * @ORM\Column(name="content", type="text", nullable=true) 64 * @ORM\Column(name="content", type="text", nullable=true)
@@ -121,12 +119,19 @@ class Entry
121 */ 119 */
122 private $user; 120 private $user;
123 121
122 /**
123 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
124 * @ORM\JoinTable(name="entry_tags")
125 */
126 private $tags;
127
124 /* 128 /*
125 * @param User $user 129 * @param User $user
126 */ 130 */
127 public function __construct(User $user) 131 public function __construct(User $user)
128 { 132 {
129 $this->user = $user; 133 $this->user = $user;
134 $this->tags = new ArrayCollection();
130 } 135 }
131 136
132 /** 137 /**
@@ -279,22 +284,6 @@ class Entry
279 /** 284 /**
280 * @return string 285 * @return string
281 */ 286 */
282 public function isDeleted()
283 {
284 return $this->isDeleted;
285 }
286
287 /**
288 * @param string $isDeleted
289 */
290 public function setDeleted($isDeleted)
291 {
292 $this->isDeleted = $isDeleted;
293 }
294
295 /**
296 * @return string
297 */
298 public function getCreatedAt() 287 public function getCreatedAt()
299 { 288 {
300 return $this->createdAt; 289 return $this->createdAt;
@@ -400,4 +389,26 @@ class Entry
400 { 389 {
401 $this->isPublic = $isPublic; 390 $this->isPublic = $isPublic;
402 } 391 }
392
393 /**
394 * @return ArrayCollection<Tag>
395 */
396 public function getTags()
397 {
398 return $this->tags;
399 }
400
401 /**
402 * @param Tag $tag
403 */
404 public function addTag(Tag $tag)
405 {
406 $this->tags[] = $tag;
407 $tag->addEntry($this);
408 }
409
410 public function removeTag(Tag $tag)
411 {
412 $this->tags->removeElement($tag);
413 }
403} 414}
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php
index 31017563..9ae5867c 100644
--- a/src/Wallabag/CoreBundle/Entity/Tag.php
+++ b/src/Wallabag/CoreBundle/Entity/Tag.php
@@ -3,18 +3,25 @@
3namespace Wallabag\CoreBundle\Entity; 3namespace Wallabag\CoreBundle\Entity;
4 4
5use Doctrine\ORM\Mapping as ORM; 5use Doctrine\ORM\Mapping as ORM;
6use JMS\Serializer\Annotation\XmlRoot;
7use JMS\Serializer\Annotation\ExclusionPolicy;
8use JMS\Serializer\Annotation\Expose;
9use Doctrine\Common\Collections\ArrayCollection;
6 10
7/** 11/**
8 * Tag 12 * Tag
9 * 13 *
14 * @XmlRoot("tag")
10 * @ORM\Table(name="tag") 15 * @ORM\Table(name="tag")
11 * @ORM\Entity 16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
17 * @ExclusionPolicy("all")
12 */ 18 */
13class Tag 19class Tag
14{ 20{
15 /** 21 /**
16 * @var integer 22 * @var integer
17 * 23 *
24 * @Expose
18 * @ORM\Column(name="id", type="integer") 25 * @ORM\Column(name="id", type="integer")
19 * @ORM\Id 26 * @ORM\Id
20 * @ORM\GeneratedValue(strategy="AUTO") 27 * @ORM\GeneratedValue(strategy="AUTO")
@@ -24,11 +31,27 @@ class Tag
24 /** 31 /**
25 * @var string 32 * @var string
26 * 33 *
34 * @Expose
27 * @ORM\Column(name="label", type="text") 35 * @ORM\Column(name="label", type="text")
28 */ 36 */
29 private $label; 37 private $label;
30 38
31 /** 39 /**
40 * @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"})
41 */
42 private $entries;
43
44 /**
45 * @ORM\ManyToOne(targetEntity="User", inversedBy="tags")
46 */
47 private $user;
48
49 public function __construct(User $user)
50 {
51 $this->user = $user;
52 $this->entries = new ArrayCollection();
53 }
54 /**
32 * Get id 55 * Get id
33 * 56 *
34 * @return integer 57 * @return integer
@@ -58,6 +81,19 @@ class Tag
58 */ 81 */
59 public function getLabel() 82 public function getLabel()
60 { 83 {
61 return $this->value; 84 return $this->label;
85 }
86
87 public function addEntry(Entry $entry)
88 {
89 $this->entries[] = $entry;
90 }
91
92 /**
93 * @return User
94 */
95 public function getUser()
96 {
97 return $this->user;
62 } 98 }
63} 99}
diff --git a/src/Wallabag/CoreBundle/Entity/TagsEntries.php b/src/Wallabag/CoreBundle/Entity/TagsEntries.php
deleted file mode 100644
index 22826387..00000000
--- a/src/Wallabag/CoreBundle/Entity/TagsEntries.php
+++ /dev/null
@@ -1,93 +0,0 @@
1<?php
2
3namespace Wallabag\CoreBundle\Entity;
4
5use Doctrine\ORM\Mapping as ORM;
6
7/**
8 * TagsEntries
9 *
10 * @ORM\Table(name="tags_entries")
11 * @ORM\Entity
12 */
13class TagsEntries
14{
15 /**
16 * @var integer
17 *
18 * @ORM\Column(name="id", type="integer")
19 * @ORM\Id
20 * @ORM\GeneratedValue(strategy="AUTO")
21 */
22 private $id;
23
24 /**
25 * @var integer
26 *
27 * @ORM\Column(name="entry_id", type="integer")
28 */
29 private $entryId;
30
31 /**
32 * @var integer
33 *
34 * @ORM\Column(name="tag_id", type="integer")
35 */
36 private $tagId;
37
38 /**
39 * Get id
40 *
41 * @return integer
42 */
43 public function getId()
44 {
45 return $this->id;
46 }
47
48 /**
49 * Set entryId
50 *
51 * @param integer $entryId
52 * @return TagsEntries
53 */
54 public function setEntryId($entryId)
55 {
56 $this->entryId = $entryId;
57
58 return $this;
59 }
60
61 /**
62 * Get entryId
63 *
64 * @return integer
65 */
66 public function getEntryId()
67 {
68 return $this->entryId;
69 }
70
71 /**
72 * Set tagId
73 *
74 * @param integer $tagId
75 * @return TagsEntries
76 */
77 public function setTagId($tagId)
78 {
79 $this->tagId = $tagId;
80
81 return $this;
82 }
83
84 /**
85 * Get tagId
86 *
87 * @return integer
88 */
89 public function getTagId()
90 {
91 return $this->tagId;
92 }
93}
diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php
index ed5cfe53..f05c8760 100644
--- a/src/Wallabag/CoreBundle/Entity/User.php
+++ b/src/Wallabag/CoreBundle/Entity/User.php
@@ -7,6 +7,8 @@ use Doctrine\ORM\Mapping as ORM;
7use Symfony\Component\Security\Core\User\UserInterface; 7use Symfony\Component\Security\Core\User\UserInterface;
8use Symfony\Component\Security\Core\User\AdvancedUserInterface; 8use Symfony\Component\Security\Core\User\AdvancedUserInterface;
9use Symfony\Component\Validator\Constraints as Assert; 9use Symfony\Component\Validator\Constraints as Assert;
10use JMS\Serializer\Annotation\ExclusionPolicy;
11use JMS\Serializer\Annotation\Expose;
10 12
11/** 13/**
12 * User 14 * User
@@ -14,12 +16,14 @@ use Symfony\Component\Validator\Constraints as Assert;
14 * @ORM\Table(name="user") 16 * @ORM\Table(name="user")
15 * @ORM\Entity 17 * @ORM\Entity
16 * @ORM\HasLifecycleCallbacks() 18 * @ORM\HasLifecycleCallbacks()
19 * @ExclusionPolicy("all")
17 */ 20 */
18class User implements AdvancedUserInterface, \Serializable 21class User implements AdvancedUserInterface, \Serializable
19{ 22{
20 /** 23 /**
21 * @var integer 24 * @var integer
22 * 25 *
26 * @Expose
23 * @ORM\Column(name="id", type="integer") 27 * @ORM\Column(name="id", type="integer")
24 * @ORM\Id 28 * @ORM\Id
25 * @ORM\GeneratedValue(strategy="AUTO") 29 * @ORM\GeneratedValue(strategy="AUTO")
@@ -97,10 +101,17 @@ class User implements AdvancedUserInterface, \Serializable
97 */ 101 */
98 private $config; 102 private $config;
99 103
104 /**
105 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
106 */
107 private $tags;
108
100 public function __construct() 109 public function __construct()
101 { 110 {
102 $this->salt = md5(uniqid(null, true)); 111 $this->isActive = true;
103 $this->entries = new ArrayCollection(); 112 $this->salt = md5(uniqid(null, true));
113 $this->entries = new ArrayCollection();
114 $this->tags = new ArrayCollection();
104 } 115 }
105 116
106 /** 117 /**
@@ -275,6 +286,25 @@ class User implements AdvancedUserInterface, \Serializable
275 } 286 }
276 287
277 /** 288 /**
289 * @param Entry $entry
290 *
291 * @return User
292 */
293 public function addTag(Tag $tag)
294 {
295 $this->tags[] = $tag;
296
297 return $this;
298 }
299
300 /**
301 * @return ArrayCollection<Tag>
302 */
303 public function getTags()
304 {
305 return $this->tags;
306 }
307 /**
278 * @inheritDoc 308 * @inheritDoc
279 */ 309 */
280 public function eraseCredentials() 310 public function eraseCredentials()