src/Entity/System/Employee.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System;
  3. use A4BGroup\A4bThemeBundle\Entity\UserInterface as A4BUserInterface;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\HttpFoundation\File\UploadedFile;
  7. /**
  8. * Class Employee
  9. *
  10. * @ORM\Entity(repositoryClass="App\Repository\System\EmployeeRepository")
  11. *
  12. * @ORM\Table(name="ps_employee")
  13. */
  14. class Employee implements A4BUserInterface
  15. {
  16. /**
  17. * @var int
  18. *
  19. * @ORM\Id
  20. *
  21. * @ORM\GeneratedValue(strategy="AUTO")
  22. *
  23. * @ORM\Column(type="integer", name="id_employee", options={"unsigned":true})
  24. */
  25. private $id;
  26. /**
  27. * @var Language
  28. *
  29. * @ORM\ManyToOne(targetEntity="Language")
  30. *
  31. * @ORM\JoinColumn(name="id_lang", referencedColumnName="id_lang")
  32. */
  33. private $language;
  34. /**
  35. * @var string
  36. *
  37. * @ORM\Column(type="string", name="lastname", length=32)
  38. */
  39. private $lastname;
  40. /**
  41. * @var string
  42. *
  43. * @ORM\Column(type="string", name="firstname", length=32)
  44. */
  45. private $firstname;
  46. /**
  47. * @var string
  48. *
  49. * @ORM\Column(type="string", nullable=false, unique=true, length=128)
  50. */
  51. private $email;
  52. /**
  53. * @var string
  54. *
  55. * @ORM\Column(type="string", name="passwd", length=128)
  56. */
  57. private $password;
  58. /**
  59. * @var \DateTime
  60. *
  61. * @ORM\Column(type="datetime", options={"default":"CURRENT_TIMESTAMP"}, name="last_passwd_gen")
  62. */
  63. private $passwordDate;
  64. /**
  65. * @var ArrayCollection<int, AdminAcl>|AdminAcl[]
  66. *
  67. * @ORM\ManyToMany(targetEntity="AdminAcl", inversedBy="employees")
  68. *
  69. * @ORM\JoinTable(name="employee_admin_acl",
  70. * joinColumns={@ORM\JoinColumn(name="employee_id", referencedColumnName="id_employee")},
  71. * inverseJoinColumns={@ORM\JoinColumn(name="admin_acl_id", referencedColumnName="id")}
  72. * )
  73. */
  74. private $routes;
  75. /**
  76. * @ORM\Column(type="boolean", options={"unsigned":true, "default":0})
  77. */
  78. private bool $active = false;
  79. /**
  80. * @ORM\Column(type="datetime", nullable=true)
  81. */
  82. private ?\DateTimeInterface $lastAccess = null;
  83. /**
  84. * @ORM\Column(type="datetime", nullable=true)
  85. */
  86. private ?\DateTimeInterface $dateAdd;
  87. /**
  88. * @ORM\Column(type="datetime", nullable=true)
  89. */
  90. private ?\DateTimeInterface $dateUpd = null;
  91. /**
  92. * @var string[]
  93. *
  94. * @ORM\Column(type="json", nullable=false)
  95. */
  96. protected $roles;
  97. /**
  98. * @var ArrayCollection<int, SynchronisedShopConfiguration>|SynchronisedShopConfiguration[]
  99. *
  100. * @ORM\OneToMany(targetEntity="App\Entity\System\SynchronisedShopConfiguration", mappedBy="employee")
  101. */
  102. private $syncronisedShopConfiguration;
  103. /**
  104. * @var Role[]|ArrayCollection<int, Role>
  105. *
  106. * @ORM\ManyToMany(targetEntity="App\Entity\System\Role", inversedBy="employees")
  107. *
  108. * @ORM\JoinTable(name="employee_role",
  109. * joinColumns={@ORM\JoinColumn(name="employee_id", referencedColumnName="id_employee")},
  110. * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id_role")}
  111. * )
  112. */
  113. private $roleCollection;
  114. /**
  115. * @var OrderReturnLineComment[]|ArrayCollection<int, OrderReturnLineComment>
  116. *
  117. * @ORM\OneToMany(targetEntity="App\Entity\System\OrderReturnLineComment", mappedBy="employee")
  118. */
  119. private $orderReturnLinesComments;
  120. public function __construct()
  121. {
  122. $this->dateAdd = new \DateTime();
  123. $this->passwordDate = new \DateTime();
  124. $this->password = '';
  125. $this->roles = [];
  126. $this->syncronisedShopConfiguration = new ArrayCollection();
  127. $this->roleCollection = new ArrayCollection();
  128. $this->orderReturnLinesComments = new ArrayCollection();
  129. }
  130. public function getId(): int
  131. {
  132. return $this->id;
  133. }
  134. public function setId(int $id): void
  135. {
  136. $this->id = $id;
  137. }
  138. public function getLanguage(): Language
  139. {
  140. return $this->language;
  141. }
  142. public function setLanguage(Language $language): self
  143. {
  144. $this->language = $language;
  145. return $this;
  146. }
  147. public function getLastname(): string
  148. {
  149. return $this->lastname;
  150. }
  151. public function setLastname(string $lastname): self
  152. {
  153. $this->lastname = $lastname;
  154. return $this;
  155. }
  156. /**
  157. * @return string
  158. */
  159. public function getName(): string
  160. {
  161. return $this->firstname;
  162. }
  163. public function setName(string $firstname): self
  164. {
  165. $this->firstname = $firstname;
  166. return $this;
  167. }
  168. public function getEmail(): string
  169. {
  170. return $this->email;
  171. }
  172. public function setEmail(string $email): self
  173. {
  174. $this->email = $email;
  175. return $this;
  176. }
  177. public function getPassword(): string
  178. {
  179. return $this->password;
  180. }
  181. public function setPassword(string $password): self
  182. {
  183. $this->password = $password;
  184. return $this;
  185. }
  186. public function getPasswordDate(): \DateTime
  187. {
  188. return $this->passwordDate;
  189. }
  190. public function setPasswordDate(\DateTime $passwordDate): self
  191. {
  192. $this->passwordDate = $passwordDate;
  193. return $this;
  194. }
  195. public function isEnabled(): bool
  196. {
  197. return $this->active;
  198. }
  199. public function setEnabled(bool $active): self
  200. {
  201. $this->active = $active;
  202. return $this;
  203. }
  204. /**
  205. * @return Role[]|ArrayCollection<int, Role>
  206. */
  207. public function getRoleCollection()
  208. {
  209. return $this->roleCollection;
  210. }
  211. /**
  212. * @param Role[]|ArrayCollection<int, Role> $roles
  213. */
  214. public function setRoleCollection($roles): Employee
  215. {
  216. $this->roleCollection = $roles;
  217. return $this;
  218. }
  219. public function getRoles(): array
  220. {
  221. $roles = $this->roles;
  222. foreach ($this->getRoleCollection() as $role) {
  223. $roleName = $role->getName();
  224. if ($role->isEmployee() && !in_array($roleName, $roles, true)) {
  225. $roles[] = $roleName;
  226. }
  227. }
  228. $roles[] = Role::ROLE_EMPLOYEE;
  229. return \array_unique($roles);
  230. }
  231. public function getSalt(): ?string
  232. {
  233. return null;
  234. }
  235. public function getUsername(): string
  236. {
  237. return $this->email;
  238. }
  239. public function eraseCredentials(): A4BUserInterface
  240. {
  241. return $this;
  242. }
  243. public function getUserIdentifier(): string
  244. {
  245. return (string)$this->getId();
  246. }
  247. public function __toString(): string
  248. {
  249. return $this->firstname.' '.$this->lastname;
  250. }
  251. public function getLastAccess(): ?\DateTimeInterface
  252. {
  253. return $this->lastAccess;
  254. }
  255. public function setLastAccess(?\DateTimeInterface $lastAccess): Employee
  256. {
  257. $this->lastAccess = $lastAccess;
  258. return $this;
  259. }
  260. public function getAvatar(): ?string
  261. {
  262. return null;
  263. }
  264. public function setAvatar(?string $avatar): A4BUserInterface
  265. {
  266. return $this;
  267. }
  268. public function setUploadedFile(?UploadedFile $uploadedFile = null): A4BUserInterface
  269. {
  270. return $this;
  271. }
  272. public function getUploadedFile(): ?UploadedFile
  273. {
  274. return null;
  275. }
  276. public function isEqualTo(A4BUserInterface $user): bool
  277. {
  278. return $this->email === $user->getEmail();
  279. }
  280. public function getDateAdd(): \DateTimeInterface
  281. {
  282. return $this->dateAdd;
  283. }
  284. public function setDateAdd(\DateTimeInterface $dateAdd): A4BUserInterface
  285. {
  286. $this->dateAdd = $dateAdd;
  287. return $this;
  288. }
  289. public function getDateUpd(): ?\DateTimeInterface
  290. {
  291. return $this->dateUpd;
  292. }
  293. public function setDateUpd(?\DateTimeInterface $dateUpd): A4BUserInterface
  294. {
  295. $this->dateUpd = $dateUpd;
  296. return $this;
  297. }
  298. /**
  299. * @param string[] $roles
  300. */
  301. public function setRoles(array $roles): A4BUserInterface
  302. {
  303. $this->roles = $roles;
  304. return $this;
  305. }
  306. /**
  307. * @param string $role
  308. */
  309. public function addRole($role): A4BUserInterface
  310. {
  311. $role = \strtoupper((string)$role);
  312. if (Role::ROLE_EMPLOYEE === $role) {
  313. return $this;
  314. }
  315. if (!\in_array($role, $this->roles, true)) {
  316. $this->roles[] = $role;
  317. }
  318. return $this;
  319. }
  320. /**
  321. * @param string $role
  322. */
  323. public function removeRole($role): A4BUserInterface
  324. {
  325. if (false !== $key = \array_search(\strtoupper((string)$role), $this->roles, true)) {
  326. unset($this->roles[$key]);
  327. $this->roles = \array_values($this->roles);
  328. }
  329. return $this;
  330. }
  331. /**
  332. * @param string $role
  333. */
  334. public function hasRole($role): bool
  335. {
  336. return \in_array(\strtoupper((string)$role), $this->getRoles(), true);
  337. }
  338. public function getPlainPassword(): ?string
  339. {
  340. return null;
  341. }
  342. public function setPlainPassword(string $plainPassword): A4BUserInterface
  343. {
  344. return $this;
  345. }
  346. public function isDeleted(): bool
  347. {
  348. return false;
  349. }
  350. public function setDeleted(bool $deleted): A4BUserInterface
  351. {
  352. return $this;
  353. }
  354. public function getLocale(): ?string
  355. {
  356. return $this->getLanguage()->getIsoCode();
  357. }
  358. public function setLocale(string $locale): A4BUserInterface
  359. {
  360. throw new \Exception('Use setLanguage instead');
  361. }
  362. public function setUsername(string $username): A4BUserInterface
  363. {
  364. $this->setEmail($username);
  365. return $this;
  366. }
  367. /**
  368. * @return AdminAcl[]|ArrayCollection<int, AdminAcl>
  369. */
  370. public function getRoutes()
  371. {
  372. return $this->routes;
  373. }
  374. /**
  375. * @param AdminAcl[]|ArrayCollection<int, AdminAcl> $routes
  376. */
  377. public function setRoutes($routes): Employee
  378. {
  379. $this->routes = $routes;
  380. return $this;
  381. }
  382. public function addRoute(AdminAcl $adminAcl): Employee
  383. {
  384. $this->routes[] = $adminAcl;
  385. return $this;
  386. }
  387. /**
  388. * @return ArrayCollection<int, SynchronisedShopConfiguration>|SynchronisedShopConfiguration[]
  389. */
  390. public function getSyncronisedShopConfiguration()
  391. {
  392. return $this->syncronisedShopConfiguration;
  393. }
  394. /**
  395. * @return ArrayCollection<int, OrderReturnLineComment>|OrderReturnLineComment[]
  396. */
  397. public function getOrderReturnLinesComments()
  398. {
  399. return $this->orderReturnLinesComments;
  400. }
  401. }