src/Entity/User.php line 36

  1. <?php
  2. namespace App\Entity;
  3. use App\Enums\CompanyRoleEnum;
  4. use App\Enums\CurrencyTypeEnum;
  5. use App\Enums\UserRoleEnum;
  6. use DateTime;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Serializable;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. use Symfony\Component\Serializer\Annotation\Ignore;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. #[ORM\Table(name: 'fos_user')]
  17. #[ORM\Entity(repositoryClass: 'App\Repository\UserRepository')]
  18. #[UniqueEntity(
  19. fields: ['username', 'email'],
  20. message: 'Nalog sa ovim korisničkim imenom već postoji!',
  21. errorPath: 'email'
  22. ),
  23. UniqueEntity(
  24. fields: ['phoneNumber'],
  25. message: 'Ovaj broj telefona već postoji!',
  26. errorPath: 'phoneNumber'
  27. )
  28. ]
  29. class User implements UserInterface, PasswordAuthenticatedUserInterface
  30. {
  31. public const VRTIC = 1798;
  32. #[ORM\Id]
  33. #[ORM\Column(type: 'integer')]
  34. #[ORM\GeneratedValue(strategy: 'AUTO')]
  35. private int $id;
  36. #[ORM\Column(name: 'username', type: 'string', length: 180)]
  37. private string $username;
  38. #[ORM\Column(name: 'username_canonical', type: 'string', length: 180, unique: true)]
  39. private string $usernameCanonical;
  40. #[ORM\Column(name: 'email', type: 'string', length: 180)]
  41. private string $email;
  42. #[ORM\Column(name: 'email_canonical', type: 'string', length: 180, unique: true)]
  43. private string $emailCanonical;
  44. #[ORM\Column(name: 'enabled', type: 'boolean')]
  45. private bool $enabled;
  46. #[ORM\Column(name: 'paid_bill', type: 'integer', options: ['default' => 1])]
  47. private int $paidBill;
  48. /**
  49. * The salt to use for hashing.
  50. */
  51. #[ORM\Column(name: 'salt', type: 'string', nullable: true)]
  52. private string|null $salt;
  53. /**
  54. * Encrypted password. Must be persisted.
  55. */
  56. #[ORM\Column(name: 'password', type: 'string')]
  57. private string $password;
  58. #[ORM\Column(name: 'last_login', type: 'datetime', nullable: true)]
  59. private DateTime|null $lastLogin;
  60. /**
  61. * Random string sent to the user email address in order to verify it.
  62. */
  63. #[ORM\Column(name: 'confirmation_token', type: 'string', length: 180, unique: true, nullable: true)]
  64. private string|null $confirmationToken;
  65. #[ORM\Column(name: 'password_requested_at', type: 'datetime', nullable: true)]
  66. private DateTime|null $passwordRequestedAt;
  67. /**
  68. * @var array<string>
  69. */
  70. #[ORM\Column(name: 'roles', type: 'array')]
  71. private array $roles;
  72. #[Assert\NotBlank(message: 'PLEASE_ENTER_FIRSTNAME', groups: ['RequireData'])]
  73. #[Assert\Length(
  74. min: 2,
  75. max: 32,
  76. minMessage: 'FIRST_NAME_IS_TOO_SHORT',
  77. maxMessage: 'FIRST_NAME_IS_TOO_LONG',
  78. groups: ['RequireData']
  79. )]
  80. private string|null $plainPassword = null;
  81. #[Assert\NotBlank(message: 'PLEASE_ENTER_FIRSTNAME', groups: ['RequireData'])]
  82. #[Assert\Length(
  83. min: 2,
  84. max: 32,
  85. minMessage: 'FIRST_NAME_IS_TOO_SHORT',
  86. maxMessage: 'FIRST_NAME_IS_TOO_LONG',
  87. groups: ['RequireData']
  88. )]
  89. #[ORM\Column(name: 'firstname', type: 'string', length: 255, nullable: true)]
  90. private string|null $firstname;
  91. #[Assert\NotBlank(message: 'PLEASE_ENTER_LASTNAME', groups: ['RequireData'])]
  92. #[Assert\Length(
  93. min: 2,
  94. max: 32,
  95. minMessage: 'LAST_NAME_IS_TOO_SHORT',
  96. maxMessage: 'LAST_NAME_IS_TOO_LONG',
  97. groups: ['RequireData']
  98. )]
  99. #[ORM\Column(name: 'lastname', type: 'string', length: 255, nullable: true)]
  100. private string|null $lastname;
  101. #[Assert\NotBlank(message: 'MUST_ACCEPT_PRIVACY_POLICY', groups: ['RequireData'])]
  102. #[ORM\Column(name: 'has_accepted_terms', type: 'boolean')]
  103. private bool $hasAcceptedTerms;
  104. #[Assert\Length(max: 50, maxMessage: 'ADDRESS_TOO_LONG')]
  105. #[ORM\Column(name: 'address', type: 'string', nullable: true)]
  106. #[Assert\NotBlank(message: 'FIELD_MUST_NOT_BE_EMPTY', groups: ['RequireData'])]
  107. private string|null $address = null;
  108. #[Assert\Length(max: 4, maxMessage: 'STREETNUMBER_TOO_LONG')]
  109. #[ORM\Column(name: 'streetnumber', type: 'string', nullable: true)]
  110. #[Assert\NotBlank(message: 'FIELD_MUST_NOT_BE_EMPTY', groups: ['RequireData'])]
  111. private string|null $streetNumber;
  112. #[Assert\Length(max: 8, maxMessage: 'ZIP_TOO_LONG')]
  113. #[ORM\Column(name: 'zip', type: 'string', nullable: true)]
  114. #[Assert\NotBlank(message: 'FIELD_MUST_NOT_BE_EMPTY', groups: ['RequireData'])]
  115. private string|null $zip;
  116. #[Assert\Length(max: 100, maxMessage: 'CITY_IS_TOO_LONG', groups: ['RequireData'])]
  117. #[ORM\Column(name: 'city', type: 'string', length: 255, nullable: true)]
  118. #[Assert\NotBlank(message: 'FIELD_MUST_NOT_BE_EMPTY', groups: ['RequireData'])]
  119. private string|null $city = null;
  120. #[ORM\Column(name: 'phone_number', type: 'string', length: 255, nullable: true, unique: true)]
  121. private string|null $phoneNumber = null;
  122. #[ORM\Column(name: 'company_name', type: 'string', length: 255, nullable: true, unique: true)]
  123. private string|null $companyName = null;
  124. #[ORM\Column(name: 'created_at', type: 'datetime')]
  125. private DateTime|null $createdAt = null;
  126. #[ORM\Column(name: 'updated_at', type: 'datetime')]
  127. private DateTime|null $updatedAt = null;
  128. #[ORM\Column(name: 'mat_id', type: 'string', length: 64, nullable: true)]
  129. private string|null $matId = null;
  130. #[ORM\Column(name: 'pib', type: 'string', length: 64, nullable: true)]
  131. private string|null $pib = null;
  132. #[ORM\Column(name: 'company_title', type: 'string', length: 255, nullable: true)]
  133. private string|null $companyTitle;
  134. #[ORM\Column(name: 'license_id', type: 'string', length: 64, nullable: true)]
  135. private string|null $licenseId;
  136. #[ORM\Column(name: 'bank_account', type: 'string', length: 128, nullable: true)]
  137. private string|null $bankAccount = null;
  138. #[ORM\Column(name: 'enable_qr', type: 'boolean', options: ['default' => true])]
  139. private bool $enableQr = true;
  140. /**
  141. * @var Collection<int, Obligation>
  142. */
  143. #[ORM\OneToMany(targetEntity: 'App\Entity\Obligation', mappedBy: 'user')]
  144. #[Ignore]
  145. private Collection $obligations;
  146. #[ORM\Column(name: 'task_notification_email', type: 'string', length: 180, nullable: true)]
  147. private string|null $taskNotificationEmail;
  148. #[ORM\ManyToOne(targetEntity: 'App\Entity\User', cascade: ['persist'])]
  149. #[ORM\JoinColumn(name: 'main_user_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  150. #[Ignore]
  151. private User|null $mainUser = null;
  152. /**
  153. * @var Collection<int, ActionLog>
  154. */
  155. #[ORM\OneToMany(targetEntity: ActionLog::class, mappedBy: 'user')]
  156. #[Ignore]
  157. private Collection $actionLogs;
  158. #[ORM\Column(type: 'string', length: 3, options: ['default' => 'RSD'])]
  159. private string $currency = 'RSD';
  160. public function __construct()
  161. {
  162. $this->enabled = false;
  163. $this->paidBill = 1;
  164. $this->roles = array();
  165. $this->obligations = new ArrayCollection();
  166. $this->actionLogs = new ArrayCollection();
  167. $this->incrementCreatedAt();
  168. }
  169. /**
  170. * @return int
  171. */
  172. public function getId(): int
  173. {
  174. return $this->id;
  175. }
  176. /**
  177. * @return string
  178. */
  179. public function getUsername(): string
  180. {
  181. return $this->username;
  182. }
  183. /**
  184. * @param string $username
  185. */
  186. public function setUsername(string $username): void
  187. {
  188. $this->username = $username;
  189. }
  190. /**
  191. * @return string
  192. */
  193. public function getUsernameCanonical(): string
  194. {
  195. return $this->usernameCanonical;
  196. }
  197. /**
  198. * @param string $usernameCanonical
  199. */
  200. public function setUsernameCanonical(string $usernameCanonical): void
  201. {
  202. $this->usernameCanonical = $usernameCanonical;
  203. }
  204. /**
  205. * @return string
  206. */
  207. public function getEmail(): string
  208. {
  209. return $this->email;
  210. }
  211. /**
  212. * @param string $email
  213. */
  214. public function setEmail(string $email): void
  215. {
  216. $this->setUsername($email);
  217. $this->email = $email;
  218. }
  219. /**
  220. * @return string
  221. */
  222. public function getEmailCanonical(): string
  223. {
  224. return $this->emailCanonical;
  225. }
  226. /**
  227. * @param string $emailCanonical
  228. */
  229. public function setEmailCanonical(string $emailCanonical): void
  230. {
  231. $this->emailCanonical = $emailCanonical;
  232. }
  233. /**
  234. * @return bool
  235. */
  236. public function isEnabled(): bool
  237. {
  238. return $this->enabled;
  239. }
  240. /**
  241. * @return bool
  242. */
  243. public function isSuperAdmin(): bool
  244. {
  245. return $this->hasRole(UserRoleEnum::ROLE_SUPER_ADMIN->value);
  246. }
  247. /**
  248. * @param bool $enabled
  249. */
  250. public function setEnabled(bool $enabled): void
  251. {
  252. $this->enabled = $enabled;
  253. }
  254. /**
  255. * @return string|null
  256. */
  257. public function getSalt(): ?string
  258. {
  259. return $this->salt;
  260. }
  261. /**
  262. * @param string|null $salt
  263. */
  264. public function setSalt(?string $salt): void
  265. {
  266. $this->salt = $salt;
  267. }
  268. /**
  269. * @return string
  270. */
  271. public function getPassword(): string
  272. {
  273. return $this->password;
  274. }
  275. /**
  276. * @param string $password
  277. */
  278. public function setPassword(string $password): void
  279. {
  280. $this->password = $password;
  281. }
  282. /**
  283. * @return DateTime|null
  284. */
  285. public function getLastLogin(): ?DateTime
  286. {
  287. return $this->lastLogin;
  288. }
  289. /**
  290. * @param DateTime|null $lastLogin
  291. */
  292. public function setLastLogin(?DateTime $lastLogin): void
  293. {
  294. $this->lastLogin = $lastLogin;
  295. }
  296. /**
  297. * @return string|null
  298. */
  299. public function getConfirmationToken(): ?string
  300. {
  301. return $this->confirmationToken;
  302. }
  303. /**
  304. * @param string|null $confirmationToken
  305. */
  306. public function setConfirmationToken(?string $confirmationToken): void
  307. {
  308. $this->confirmationToken = $confirmationToken;
  309. }
  310. /**
  311. * @return DateTime|null
  312. */
  313. public function getPasswordRequestedAt(): ?DateTime
  314. {
  315. return $this->passwordRequestedAt;
  316. }
  317. /**
  318. * @param DateTime|null $passwordRequestedAt
  319. */
  320. public function setPasswordRequestedAt(?DateTime $passwordRequestedAt): void
  321. {
  322. $this->passwordRequestedAt = $passwordRequestedAt;
  323. }
  324. /**
  325. * @return string[]
  326. */
  327. public function getRoles(): array
  328. {
  329. $roles = $this->roles;
  330. // we need to make sure to have at least one role
  331. $roles[] = UserRoleEnum::ROLE_DEFAULT->value;
  332. return array_unique($roles);
  333. }
  334. /**
  335. * @param string $role
  336. * @return bool
  337. */
  338. #[Ignore]
  339. public function hasRole(string $role): bool
  340. {
  341. return in_array(strtoupper($role), $this->getRoles(), true);
  342. }
  343. /**
  344. * @param string[] $roles
  345. * @return $this
  346. */
  347. public function setRoles(array $roles): self
  348. {
  349. $this->roles = array();
  350. foreach ($roles as $role) {
  351. $this->addRole($role);
  352. }
  353. return $this;
  354. }
  355. /**
  356. * @param int $ttl
  357. * @return bool
  358. */
  359. #[Ignore]
  360. public function isPasswordRequestNonExpired(int $ttl): bool
  361. {
  362. return $this->getPasswordRequestedAt() instanceof \DateTime &&
  363. $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
  364. }
  365. /**
  366. * @return string|null
  367. */
  368. public function getPlainPassword(): ?string
  369. {
  370. return $this->plainPassword;
  371. }
  372. /**
  373. * @param string|null $plainPassword
  374. */
  375. public function setPlainPassword(?string $plainPassword): void
  376. {
  377. $this->plainPassword = $plainPassword;
  378. }
  379. /**
  380. * @return string|null
  381. */
  382. public function getFirstname(): ?string
  383. {
  384. return $this->firstname;
  385. }
  386. /**
  387. * @param string|null $firstname
  388. */
  389. public function setFirstname(?string $firstname): void
  390. {
  391. $this->firstname = $firstname;
  392. }
  393. /**
  394. * @return string|null
  395. */
  396. public function getLastname(): ?string
  397. {
  398. return $this->lastname;
  399. }
  400. /**
  401. * @param string|null $lastname
  402. */
  403. public function setLastname(?string $lastname): void
  404. {
  405. $this->lastname = $lastname;
  406. }
  407. /**
  408. * @return bool
  409. */
  410. public function getHasAcceptedTerms(): bool
  411. {
  412. return $this->hasAcceptedTerms;
  413. }
  414. /**
  415. * @param bool $hasAcceptedTerms
  416. */
  417. public function setHasAcceptedTerms(bool $hasAcceptedTerms): void
  418. {
  419. $this->hasAcceptedTerms = $hasAcceptedTerms;
  420. }
  421. /**
  422. * @return string|null
  423. */
  424. public function getAddress(): ?string
  425. {
  426. return $this->address;
  427. }
  428. /**
  429. * @param string|null $address
  430. */
  431. public function setAddress(?string $address): void
  432. {
  433. $this->address = $address;
  434. }
  435. /**
  436. * @return string|null
  437. */
  438. public function getStreetnumber(): ?string
  439. {
  440. return $this->streetNumber;
  441. }
  442. /**
  443. * @param string|null $streetNumber
  444. */
  445. public function setStreetNumber(?string $streetNumber): void
  446. {
  447. $this->streetNumber = $streetNumber;
  448. }
  449. /**
  450. * @return string|null
  451. */
  452. public function getZip(): ?string
  453. {
  454. return $this->zip;
  455. }
  456. /**
  457. * @param string|null $zip
  458. */
  459. public function setZip(?string $zip): void
  460. {
  461. $this->zip = $zip;
  462. }
  463. /**
  464. * @return string|null
  465. */
  466. public function getCity(): ?string
  467. {
  468. return $this->city;
  469. }
  470. /**
  471. * @param string|null $city
  472. */
  473. public function setCity(?string $city): void
  474. {
  475. $this->city = $city;
  476. }
  477. /**
  478. * @return string|null
  479. */
  480. public function getPhoneNumber(): ?string
  481. {
  482. return $this->phoneNumber;
  483. }
  484. /**
  485. * @param string|null $phoneNumber
  486. */
  487. public function setPhoneNumber(?string $phoneNumber): void
  488. {
  489. $this->phoneNumber = $phoneNumber;
  490. }
  491. /**
  492. * @return string|null
  493. */
  494. public function getCompanyName(): ?string
  495. {
  496. return $this->companyName;
  497. }
  498. /**
  499. * @param string|null $companyName
  500. */
  501. public function setCompanyName(?string $companyName): void
  502. {
  503. $this->companyName = $companyName;
  504. }
  505. /**
  506. * @return DateTime|null
  507. */
  508. public function getCreatedAt(): ?DateTime
  509. {
  510. return $this->createdAt;
  511. }
  512. /**
  513. * @param DateTime $createdAt
  514. */
  515. public function setCreatedAt(DateTime $createdAt): void
  516. {
  517. $this->createdAt = $createdAt;
  518. }
  519. /**
  520. * @return DateTime
  521. */
  522. public function getUpdatedAt(): DateTime
  523. {
  524. return $this->updatedAt;
  525. }
  526. /**
  527. * @param DateTime $updatedAt
  528. */
  529. public function setUpdatedAt(DateTime $updatedAt): void
  530. {
  531. $this->updatedAt = $updatedAt;
  532. }
  533. #[ORM\PrePersist]
  534. public function incrementCreatedAt(): void
  535. {
  536. if ($this->createdAt === null) {
  537. $this->createdAt = new DateTime();
  538. }
  539. $this->updatedAt = new DateTime();
  540. }
  541. #[ORM\PreUpdate]
  542. public function incrementUpdatedAt(): void
  543. {
  544. $this->updatedAt = new DateTime();
  545. }
  546. /**
  547. * @return string|null
  548. */
  549. public function getMatId(): ?string
  550. {
  551. return $this->matId;
  552. }
  553. /**
  554. * @param string|null $matId
  555. */
  556. public function setMatId(?string $matId): void
  557. {
  558. $this->matId = $matId;
  559. }
  560. /**
  561. * @return string|null
  562. */
  563. public function getPib(): ?string
  564. {
  565. return $this->pib;
  566. }
  567. /**
  568. * @param string|null $pib
  569. */
  570. public function setPib(?string $pib): void
  571. {
  572. $this->pib = $pib;
  573. }
  574. /**
  575. * @return string|null
  576. */
  577. public function getCompanyTitle(): ?string
  578. {
  579. return $this->companyTitle;
  580. }
  581. /**
  582. * @param string|null $companyTitle
  583. */
  584. public function setCompanyTitle(?string $companyTitle): void
  585. {
  586. $this->companyTitle = $companyTitle;
  587. }
  588. /**
  589. * @return string|null
  590. */
  591. public function getLicenseId(): ?string
  592. {
  593. return $this->licenseId;
  594. }
  595. /**
  596. * @param string|null $licenseId
  597. */
  598. public function setLicenseId(?string $licenseId): void
  599. {
  600. $this->licenseId = $licenseId;
  601. }
  602. /**
  603. * @return string|null
  604. */
  605. public function getBankAccount(): ?string
  606. {
  607. return $this->bankAccount;
  608. }
  609. /**
  610. * @param string|null $bankAccount
  611. */
  612. public function setBankAccount(?string $bankAccount): void
  613. {
  614. $this->bankAccount = $bankAccount;
  615. }
  616. /**
  617. * @return bool
  618. */
  619. public function getEnableQr(): bool
  620. {
  621. return $this->enableQr;
  622. }
  623. /**
  624. * @param bool $enableQr
  625. */
  626. public function setEnableQr(bool $enableQr): void
  627. {
  628. $this->enableQr = $enableQr;
  629. }
  630. /**
  631. * @return Collection<int, Obligation>
  632. */
  633. #[Ignore]
  634. public function getObligations(): Collection
  635. {
  636. return $this->obligations;
  637. }
  638. /**
  639. * @param Obligation $obligation
  640. * @return $this
  641. */
  642. public function addObligation(Obligation $obligation): self
  643. {
  644. if (!$this->obligations->contains($obligation)) {
  645. $this->obligations[] = $obligation;
  646. $obligation->setUser($this);
  647. }
  648. return $this;
  649. }
  650. /**
  651. * @param Obligation $obligation
  652. * @return $this
  653. */
  654. public function removeObligation(Obligation $obligation): self
  655. {
  656. if ($this->obligations->contains($obligation)) {
  657. $this->obligations->removeElement($obligation);
  658. if ($obligation->getUser() === $this) {
  659. $obligation->setUser(null);
  660. }
  661. }
  662. return $this;
  663. }
  664. /**
  665. * @return string|null
  666. */
  667. public function getTaskNotificationEmail(): ?string
  668. {
  669. return $this->taskNotificationEmail;
  670. }
  671. /**
  672. * @param string|null $taskNotificationEmail
  673. */
  674. public function setTaskNotificationEmail(?string $taskNotificationEmail): void
  675. {
  676. $this->taskNotificationEmail = $taskNotificationEmail;
  677. }
  678. /**
  679. * @return User|null
  680. */
  681. #[Ignore]
  682. public function getMainUser(): ?User
  683. {
  684. return $this->mainUser;
  685. }
  686. /**
  687. * @param User|null $mainUser
  688. */
  689. #[Ignore]
  690. public function setMainUser(?User $mainUser): void
  691. {
  692. $this->mainUser = $mainUser;
  693. }
  694. /**
  695. * Returns company role or null
  696. * @return string|null
  697. */
  698. public function getCompanyRole(): ?string
  699. {
  700. foreach ($this->getRoles() as $role) {
  701. if (in_array($role, CompanyRoleEnum::getAllValues(), true)) {
  702. return $role;
  703. }
  704. }
  705. return null;
  706. }
  707. /**
  708. * Returns property which is used for createdBy fields of other tables
  709. *
  710. * @return string
  711. */
  712. public function getCreatedByValue(): string
  713. {
  714. return sprintf('%s.%s.', mb_substr($this->getFirstname(), 0, 1), mb_substr($this->getLastname(), 0, 1));
  715. }
  716. /**
  717. * @return User
  718. */
  719. #[Ignore]
  720. public function getSharedCompanyUser(): User
  721. {
  722. return $this->mainUser !== null ? $this->mainUser : $this;
  723. }
  724. /**
  725. * @return array<User>
  726. */
  727. public function getUserAndMainUser(): array
  728. {
  729. $users = [];
  730. $users[] = $this;
  731. if ($this->mainUser) {
  732. $users[] = $this->mainUser;
  733. }
  734. return $users;
  735. }
  736. /**
  737. * @param string $role
  738. * @return $this
  739. */
  740. public function addRole(string $role): self
  741. {
  742. $role = strtoupper($role);
  743. if ($role === UserRoleEnum::ROLE_DEFAULT->value) {
  744. return $this;
  745. }
  746. if (!in_array($role, $this->roles, true)) {
  747. if (in_array($role, CompanyRoleEnum::getAllValues(), true)) {
  748. foreach (CompanyRoleEnum::getAllValues() as $companyRole) {
  749. $this->removeRole($companyRole);
  750. }
  751. }
  752. $this->roles[] = $role;
  753. }
  754. return $this;
  755. }
  756. /**
  757. * @param string $role
  758. * @return $this
  759. */
  760. public function removeRole(string $role): self
  761. {
  762. if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
  763. unset($this->roles[$key]);
  764. $this->roles = array_values($this->roles);
  765. }
  766. return $this;
  767. }
  768. /**
  769. * @return string
  770. */
  771. public function getFullName(): string
  772. {
  773. return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
  774. }
  775. /**
  776. * @return Collection<int, ActionLog>
  777. */
  778. #[Ignore]
  779. public function getActionLogs(): Collection
  780. {
  781. return $this->actionLogs;
  782. }
  783. /**
  784. * @param ActionLog $actionLog
  785. * @return $this
  786. */
  787. public function addActionLog(ActionLog $actionLog): self
  788. {
  789. if (!$this->actionLogs->contains($actionLog)) {
  790. $this->actionLogs[] = $actionLog;
  791. $actionLog->setUser($this);
  792. }
  793. return $this;
  794. }
  795. /**
  796. * @param ActionLog $actionLog
  797. * @return $this
  798. */
  799. public function removeActionLog(ActionLog $actionLog): self
  800. {
  801. if ($this->actionLogs->removeElement($actionLog)) {
  802. // set the owning side to null (unless already changed)
  803. if ($actionLog->getUser() === $this) {
  804. $actionLog->setUser(null);
  805. }
  806. }
  807. return $this;
  808. }
  809. /**
  810. * @return string
  811. */
  812. public function __toString(): string
  813. {
  814. return (string) $this->getUsername();
  815. }
  816. //
  817. // /**
  818. // * @return string
  819. // */
  820. // public function serialize(): string
  821. // {
  822. // return serialize(array(
  823. // $this->password,
  824. // $this->getSalt(),
  825. // $this->usernameCanonical,
  826. // $this->username,
  827. // $this->enabled,
  828. // $this->id,
  829. // $this->email,
  830. // $this->emailCanonical,
  831. // ));
  832. // }
  833. //
  834. // /**
  835. // * @param string $serialized
  836. // */
  837. // public function unserialize($serialized): void
  838. // {
  839. // $data = unserialize($serialized);
  840. //
  841. // if (13 === count($data)) {
  842. // // Unserializing a User object from 1.3.x
  843. // unset($data[4], $data[5], $data[6], $data[9], $data[10]);
  844. // $data = array_values($data);
  845. // } elseif (11 === count($data)) {
  846. // // Unserializing a User from a dev version somewhere between 2.0-alpha3 and 2.0-beta1
  847. // unset($data[4], $data[7], $data[8]);
  848. // $data = array_values($data);
  849. // }
  850. //
  851. // list(
  852. // $this->password,
  853. // $this->salt,
  854. // $this->usernameCanonical,
  855. // $this->username,
  856. // $this->enabled,
  857. // $this->id,
  858. // $this->email,
  859. // $this->emailCanonical
  860. // ) = $data;
  861. // }
  862. public function eraseCredentials(): void
  863. {
  864. $this->setPlainPassword(null);
  865. }
  866. /**
  867. * @param bool $boolean
  868. * @return $this
  869. */
  870. public function setSuperAdmin(bool $boolean): self
  871. {
  872. if ($boolean === true) {
  873. $this->addRole(UserRoleEnum::ROLE_SUPER_ADMIN->value);
  874. } else {
  875. $this->removeRole(UserRoleEnum::ROLE_SUPER_ADMIN->value);
  876. }
  877. return $this;
  878. }
  879. /**
  880. * @return string
  881. */
  882. public function getUserIdentifier(): string
  883. {
  884. return $this->getUsername();
  885. }
  886. /**
  887. * @return bool
  888. */
  889. public function isUserCyrillic(): bool
  890. {
  891. $userArray = ['draganaDjordjevic'];
  892. if (in_array($this->getCompanyName(), $userArray)) {
  893. return true;
  894. }
  895. return false;
  896. }
  897. /**
  898. * @param string $currency
  899. * @return void
  900. */
  901. public function setCurrency(string $currency): void
  902. {
  903. $this->currency = $currency;
  904. }
  905. /**
  906. * @return string
  907. */
  908. public function getCurrency(): string
  909. {
  910. return $this->currency;
  911. }
  912. /**
  913. * @return int
  914. */
  915. public function getPaidBill(): int
  916. {
  917. return $this->paidBill;
  918. }
  919. /**
  920. * @param int $paidBill
  921. */
  922. public function setPaidBill(int $paidBill): void
  923. {
  924. $this->paidBill = $paidBill;
  925. }
  926. }