3 namespace Wallabag\CoreBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity
;
8 use Symfony\Component\Security\Core\User\UserInterface
;
9 use Symfony\Component\Security\Core\User\AdvancedUserInterface
;
10 use Symfony\Component\Validator\Constraints
as Assert
;
11 use JMS\Serializer\Annotation\ExclusionPolicy
;
12 use JMS\Serializer\Annotation\Expose
;
13 use FOS\UserBundle\Model\User
as BaseUser
;
18 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
20 * @ORM\HasLifecycleCallbacks()
21 * @ExclusionPolicy("all")
23 * @UniqueEntity("email")
24 * @UniqueEntity("username")
26 class User
extends BaseUser
implements AdvancedUserInterface
, \Serializable
32 * @ORM\Column(name="id", type="integer")
34 * @ORM\GeneratedValue(strategy="AUTO")
41 * @ORM\Column(name="name", type="text", nullable=true)
48 * @ORM\Column(name="created_at", type="datetime")
55 * @ORM\Column(name="updated_at", type="datetime")
60 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
65 * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
70 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
74 public function __construct()
76 parent
::__construct();
77 $this->entries
= new ArrayCollection();
78 $this->tags
= new ArrayCollection();
85 public function timestamps()
87 if (is_null($this->createdAt
)) {
88 $this->createdAt
= new \
DateTime();
91 $this->updatedAt
= new \
DateTime();
97 * @param string $password
101 public function setPassword($password)
103 if (!$password && 0 === strlen($password)) {
107 $this->password
= sha1($password.$this->getUsername().$this->getSalt());
115 * @param string $name
119 public function setName($name)
131 public function getName()
139 public function getCreatedAt()
141 return $this->createdAt
;
147 public function getUpdatedAt()
149 return $this->updatedAt
;
153 * @param Entry $entry
157 public function addEntry(Entry
$entry)
159 $this->entries
[] = $entry;
165 * @return ArrayCollection<Entry>
167 public function getEntries()
169 return $this->entries
;
173 * @param Entry $entry
177 public function addTag(Tag
$tag)
179 $this->tags
[] = $tag;
185 * @return ArrayCollection<Tag>
187 public function getTags()
192 public function isEqualTo(UserInterface
$user)
194 return $this->username
=== $user->getUsername();
200 * @param \Wallabag\CoreBundle\Entity\Config $config
204 public function setConfig(\Wallabag\CoreBundle\Entity\Config
$config = null)
206 $this->config
= $config;
214 * @return \Wallabag\CoreBundle\Entity\Config
216 public function getConfig()
218 return $this->config
;