diff --git a/old/src/PointToolsBundle/Entity/User.php b/old/src/PointToolsBundle/Entity/User.php deleted file mode 100644 index c219388..0000000 --- a/old/src/PointToolsBundle/Entity/User.php +++ /dev/null @@ -1,230 +0,0 @@ -id = $id; - $this->login = $login; - $this->name = $name; - $this->createdAt = $createdAt ?: new \DateTime(); - - $this->subscribers = new ArrayCollection(); - $this->subscriptions = new ArrayCollection(); - $this->newSubscriberEvents = new ArrayCollection(); - } - - /** - * @ORM\PreUpdate - */ - public function preUpdate(): void - { - $this->updatedAt = new \DateTime(); - } - - public function getId(): int - { - return $this->id; - } - - - public function getLogin(): string - { - return $this->login; - } - - public function getName(): ?string - { - return $this->name; - } - - public function updateLoginAndName(string $login, ?string $name): self - { - $this->login = $login; - $this->name = $name; - - return $this; - } - - public function addSubscriber(Subscription $subscribers): self - { - $this->subscribers[] = $subscribers; - - return $this; - } - - public function removeSubscriber(Subscription $subscribers) - { - $this->subscribers->removeElement($subscribers); - } - - /** - * @return Subscription[]|ArrayCollection - */ - public function getSubscribers(): iterable - { - return $this->subscribers; - } - - /** - * @return Subscription[]|ArrayCollection - */ - public function getSubscriptions(): iterable - { - return $this->subscriptions; - } - - public function addNewSubscriberEvent(SubscriptionEvent $newSubscriberEvents): self - { - $this->newSubscriberEvents[] = $newSubscriberEvents; - - return $this; - } - - /** - * @return SubscriptionEvent[]|ArrayCollection - */ - public function getNewSubscriberEvents(): iterable - { - return $this->newSubscriberEvents; - } - - public function getCreatedAt(): \DateTime - { - return $this->createdAt; - } - - public function getUpdatedAt(): ?\DateTime - { - return $this->updatedAt; - } - - public function updatePrivacy(?bool $public, ?bool $whitelistOnly): void - { - $this->public = $public; - $this->whitelistOnly = $whitelistOnly; - } - - public function isPublic(): ?bool - { - return $this->public; - } - - public function isWhitelistOnly(): ?bool - { - return $this->whitelistOnly; - } - - public function isRemoved(): bool - { - return $this->removed; - } - - public function markAsRemoved(): void - { - $this->removed = true; - } - - public function restore(): void - { - $this->removed = false; - } -} diff --git a/src/Entity/User.php b/src/Entity/User.php new file mode 100644 index 0000000..c24999c --- /dev/null +++ b/src/Entity/User.php @@ -0,0 +1,178 @@ + false])] + private bool $public = false; + + #[ORM\Column(name: 'whitelist_only', type: 'boolean', nullable: false, options: ['default' => false])] + private bool $whitelistOnly = false; + + #[ORM\OneToMany(mappedBy: 'author', targetEntity: Subscription::class, fetch: 'EXTRA_LAZY')] + private ArrayCollection $subscribers; + + #[ORM\OneToMany(mappedBy: 'subscriber', targetEntity: Subscription::class, fetch: 'EXTRA_LAZY')] + private ArrayCollection $subscriptions; + + #[ORM\OneToMany(mappedBy: 'author', targetEntity: SubscriptionEvent::class, fetch: 'EXTRA_LAZY')] + private ArrayCollection $newSubscriberEvents; + + #[ORM\Column(name: 'is_removed', type: 'boolean', options: ['default' => false])] + private bool $removed = false; + + public function __construct( + int $id, + \DateTime $createdAt = null, + string $login = null, + string $name = null + ) { + $this->id = $id; + $this->login = $login; + $this->name = $name; + $this->createdAt = $createdAt ?: new \DateTime(); + + $this->subscribers = new ArrayCollection(); + $this->subscriptions = new ArrayCollection(); + $this->newSubscriberEvents = new ArrayCollection(); + } + + #[ORM\PreUpdate] + public function preUpdate(): void + { + $this->updatedAt = new \DateTime(); + } + + public function getId(): int + { + return $this->id; + } + + public function getLogin(): string + { + return $this->login; + } + + public function getName(): ?string + { + return $this->name; + } + + public function updateLoginAndName(string $login, ?string $name): self + { + $this->login = $login; + $this->name = $name; + + return $this; + } + + public function addSubscriber(Subscription $subscribers): self + { + $this->subscribers[] = $subscribers; + + return $this; + } + + public function removeSubscriber(Subscription $subscribers) + { + $this->subscribers->removeElement($subscribers); + } + + /** @return Subscription[]|ArrayCollection */ + public function getSubscribers(): ArrayCollection + { + return $this->subscribers; + } + + /** @return Subscription[]|ArrayCollection */ + public function getSubscriptions(): ArrayCollection + { + return $this->subscriptions; + } + + public function addNewSubscriberEvent(SubscriptionEvent $newSubscriberEvents): self + { + $this->newSubscriberEvents[] = $newSubscriberEvents; + + return $this; + } + + /** @return SubscriptionEvent[]|ArrayCollection */ + public function getNewSubscriberEvents(): ArrayCollection + { + return $this->newSubscriberEvents; + } + + public function getCreatedAt(): \DateTime + { + return $this->createdAt; + } + + public function getUpdatedAt(): ?\DateTime + { + return $this->updatedAt; + } + + public function updatePrivacy(?bool $public, ?bool $whitelistOnly): void + { + $this->public = $public; + $this->whitelistOnly = $whitelistOnly; + } + + public function isPublic(): ?bool + { + return $this->public; + } + + public function isWhitelistOnly(): bool + { + return $this->whitelistOnly; + } + + public function isRemoved(): bool + { + return $this->removed; + } + + public function markAsRemoved(): void + { + $this->removed = true; + } + + public function restore(): void + { + $this->removed = false; + } +} diff --git a/old/src/PointToolsBundle/Repository/UserRepository.php b/src/Repository/UserRepository.php similarity index 77% rename from old/src/PointToolsBundle/Repository/UserRepository.php rename to src/Repository/UserRepository.php index 22d7100..24c69e5 100644 --- a/old/src/PointToolsBundle/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -1,16 +1,35 @@ + * + * @method User|null find($id, $lockMode = null, $lockVersion = null) + * @method User|null findOneBy(array $criteria, array $orderBy = null) + * @method User[] findAll() + * @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class UserRepository extends ServiceEntityRepository { - public function add(User $entity) + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, User::class); + } + + public function save(User $entity, bool $flush = false): void { $this->getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } } public function findActiveUserWithSubscribers(int $id): ?User @@ -29,9 +48,7 @@ class UserRepository extends EntityRepository ; } - /** - * Case-insensitive user search - */ + /** Case-insensitive user search */ public function findUserByLogin(string $login): ?User { $qb = $this->createQueryBuilder('u'); @@ -75,9 +92,7 @@ class UserRepository extends EntityRepository return $qb->select('COUNT(u)')->getQuery()->getSingleScalarResult(); } - /** - * @return User[] - */ + /** @return User[] */ public function findUserSubscribersById(int $id): array { $qb = $this->createQueryBuilder('u'); @@ -124,4 +139,4 @@ class UserRepository extends EntityRepository return $result; } -} \ No newline at end of file +}