X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FUserBundle%2FEntity%2FUser.php;h=a3320bbcaeb14f2471f14e797f578be8917fc482;hb=9114615adcee0255273c7e91d6d8e55f57fc3d6f;hp=ed6ce3319c5b89f47781c40961e860a4e71a3f68;hpb=c07ec4b6820723165bd7b832681ad6d43ad605d0;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index ed6ce331..a3320bbc 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,21 +46,21 @@ 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; @@ -68,7 +69,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * * @ORM\Column(name="created_at", type="datetime") * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $createdAt; @@ -77,7 +78,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * * @ORM\Column(name="updated_at", type="datetime") * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $updatedAt; @@ -91,13 +92,36 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf */ protected $config; + /** + * @var ArrayCollection + * + * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\SiteCredential", mappedBy="user", cascade={"remove"}) + */ + protected $site_credentials; + + /** + * @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 +131,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 +144,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf */ public function timestamps() { - if (is_null($this->createdAt)) { + if (null === $this->createdAt) { $this->createdAt = new \DateTime(); } @@ -288,4 +307,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(); + } + } }