src/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. /**
  9. * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  10. * @ORM\Table(name="appuser")
  11. */
  12. class User implements UserInterface, \Serializable
  13. {
  14. /**
  15. * @ORM\Id()
  16. * @ORM\GeneratedValue()
  17. * @ORM\Column(type="integer")
  18. */
  19. private $id;
  20. /**
  21. * @ORM\Column(type="string", length=255)
  22. */
  23. private $firstname;
  24. /**
  25. * @ORM\Column(type="string", length=255, nullable=true)
  26. */
  27. private $lastname;
  28. /**
  29. * @ORM\Column(type="string", length=255)
  30. */
  31. private $email;
  32. /**
  33. * @var string The hashed password
  34. * @ORM\Column(type="text")
  35. */
  36. private $password;
  37. /**
  38. * @ORM\Column(type="json")
  39. */
  40. private $roles = [];
  41. /**
  42. * @ORM\Column(type="integer")
  43. */
  44. private $permission_level;
  45. /**
  46. * @ORM\Column(type="datetime", nullable=true)
  47. */
  48. private $last_login;
  49. /**
  50. * @ORM\Column(type="integer")
  51. */
  52. private $status;
  53. /**
  54. * @ORM\Column(type="datetime")
  55. */
  56. private $date_updated;
  57. /**
  58. * @ORM\ManyToMany(targetEntity="App\Entity\Organisation", inversedBy="users")
  59. */
  60. private $organisations;
  61. /**
  62. * @ORM\ManyToMany(targetEntity="App\Entity\Team", inversedBy="users")
  63. */
  64. private $teams;
  65. public function __construct()
  66. {
  67. $this->organisations = new ArrayCollection();
  68. $this->teams = new ArrayCollection();
  69. }
  70. public function getId(): ?int
  71. {
  72. return $this->id;
  73. }
  74. public function getFirstname(): ?string
  75. {
  76. return $this->firstname;
  77. }
  78. public function setFirstname(string $firstname): self
  79. {
  80. $this->firstname = $firstname;
  81. return $this;
  82. }
  83. public function getLastname(): ?string
  84. {
  85. return $this->lastname;
  86. }
  87. public function setLastname(?string $lastname): self
  88. {
  89. $this->lastname = $lastname;
  90. return $this;
  91. }
  92. public function getEmail(): ?string
  93. {
  94. return $this->email;
  95. }
  96. public function setEmail(string $email): self
  97. {
  98. $this->email = $email;
  99. return $this;
  100. }
  101. /**
  102. * @see UserInterface
  103. */
  104. public function getPassword(): string
  105. {
  106. return (string) $this->password;
  107. }
  108. public function setPassword(string $password): self
  109. {
  110. $this->password = $password;
  111. return $this;
  112. }
  113. /**
  114. * A visual identifier that represents this user.
  115. *
  116. * @see UserInterface
  117. */
  118. public function getUsername(): string
  119. {
  120. //return (string) $this->email;
  121. return (string) "Username";
  122. }
  123. /**
  124. * @see UserInterface
  125. */
  126. public function getRoles(): array
  127. {
  128. $roles = $this->roles;
  129. // guarantee every user at least has ROLE_USER
  130. $roles[] = 'ROLE_USER';
  131. return array_unique($roles);
  132. }
  133. public function setRoles(array $roles): self
  134. {
  135. $this->roles = $roles;
  136. return $this;
  137. }
  138. public function getPermissionLevel(): ?int
  139. {
  140. return $this->permission_level;
  141. }
  142. public function setPermissionLevel(int $permission_level): self
  143. {
  144. $this->permission_level = $permission_level;
  145. return $this;
  146. }
  147. public function getLastLogin(): ?\DateTimeInterface
  148. {
  149. return $this->last_login;
  150. }
  151. public function setLastLogin(?\DateTimeInterface $last_login): self
  152. {
  153. $this->last_login = $last_login;
  154. return $this;
  155. }
  156. public function getStatus(): ?int
  157. {
  158. return $this->status;
  159. }
  160. public function setStatus(int $status): self
  161. {
  162. $this->status = $status;
  163. return $this;
  164. }
  165. public function getDateUpdated(): ?\DateTimeInterface
  166. {
  167. return $this->date_updated;
  168. }
  169. public function setDateUpdated(\DateTimeInterface $date_updated): self
  170. {
  171. $this->date_updated = $date_updated;
  172. return $this;
  173. }
  174. /**
  175. * @see UserInterface
  176. */
  177. public function getSalt()
  178. {
  179. // not needed when using the "bcrypt" algorithm in security.yaml
  180. }
  181. /**
  182. * @see UserInterface
  183. */
  184. public function eraseCredentials()
  185. {
  186. // If you store any temporary, sensitive data on the user, clear it here
  187. // $this->plainPassword = null;
  188. }
  189. /**
  190. * @return Collection|Organisation[]
  191. */
  192. public function getOrganisations(): Collection
  193. {
  194. //echo $this->getStatus();
  195. return $this->organisations;
  196. }
  197. public function addOrganisation(Organisation $organisation): self
  198. {
  199. if (!$this->organisations->contains($organisation)) {
  200. $this->organisations[] = $organisation;
  201. }
  202. return $this;
  203. }
  204. public function removeOrganisation(Organisation $organisation): self
  205. {
  206. if ($this->organisations->contains($organisation)) {
  207. $this->organisations->removeElement($organisation);
  208. }
  209. return $this;
  210. }
  211. /**
  212. * @return Collection|Team[]
  213. */
  214. public function getTeams(): Collection
  215. {
  216. //echo $this->getStatus();
  217. return $this->teams;
  218. }
  219. public function addTeam(Team $team): self
  220. {
  221. if (!$this->teams->contains($team)) {
  222. $this->teams[] = $team;
  223. }
  224. return $this;
  225. }
  226. public function removeTeam(Team $team): self
  227. {
  228. if ($this->teams->contains($team)) {
  229. $this->teams->removeElement($team);
  230. }
  231. return $this;
  232. }
  233. public function serialize()
  234. {
  235. $toBeSerialised = array(
  236. $this->id,
  237. $this->getEmail(),
  238. $this->password,
  239. // see section on salt below
  240. // $this->salt,
  241. );
  242. //var_dump($toBeSerialised);
  243. return serialize($toBeSerialised);
  244. }
  245. public function unserialize($serialized)
  246. {
  247. // echo "User-unserialize:";
  248. // var_dump(unserialize($serialized));
  249. // echo "<br>";
  250. list (
  251. $this->id,
  252. $this->email,
  253. $this->password,
  254. // see section on salt below
  255. // $this->salt
  256. ) = unserialize($serialized, ['allowed_classes' => [self::class]]);
  257. }
  258. }