aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/UserBundle')
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
index ed6ce331..aba76ca7 100644
--- a/src/Wallabag/UserBundle/Entity/User.php
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection;
6use Doctrine\ORM\Mapping as ORM; 6use Doctrine\ORM\Mapping as ORM;
7use JMS\Serializer\Annotation\Groups; 7use JMS\Serializer\Annotation\Groups;
8use JMS\Serializer\Annotation\XmlRoot; 8use JMS\Serializer\Annotation\XmlRoot;
9use JMS\Serializer\Annotation\Accessor;
9use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; 10use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
10use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; 11use Scheb\TwoFactorBundle\Model\TrustedComputerInterface;
11use FOS\UserBundle\Model\User as BaseUser; 12use FOS\UserBundle\Model\User as BaseUser;
@@ -36,7 +37,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
36 * @ORM\Id 37 * @ORM\Id
37 * @ORM\GeneratedValue(strategy="AUTO") 38 * @ORM\GeneratedValue(strategy="AUTO")
38 * 39 *
39 * @Groups({"user_api"}) 40 * @Groups({"user_api", "user_api_with_client"})
40 */ 41 */
41 protected $id; 42 protected $id;
42 43
@@ -45,21 +46,21 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
45 * 46 *
46 * @ORM\Column(name="name", type="text", nullable=true) 47 * @ORM\Column(name="name", type="text", nullable=true)
47 * 48 *
48 * @Groups({"user_api"}) 49 * @Groups({"user_api", "user_api_with_client"})
49 */ 50 */
50 protected $name; 51 protected $name;
51 52
52 /** 53 /**
53 * @var string 54 * @var string
54 * 55 *
55 * @Groups({"user_api"}) 56 * @Groups({"user_api", "user_api_with_client"})
56 */ 57 */
57 protected $username; 58 protected $username;
58 59
59 /** 60 /**
60 * @var string 61 * @var string
61 * 62 *
62 * @Groups({"user_api"}) 63 * @Groups({"user_api", "user_api_with_client"})
63 */ 64 */
64 protected $email; 65 protected $email;
65 66
@@ -68,7 +69,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
68 * 69 *
69 * @ORM\Column(name="created_at", type="datetime") 70 * @ORM\Column(name="created_at", type="datetime")
70 * 71 *
71 * @Groups({"user_api"}) 72 * @Groups({"user_api", "user_api_with_client"})
72 */ 73 */
73 protected $createdAt; 74 protected $createdAt;
74 75
@@ -77,7 +78,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
77 * 78 *
78 * @ORM\Column(name="updated_at", type="datetime") 79 * @ORM\Column(name="updated_at", type="datetime")
79 * 80 *
80 * @Groups({"user_api"}) 81 * @Groups({"user_api", "user_api_with_client"})
81 */ 82 */
82 protected $updatedAt; 83 protected $updatedAt;
83 84
@@ -97,7 +98,8 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
97 private $authCode; 98 private $authCode;
98 99
99 /** 100 /**
100 * @var bool Enabled yes/no 101 * @var bool
102 *
101 * @ORM\Column(type="boolean") 103 * @ORM\Column(type="boolean")
102 */ 104 */
103 private $twoFactorAuthentication = false; 105 private $twoFactorAuthentication = false;
@@ -108,10 +110,20 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
108 private $trusted; 110 private $trusted;
109 111
110 /** 112 /**
113 * @var ArrayCollection
114 *
111 * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) 115 * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"})
112 */ 116 */
113 protected $clients; 117 protected $clients;
114 118
119 /**
120 * @see getFirstClient() below
121 *
122 * @Groups({"user_api_with_client"})
123 * @Accessor(getter="getFirstClient")
124 */
125 protected $default_client;
126
115 public function __construct() 127 public function __construct()
116 { 128 {
117 parent::__construct(); 129 parent::__construct();
@@ -288,4 +300,16 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
288 { 300 {
289 return $this->clients; 301 return $this->clients;
290 } 302 }
303
304 /**
305 * Only used by the API when creating a new user it'll also return the first client (which was also created at the same time).
306 *
307 * @return Client
308 */
309 public function getFirstClient()
310 {
311 if (!empty($this->clients)) {
312 return $this->clients->first();
313 }
314 }
291} 315}