X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2FWallabag%2FUserBundle%2FEntity%2FUser.php;h=20aca29837776bae9fc6ababf1b6000f069fd5d0;hb=f808b01692a835673f328d7221ba8c212caa9b61;hp=1ff3046a8c798a226e5964d8ebdde28b170a3040;hpb=5709ecb36809fb009446a11a758232bbe8f264e4;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 1ff3046a..20aca298 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -4,11 +4,12 @@ namespace Wallabag\UserBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use FOS\UserBundle\Model\User as BaseUser; +use JMS\Serializer\Annotation\Accessor; use JMS\Serializer\Annotation\Groups; use JMS\Serializer\Annotation\XmlRoot; use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; -use FOS\UserBundle\Model\User as BaseUser; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\UserInterface; use Wallabag\ApiBundle\Entity\Client; @@ -36,7 +37,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $id; @@ -45,39 +46,39 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * * @ORM\Column(name="name", type="text", nullable=true) * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $name; /** * @var string * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $username; /** * @var string * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $email; /** - * @var date + * @var \DateTime * * @ORM\Column(name="created_at", type="datetime") * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $createdAt; /** - * @var date + * @var \DateTime * * @ORM\Column(name="updated_at", type="datetime") * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $updatedAt; @@ -91,13 +92,29 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf */ protected $config; + /** + * @var ArrayCollection + * + * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) + */ + protected $clients; + + /** + * @see getFirstClient() below + * + * @Groups({"user_api_with_client"}) + * @Accessor(getter="getFirstClient") + */ + protected $default_client; + /** * @ORM\Column(type="integer", nullable=true) */ private $authCode; /** - * @var bool Enabled yes/no + * @var bool + * * @ORM\Column(type="boolean") */ private $twoFactorAuthentication = false; @@ -107,11 +124,6 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf */ private $trusted; - /** - * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) - */ - protected $clients; - public function __construct() { parent::__construct(); @@ -125,7 +137,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf */ public function timestamps() { - if (is_null($this->createdAt)) { + if (null === $this->createdAt) { $this->createdAt = new \DateTime(); } @@ -157,7 +169,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf } /** - * @return string + * @return \DateTime */ public function getCreatedAt() { @@ -165,7 +177,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf } /** - * @return string + * @return \DateTime */ public function getUpdatedAt() { @@ -288,4 +300,16 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf { return $this->clients; } + + /** + * 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). + * + * @return Client + */ + public function getFirstClient() + { + if (!empty($this->clients)) { + return $this->clients->first(); + } + } }