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