Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

UserBuilder.php 2.9KB

pirms 3 gadiem
pirms 2 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 2 gadiem
pirms 3 gadiem
pirms 2 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 2 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 2 gadiem
pirms 3 gadiem
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Lc\SovBundle\Builder\User;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Model\Address\AddressInterface;
  5. use Lc\SovBundle\Doctrine\EntityInterface;
  6. use Lc\SovBundle\Doctrine\Extension\BlameableInterface;
  7. use Lc\SovBundle\Factory\User\UserFactory;
  8. use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
  9. use Lc\SovBundle\Model\Ticket\TicketInterface;
  10. use Lc\SovBundle\Model\User\UserInterface;
  11. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  12. use Lc\SovBundle\Repository\User\UserStore;
  13. use Lc\SovBundle\Solver\User\UserSolver;
  14. class UserBuilder
  15. {
  16. protected EntityManagerInterface $entityManager;
  17. protected UserStore $userStore;
  18. protected UserSolver $userSolver;
  19. protected UserFactory $userFactory;
  20. public function __construct(EntityManagerInterface $entityManager, UserStore $userStore, UserSolver $userSolver, UserFactory $userFactory)
  21. {
  22. $this->entityManager = $entityManager;
  23. $this->userStore = $userStore;
  24. $this->userSolver = $userSolver;
  25. $this->userFactory = $userFactory;
  26. }
  27. public function create(string $email, string $password, array $roles = [])
  28. {
  29. $user = $this->userFactory->create();
  30. $user->setEmail($email);
  31. $user->setPassword($password);
  32. $user->setRoles($roles);
  33. $this->entityManager->create($user);
  34. $this->entityManager->flush();
  35. return $user;
  36. }
  37. public function setNewsletter(UserInterface $user, NewsletterInterface $newsletter, bool $subscribeNewsletter): void
  38. {
  39. if ($subscribeNewsletter) {
  40. $user->addNewsletter($newsletter);
  41. } else {
  42. $user->removeNewsletter($newsletter);
  43. }
  44. $this->entityManager->persist($user);
  45. $this->entityManager->flush();
  46. }
  47. public function initBlameableSystem(EntityInterface $entity)
  48. {
  49. $userSystem = $this->userStore->getOneByDevAlias('system');
  50. $this->initBlameable($entity, $userSystem);
  51. return $entity;
  52. }
  53. public function initBlameableUpdatedSystem(EntityInterface $entity)
  54. {
  55. $userSystem = $this->userStore->getOneByDevAlias('system');
  56. $this->initBlameableUpdated($entity, $userSystem);
  57. return $entity;
  58. }
  59. public function initBlameable(EntityInterface $entity, UserInterface $user)
  60. {
  61. if ($entity instanceof BlameableInterface) {
  62. $entity->setCreatedBy($user);
  63. }
  64. $this->initBlameableUpdated($entity, $user);
  65. }
  66. public function initBlameableUpdated(EntityInterface $entity, UserInterface $user)
  67. {
  68. if ($entity instanceof BlameableInterface) {
  69. $entity->setUpdatedBy($user);
  70. }
  71. }
  72. public function setLastLogin(?UserInterface $user)
  73. {
  74. if ($user instanceof UserInterface) {
  75. $user->setLastLogin(new \DateTime());
  76. $this->entityManager->update($user);
  77. $this->entityManager->flush();
  78. }
  79. }
  80. }