src/Entity/Profile/Profile.php line 77

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-03-19
  5.  * Time: 15:36
  6.  */
  7. namespace App\Entity\Profile;
  8. use AngelGamez\TranslatableBundle\Entity\TranslatableValue;
  9. //use ApiPlatform\Core\Annotation\ApiProperty;
  10. use App\Entity\Account\Advertiser;
  11. use App\Entity\ApartmentsPricing;
  12. use App\Entity\ContainsDomainEvents;
  13. use App\Entity\Account\Customer;
  14. use App\Entity\DomainEventsRecorderTrait;
  15. use App\Entity\ExpressPricing;
  16. use App\Entity\IProvidesServices;
  17. use App\Entity\Location\City;
  18. use App\Entity\Location\MapCoordinate;
  19. use App\Entity\Location\Station;
  20. use App\Entity\Messengers;
  21. use App\Entity\PhoneCallRestrictions;
  22. use App\Entity\Profile\Comment\CommentByCustomer;
  23. use App\Entity\Profile\Confirmation\ModerationRequest;
  24. use App\Entity\Sales\Profile\AdBoardPlacement;
  25. use App\Entity\Sales\Profile\PlacementHiding;
  26. use App\Entity\Sales\Profile\TopPlacement;
  27. use App\Entity\Saloon\Saloon;
  28. use App\Entity\ProvidedServiceTrait;
  29. use App\Entity\TakeOutPricing;
  30. use App\Helper\TopCardTrait;
  31. use App\Repository\ProfileRepository;
  32. use Carbon\Carbon;
  33. use Carbon\CarbonImmutable;
  34. use Doctrine\Common\Collections\ArrayCollection;
  35. use Doctrine\Common\Collections\Collection;
  36. use Doctrine\ORM\Mapping as ORM;
  37. use Doctrine\ORM\Mapping\Index;
  38. //use ApiPlatform\Core\Annotation\ApiResource;
  39. //use ApiPlatform\Core\Annotation\ApiFilter;
  40. //use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  41. //use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\RangeFilter;
  42. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  43. use Symfony\Component\Serializer\Annotation\Groups;
  44. use Gedmo\Mapping\Annotation as Gedmo;
  45. use App\Validator\Constraints\ValidPhoneForCountry as ValidPhoneForCountryAssert;
  46. use App\Validator\Constraints\PhoneNotBlack as PhoneNotBlackAssert;
  47. /**
  48.  * ApiResource(collectionOperations={"get"}, itemOperations={"get"}, normalizationContext={"groups"={"profile"}}, attributes={"pagination_client_enabled"=true, "pagination_client_items_per_page"=true})
  49.  * ApiFilter(SearchFilter::class, properties={"city": "exact", "providedServices": "exact"})
  50.  * ApiFilter(RangeFilter::class, properties={"personParameters.age", "personParameters.height", "personParameters.weight", "personParameters.breastSize", "apartmentsPricing.oneHourPrice"})
  51.  * @ValidPhoneForCountryAssert/ProtocolClass
  52.  * @PhoneNotBlackAssert/ProtocolClass
  53.  */
  54. #[Gedmo\SoftDeleteable(fieldName: "deletedAt", timeAware: true)]
  55. #[ORM\Table(name: 'profiles')]
  56. #[Index(name: 'idx_deleted_at', columns: ['deleted_at'])]
  57. #[Index(name: 'idx_created_at', columns: ['created_at'])]
  58. #[Index(name: 'idx_gender', columns: ['person_gender'])]
  59. #[Index(name: 'idx_apartments_one_hour_price', columns: ['apartments_one_hour_price'])]
  60. #[Index(name: 'idx_is_dummy', columns: ['is_dummy'])]
  61. #[Index(name: 'idx_city_deleted', columns: ['city_id', 'deleted_at'])]
  62. #[Index(name: 'idx_city_deleted_moderation', columns: ['city_id', 'deleted_at', 'moderation_status'])]
  63. #[Index(name: 'idx_city_masseur_deleted', columns: ['city_id', 'is_masseur', 'deleted_at'])]
  64. #[Index(name: 'idx_city_masseur_deleted_moderation', columns: ['city_id', 'is_masseur', 'deleted_at', 'moderation_status'])]
  65. #[Index(name: 'idx_city_deleted_gender', columns: ['city_id', 'deleted_at', 'person_gender'])]
  66. #[Index(name: 'idx_city_deleted_moderation_gender', columns: ['city_id', 'deleted_at', 'moderation_status', 'person_gender'])]
  67. #[Index(name: 'idx_city_masseur_deleted_gender', columns: ['city_id', 'is_masseur', 'deleted_at', 'person_gender'])]
  68. #[Index(name: 'idx_city_masseur_deleted_moderation_gender', columns: ['city_id', 'is_masseur', 'deleted_at', 'moderation_status', 'person_gender'])]
  69. #[Index(name: 'idx_saloon', columns: ['saloon_id'])]
  70. #[ORM\Entity(repositoryClass: ProfileRepository::class)]
  71. #[ORM\HasLifecycleCallbacks]
  72. class Profile implements ContainsDomainEvents, IProvidesServices
  73. {
  74.     use SoftDeleteableEntity;
  75.     use DomainEventsRecorderTrait;
  76.     use ProvidedServiceTrait;
  77.     use TopCardTrait;
  78.     const MODERATION_STATUS_NOT_PASSED = 0;
  79.     const MODERATION_STATUS_APPROVED = 1;
  80.     const MODERATION_STATUS_WAITING = 2;
  81.     const MODERATION_STATUS_REJECTED = 3;
  82.     #[ORM\Id]
  83.     #[ORM\Column(name: 'id', type: 'integer')]
  84.     #[ORM\GeneratedValue(strategy: 'AUTO')]
  85.     #[Groups(['preview', 'listing'])]
  86.     protected int $id;
  87.     #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true)]
  88.     #[ORM\ManyToOne(targetEntity: Advertiser::class, inversedBy: 'profiles')]
  89.     protected ?Advertiser $owner;
  90.     #[ORM\Column(name: 'is_dummy', type: 'boolean', options: ['default' => 0])]
  91.     protected bool $dummy = false;
  92.     /** @var TopPlacement[] */
  93.     #[ORM\OneToMany(targetEntity: TopPlacement::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  94.     protected Collection $topPlacements;
  95.     #[ORM\OneToOne(targetEntity: AdBoardPlacement::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  96.     protected ?AdBoardPlacement $adBoardPlacement = null;
  97.     #[ORM\OneToOne(targetEntity: PlacementHiding::class, mappedBy: 'profile', cascade: ['all'])]
  98.     protected ?PlacementHiding $placementHiding = null;
  99.     #[ORM\Column(name: 'uri_identity', type: 'string', length: 64)]
  100.     #[Groups(['preview', 'listing'])]
  101.     protected string $uriIdentity;
  102.     #[ORM\Column(name: 'name', type: 'translatable')]
  103.     #[Groups(['preview', 'listing'])]
  104.     protected TranslatableValue $name;
  105.     #[ORM\Column(name: 'description', type: 'translatable')]
  106.     #[Groups('preview')]
  107.     protected ?TranslatableValue $description = null;
  108.     #[ORM\Embedded(class: PersonParameters::class, columnPrefix: 'person_')]
  109.     #[Groups(['preview', 'listing'])]
  110.     protected PersonParameters $personParameters;
  111.     /** var ProfileService[] */
  112.     #[ORM\OneToMany(targetEntity: ProfileService::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  113.     #[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'profiles')]
  114.     #[Groups(['preview', 'listing'])]
  115.     protected Collection $providedServices;
  116.     #[ORM\OneToMany(targetEntity: ProfileProvidedInventoryItem::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  117.     #[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'profiles')]
  118.     #[Groups(['preview', 'listing'])]
  119.     protected Collection $providedInventoryItems;
  120.     /** @var int[] */
  121.     #[ORM\Column(name: 'client_types', type: 'simple_array', nullable: true)]
  122.     #[Groups('preview')]
  123.     protected ?array $clientTypes;
  124.     #[ORM\Column(name: 'phone_number', type: 'string', length: 24)]
  125.     #[Groups(['preview', 'listing'])]
  126.     protected string $phoneNumber;
  127.     #[ORM\Embedded(class: Messengers::class, columnPrefix: false)]
  128.     #[Groups(['preview', 'listing'])]
  129.     protected ?Messengers $messengers = null;
  130.     #[ORM\Embedded(class: PhoneCallRestrictions::class, columnPrefix: false)]
  131.     #[Groups('preview')]
  132.     protected ?PhoneCallRestrictions $phoneCallRestrictions = null;
  133.     #[ORM\Column(name: 'is_masseur', type: 'boolean')]
  134.     #[Groups(['preview', 'listing'])]
  135.     protected bool $masseur = false;
  136.     #[ORM\Embedded(class: ClientRestrictions::class, columnPrefix: false)]
  137.     #[Groups('preview')]
  138.     protected ?ClientRestrictions $clientRestrictions = null;
  139.     #[ORM\Embedded(class: ApartmentsPricing::class, columnPrefix: false)]
  140.     #[Groups('preview')]
  141.     protected ?ApartmentsPricing $apartmentsPricing = null;
  142.     #[ORM\Embedded(class: TakeOutPricing::class, columnPrefix: false)]
  143.     #[Groups('preview')]
  144.     protected ?TakeOutPricing $takeOutPricing = null;
  145.     #[ORM\Embedded(class: ExpressPricing::class, columnPrefix: false)]
  146.     #[Groups('preview')]
  147.     protected ?ExpressPricing $expressPricing = null;
  148.     #[ORM\Embedded(class: CarPricing::class, columnPrefix: false)]
  149.     #[Groups('preview')]
  150.     protected ?CarPricing $carPricing = null;
  151.     #[ORM\Column(name: 'extra_charge', type: 'integer', nullable: true)]
  152.     #[Groups('preview')]
  153.     protected ?int $extraCharge;
  154.     #[ORM\Column(name: 'prepayment', type: 'boolean', nullable: true)]
  155.     #[Groups('preview')]
  156.     protected ?bool $prepayment = null;
  157.     #[ORM\Column(name: 'prepayment_amount', type: 'integer', nullable: true)]
  158.     #[Groups('preview')]
  159.     protected ?int $prepaymentAmount = null;
  160.     #[ORM\Column(name: 'prepayment_comment', type: 'string', length: 512, nullable: true)]
  161.     #[Groups('preview')]
  162.     protected ?string $prepaymentComment = null;
  163.     /** @var Photo[] */
  164.     #[ORM\OneToMany(targetEntity: Photo::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  165.     #[Groups('preview')]
  166.     protected Collection $photos;
  167.     /** @var Selfie[] */
  168.     #[ORM\OneToMany(targetEntity: Selfie::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  169.     #[Groups('preview')]
  170.     protected Collection $selfies;
  171.     /** @var Video[] */
  172.     #[ORM\OneToMany(targetEntity: Video::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  173.     #[Groups('preview')]
  174.     protected Collection $videos;
  175.     #[ORM\OneToMany(targetEntity: FileProcessingTask::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  176.     protected Collection $processingFiles;
  177.     #[ORM\OneToOne(targetEntity: AdminApprovalPhoto::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  178.     protected ?AdminApprovalPhoto $adminApprovalPhoto = null;
  179.     #[ORM\OneToOne(targetEntity: Avatar::class, mappedBy: 'profile', cascade: ['all'], orphanRemoval: true)]
  180.     #[Groups(['preview', 'listing'])]
  181.     protected ?Avatar $avatar = null;
  182.     /** @var CommentByCustomer[] */
  183.     #[ORM\OneToMany(targetEntity: CommentByCustomer::class, mappedBy: 'profile')]
  184.     #[Groups('preview')]
  185.     protected Collection $comments;
  186.     #[ORM\Column(name: 'is_approved', type: 'boolean')]
  187.     #[Groups(['preview', 'listing'])]
  188.     protected bool $approved = false;
  189.     #[ORM\Column(name: 'moderation_status', type: 'integer')]
  190.     #[Groups('preview')]
  191.     protected int $moderationStatus = 0;
  192.     #[ORM\JoinColumn(name: 'city_id', referencedColumnName: 'id')]
  193.     #[ORM\ManyToOne(targetEntity: City::class)]
  194.     #[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'profiles')]
  195.     #[Groups(['preview', 'listing'])]
  196.     protected City $city;
  197.     /** @var Station[] */
  198.     //, indexBy="id"
  199.     #[ORM\JoinTable(name: 'profile_stations')]
  200.     #[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id')]
  201.     #[ORM\InverseJoinColumn(name: 'station_id', referencedColumnName: 'id')]
  202.     #[ORM\ManyToMany(targetEntity: Station::class)]
  203.     #[Groups(['preview', 'listing'])]
  204.     #[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'profiles')]
  205.     protected Collection $stations;
  206.     /** @var Collection<int, ProfileName> */
  207.     #[ORM\JoinTable(name: 'profile_profile_names')]
  208.     #[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
  209.     #[ORM\InverseJoinColumn(name: 'profile_name_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
  210.     #[ORM\ManyToMany(targetEntity: ProfileName::class, inversedBy: 'profiles')]
  211.     protected Collection $profileNames;
  212.     #[ORM\Embedded(class: MapCoordinate::class, columnPrefix: false)] // ApiProperty()
  213.     #[Groups(['preview', 'listing'])]
  214.     protected ?MapCoordinate $mapCoordinate;
  215.     #[ORM\Column(name: 'created_at', type: 'datetimetz_immutable', nullable: true)]
  216.     #[Groups('preview')]
  217.     protected ?\DateTimeImmutable $createdAt;
  218.     #[Gedmo\Timestampable(on: "change", field: ["name", "description", "personParameters", "providedServices", "clientTypes", "phoneNumber", "messengers", "phoneCallrestrictions", "masseur", "clientRestrictions", "apartmentsPricing", "takeOutPricing", "expressPricing", "carPricing", "extraCharge", "prepayment", "prepaymentAmount", "prepaymentComment", "photos", "selfies", "videos", "avatar", "stations", "mapCoordinate"])]
  219.     #[ORM\Column(name: 'updated_at', type: 'datetimetz_immutable', nullable: true)]
  220.     #[Groups('preview')]
  221.     protected ?\DateTimeImmutable $updatedAt;
  222.     #[ORM\Column(name: 'mautic_stale_30d_sent_at', type: 'datetimetz_immutable', nullable: true)]
  223.     private ?\DateTimeImmutable $mauticStale30dSentAt = null;
  224.     #[ORM\Column(name: 'inactivated_at', type: 'datetimetz_immutable', nullable: true)]
  225.     protected ?\DateTimeImmutable $inactivatedAt;
  226.     private bool $draft = false;
  227.     #[ORM\Column(name: 'seo', type: 'json', nullable: true)]
  228.     #[Groups(['preview', 'listing'])]
  229.     private ?array $seo = null;
  230.     #[ORM\ManyToOne(targetEntity: Station::class)]
  231.     #[ORM\JoinColumn(name: 'primary_station_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  232.     #[Groups(['preview', 'listing'])]
  233.     #[ORM\Cache(usage: 'READ_ONLY')]
  234.     private ?Station $primaryStation = null;
  235.     #[ORM\ManyToOne(targetEntity: Saloon::class, inversedBy: 'profiles')]
  236.     #[ORM\JoinColumn(name: 'saloon_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  237.     private ?Saloon $saloon = null;
  238.     #[ORM\Column(type: 'smallint', options: ['default' => 0])]
  239.     private int $deleteMode = 0;
  240.     protected function __construct(?\DateTimeImmutable $createdAt)
  241.     {
  242.         $this->draft = true;
  243.         $this->createdAt = $createdAt;
  244.         $this->photos = new ArrayCollection();
  245.         $this->selfies = new ArrayCollection();
  246.         $this->videos = new ArrayCollection();
  247.         $this->processingFiles = new ArrayCollection();
  248.         $this->comments = new ArrayCollection();
  249.         $this->topPlacements = new ArrayCollection();
  250.         $this->providedServices = new ArrayCollection();
  251.         $this->providedInventoryItems = new ArrayCollection();
  252.         $this->stations = new ArrayCollection();
  253.         $this->profileNames = new ArrayCollection();
  254.         $this->inactivatedAt = CarbonImmutable::now();
  255.     }
  256.     public static function draft(?\DateTimeImmutable $createdAt = null, ?bool $dummy = null): self
  257.     {
  258.         $profile = new static($createdAt);
  259.         if (null !== $dummy)
  260.             $profile->dummy = $dummy;
  261.         return $profile;
  262.     }
  263.     public static function create(string $uriIdentity, ?\DateTimeImmutable $createdAt = null): self
  264.     {
  265.         $profile = new static($createdAt);
  266.         $profile->defineUriIdentity($uriIdentity);
  267.         $profile->toggleMasseur(false);
  268.         return $profile;
  269.     }
  270.     public function defineUriIdentity(string $uriIdentity): void
  271.     {
  272.         if (!$this->isDraft()) {
  273.             throw new \DomainException('Profile is already created and can\'t change its URI.');
  274.         }
  275.         $this->uriIdentity = $uriIdentity;
  276.         $this->draft = false;
  277.     }
  278.     public function isDraft(): bool
  279.     {
  280.         return $this->draft;
  281.     }
  282.     public function toggleMasseur(bool $isMasseur): void
  283.     {
  284.         if ($this->masseur !== $isMasseur && (null !== $this->adBoardPlacement && false == $this->adBoardPlacement->getType()->isFree())) {
  285.             throw new \DomainException('Impossible to toggle profile type while it is displaying on adboard.');
  286.         }
  287.         $this->masseur = $isMasseur;
  288.     }
  289.     public static function createMasseur(string $uriIdentity, ?\DateTimeImmutable $createdAt = null): self
  290.     {
  291.         $profile = new static($createdAt);
  292.         $profile->defineUriIdentity($uriIdentity);
  293.         $profile->toggleMasseur(true);
  294.         return $profile;
  295.     }
  296.     public function isOwnedBy(Advertiser $account): bool
  297.     {
  298.         return $account->getId() === $this->owner->getId();
  299.     }
  300.     public function getId(): int
  301.     {
  302.         return $this->id;
  303.     }
  304.     public function setBio(TranslatableValue $name, TranslatableValue $description): void
  305.     {
  306.         $this->name = $name;
  307.         $this->description = $description;
  308.     }
  309.     public function setLocation(City $city, $stations, ?MapCoordinate $mapCoordinate): void
  310.     {
  311.         if (!$this->isDraft() && !$this->city->equals($city)) {
  312.             throw new \DomainException('City change for a saved profile is forbidden.');
  313.         }
  314.         $this->city = $city;
  315.         $this->changeStations($stations);
  316.         $this->normalizePrimaryStation();
  317.         $this->mapCoordinate = $mapCoordinate;
  318.     }
  319.     public function recoverCity(City $city, string $uriIdentity): void
  320.     {
  321.         $this->city = $city;
  322.         $this->uriIdentity = $uriIdentity;
  323.     }
  324.     protected function changeStations($stations)
  325.     {
  326.         if (null === $stations)
  327.             return;
  328.         if (false === is_array($stations) && false === is_iterable($stations))
  329.             throw new \InvalidArgumentException('Stations list should be either an array or an ArrayCollection');
  330.         $stationsArray = is_iterable($stations) && !is_array($stations) ? iterator_to_array($stations) : $stations;
  331.         $stations = [];
  332.         foreach ($stationsArray as $station) {
  333.             $stations[$station->getId()] = $station;
  334.         }
  335.         $stationIds = array_map(function (Station $station): int {
  336.             return $station->getId();
  337.         }, $stations);
  338.         $existingStationIds = $this->stations->map(function (Station $station): int {
  339.             return $station->getId();
  340.         })->getValues();
  341.         $stationIdsToAdd = array_diff($stationIds, $existingStationIds);
  342.         $stationIdsToRemove = array_diff($existingStationIds, $stationIds);
  343.         foreach ($stationIdsToAdd as $stationId) {
  344.             $this->stations->add($stations[$stationId]);
  345.         }
  346.         foreach ($this->stations as $station) {
  347.             if (in_array($station->getId(), $stationIdsToRemove, true)) {
  348.                 $this->stations->removeElement($station);
  349.             }
  350.         }
  351.     }
  352.     public function normalizePrimaryStation(): void
  353.     {
  354.         if ($this->stations->isEmpty()) {
  355.             $this->primaryStation = null;
  356.             return;
  357.         }
  358.         if ($this->primaryStation === null || !$this->stations->contains($this->primaryStation)) {
  359.             $this->primaryStation = $this->stations->first();
  360.         }
  361.     }
  362.     public function setEnabledProvidedServices($services): void
  363.     {
  364.         if (null !== $services) {
  365.             if (is_array($services)) {
  366.                 $services = new ArrayCollection($services);
  367.             } elseif (!$services instanceof ArrayCollection) {
  368.                 if (is_iterable($services)) {
  369.                     $services = new ArrayCollection(iterator_to_array($services));
  370.                 } else {
  371.                     throw new \InvalidArgumentException('Services list should be either an array or an ArrayCollection');
  372.                 }
  373.             }
  374.             $this->providedServices = $services;
  375.         }
  376.     }
  377.     public function getProvidedInventoryItems(): Collection
  378.     {
  379.         return $this->providedInventoryItems;
  380.     }
  381.     public function getProvidedInventoryItemsGroupedByType(): array
  382.     {
  383.         $items = $this->providedInventoryItems->toArray();
  384.         usort(
  385.             $items,
  386.             function (ProfileProvidedInventoryItem $left, ProfileProvidedInventoryItem $right): int {
  387.                 return [
  388.                     ProfileInventoryItemType::getSortOrder($left->getItem()->getType()),
  389.                     $left->getItem()->getSort(),
  390.                     $left->getItem()->getId(),
  391.                 ] <=> [
  392.                     ProfileInventoryItemType::getSortOrder($right->getItem()->getType()),
  393.                     $right->getItem()->getSort(),
  394.                     $right->getItem()->getId(),
  395.                 ];
  396.             }
  397.         );
  398.         $groupedItems = [];
  399.         foreach ($items as $providedItem) {
  400.             $groupedItems[$providedItem->getItem()->getType()][] = $providedItem;
  401.         }
  402.         return $groupedItems;
  403.     }
  404.     public function removeProvidedInventoryItem(ProfileProvidedInventoryItem $providedItem): void
  405.     {
  406.         $this->providedInventoryItems->removeElement($providedItem);
  407.     }
  408.     public function provideInventoryItem(ProfileProvidedInventoryItem $providedItem): void
  409.     {
  410.         $existingSameItem = $this->providedInventoryItems->filter(
  411.             function (ProfileProvidedInventoryItem $existingProvidedItem) use ($providedItem): bool {
  412.                 return $existingProvidedItem->getItem()->getId() === $providedItem->getItem()->getId();
  413.             }
  414.         )->first();
  415.         if ($existingSameItem instanceof ProfileProvidedInventoryItem) {
  416.             $existingSameItem->updateComment($providedItem->getComment());
  417.             return;
  418.         }
  419.         $this->providedInventoryItems->add($providedItem);
  420.     }
  421.     public function setPhoneCallOptions(string $phoneNumber, ?PhoneCallRestrictions $restrictions, ?Messengers $messengers): void
  422.     {
  423.         $this->phoneNumber = $phoneNumber;
  424.         $this->phoneCallRestrictions = $restrictions;
  425.         $this->messengers = $messengers;
  426.     }
  427.     public function getSaloon(): ?Saloon
  428.     {
  429.         return $this->saloon;
  430.     }
  431.     public function attachToSaloon(?Saloon $saloon): void
  432.     {
  433.         $this->saloon = $saloon;
  434.     }
  435.     public function detachFromSaloon(): void
  436.     {
  437.         $this->attachToSaloon(null);
  438.     }
  439.     public function setPricing(?ApartmentsPricing $apartmentsPricing, ?TakeOutPricing $takeOutPricing, ?int $extraCharge, ?ExpressPricing $expressPricing = null, ?CarPricing $carPricing = null): void
  440.     {
  441.         $this->apartmentsPricing = $apartmentsPricing;
  442.         $this->takeOutPricing = $takeOutPricing;
  443.         $this->extraCharge = $extraCharge;
  444.         $this->expressPricing = $expressPricing;
  445.         $this->carPricing = $carPricing;
  446.     }
  447.     public function setPrepaymentOptions(?bool $prepayment, ?int $prepaymentAmount, ?string $prepaymentComment): void
  448.     {
  449.         $this->prepayment = $prepayment;
  450.         if ($prepayment !== true) {
  451.             $this->prepaymentAmount = null;
  452.             $this->prepaymentComment = null;
  453.             return;
  454.         }
  455.         $this->prepaymentAmount = $prepaymentAmount;
  456.         $this->prepaymentComment = $prepaymentComment;
  457.     }
  458.     public function isApproved(): bool
  459.     {
  460.         return $this->approved;
  461.     }
  462.     public function approve(): void
  463.     {
  464.         $this->approved = true;
  465.     }
  466.     public function unApprove(): void
  467.     {
  468.         $this->approved = false;
  469.     }
  470.     public function getOwner(): ?Advertiser
  471.     {
  472.         return $this->owner;
  473.     }
  474.     public function setOwner(Advertiser $owner): void
  475.     {
  476.         $this->owner = $owner;
  477.     }
  478.     public function hasOwner(): bool
  479.     {
  480.         return null !== $this->owner;
  481.     }
  482.     public function getTopPlacements(): Collection
  483.     {
  484.         return $this->topPlacements;
  485.     }
  486.     public function addTopPlacement(TopPlacement $topPlacement): void
  487.     {
  488.         $this->topPlacements->add($topPlacement);
  489.     }
  490.     public function getAdBoardPlacement(): ?AdBoardPlacement
  491.     {
  492.         return $this->adBoardPlacement;
  493.     }
  494.     public function setAdBoardPlacement(AdBoardPlacement $adBoardPlacement): void
  495.     {
  496.         $this->adBoardPlacement = $adBoardPlacement;
  497.     }
  498.     /**
  499.      * Анкета оплачена и выводится в общих списках на сайте
  500.      * или в ТОПе, то есть "АКТИВНА"
  501.      */
  502.     public function isActive(): bool
  503.     {
  504.         return null !== $this->adBoardPlacement || $this->hasRunningTopPlacement();
  505.     }
  506.     public function hasRunningTopPlacement(): bool
  507.     {
  508.         $now = new \DateTimeImmutable('now');
  509.         foreach ($this->topPlacements as /** @var TopPlacement $topPlacement */ $topPlacement) {
  510.             if ($topPlacement->getPlacedAt() <= $now && $now <= $topPlacement->getExpiresAt())
  511.                 return true;
  512.         }
  513.         return false;
  514.     }
  515.     public function getUriIdentity(): string
  516.     {
  517.         return $this->uriIdentity;
  518.     }
  519.     public function getName(): TranslatableValue
  520.     {
  521.         return $this->name;
  522.     }
  523.     public function getDescription(): ?TranslatableValue
  524.     {
  525.         return $this->description;
  526.     }
  527.     public function getPersonParameters(): PersonParameters
  528.     {
  529.         return $this->personParameters;
  530.     }
  531.     public function setPersonParameters(PersonParameters $personParameters): void
  532.     {
  533.         $this->personParameters = $personParameters;
  534.     }
  535.     public function getPhoneNumber(): string
  536.     {
  537.         return $this->phoneNumber;
  538.     }
  539.     //TODO return type
  540.     public function getPhoneCallRestrictions(): ?PhoneCallRestrictions
  541.     {
  542.         return $this->phoneCallRestrictions;
  543.     }
  544.     public function isMasseur(): bool
  545.     {
  546.         return $this->masseur;
  547.     }
  548.     //TODO return type
  549.     public function getClientRestrictions(): ?ClientRestrictions
  550.     {
  551.         return $this->clientRestrictions;
  552.     }
  553.     //TODO return type
  554.     public function setClientRestrictions(?ClientRestrictions $restrictions): void
  555.     {
  556.         $this->clientRestrictions = $restrictions;
  557.     }
  558.     //TODO return type
  559.     public function getApartmentsPricing(): ?ApartmentsPricing
  560.     {
  561.         return $this->apartmentsPricing;
  562.     }
  563.     public function getTakeOutPricing(): ?TakeOutPricing
  564.     {
  565.         return $this->takeOutPricing;
  566.     }
  567.     public function getExtraCharge(): ?int
  568.     {
  569.         return $this->extraCharge;
  570.     }
  571.     public function isPrepayment(): ?bool
  572.     {
  573.         return $this->prepayment;
  574.     }
  575.     public function isWithoutPrepayment(): bool
  576.     {
  577.         return $this->prepayment === false;
  578.     }
  579.     public function getPrepaymentAmount(): ?int
  580.     {
  581.         return $this->prepaymentAmount;
  582.     }
  583.     public function getPrepaymentComment(): ?string
  584.     {
  585.         return $this->prepaymentComment;
  586.     }
  587.     public function addPhoto(string $path, bool $isMain): Photo
  588.     {
  589.         $photos = $this->getPhotos();
  590.         $found = $photos->filter(function (Photo $photo) use ($path): bool {
  591.             return $path === $photo->getPath();
  592.         });
  593.         if (!$found->isEmpty())
  594.             return $found->first();
  595.         if (true === $isMain) {
  596.             $photos->forAll(function ($index, Photo $photo): true {
  597.                 $photo->unsetMain();
  598.                 return true;
  599.             });
  600.         }
  601.         $photo = new Photo($this, $path, $isMain);
  602.         $this->photos->add($photo);
  603.         return $photo;
  604.     }
  605.     /**
  606.      * @return Photo[]
  607.      */
  608.     public function getPhotos(): Collection
  609.     {
  610.         return $this->photos->filter(function ($mediaFile): bool {
  611.             return get_class($mediaFile) == Photo::class;
  612.         });
  613.     }
  614.     public function removePhoto(string $path): bool
  615.     {
  616.         foreach ($this->getPhotos() as $photo) {
  617.             if ($path === $photo->getPath()) {
  618.                 $this->photos->removeElement($photo);
  619.                 return true;
  620.             }
  621.         }
  622.         return false;
  623.     }
  624.     public function getMainPhotoOrFirstPhoto(): ?Photo
  625.     {
  626.         $photos = $this->getPhotos();
  627.         if ($photos->isEmpty()) {
  628.             return null;
  629.         }
  630.         $mainPhoto = $this->getMainPhoto();
  631.         if (null === $mainPhoto) {
  632.             $mainPhoto = $photos->first();
  633.         }
  634.         return $mainPhoto;
  635.     }
  636.     public function getMainPhoto(): ?Photo
  637.     {
  638.         $photos = $this->getPhotos();
  639.         if ($photos->isEmpty()) {
  640.             return null;
  641.         }
  642.         $mainPhoto = null;
  643.         $photos->forAll(function ($index, Photo $photo) use (&$mainPhoto): bool {
  644.             if ($photo->isMain()) {
  645.                 $mainPhoto = $photo;
  646.                 return false; // Stop the cycle
  647.             }
  648.             return true;
  649.         });
  650.         return $mainPhoto;
  651.     }
  652.     public function changeMainPhoto(string $path): void
  653.     {
  654.         $photos = $this->getPhotos();
  655.         $found = $photos->filter(function (Photo $photo) use ($path): bool {
  656.             return $path === $photo->getPath();
  657.         });
  658.         if ($found->isEmpty()) {
  659.             return;
  660.         }
  661.         $mainPhoto = $found->first();
  662.         $photos->forAll(function ($index, Photo $photo): true {
  663.             $photo->unsetMain();
  664.             return true;
  665.         });
  666.         $mainPhoto->setMain();
  667.     }
  668.     public function addSelfie(string $path): Selfie
  669.     {
  670.         $found = $this->getSelfies()->filter(function (Selfie $selfie) use ($path): bool {
  671.             return $path === $selfie->getPath();
  672.         });
  673.         if (!$found->isEmpty())
  674.             return $found->first();
  675.         $selfie = new Selfie($this, $path);
  676.         $this->selfies->add($selfie);
  677.         return $selfie;
  678.     }
  679.     /**
  680.      * @return Selfie[]
  681.      */
  682.     public function getSelfies(): Collection
  683.     {
  684.         return $this->selfies;
  685.     }
  686.     public function removeSelfie(string $path): bool
  687.     {
  688.         foreach ($this->getSelfies() as $selfie) {
  689.             if ($path === $selfie->getPath()) {
  690.                 $this->selfies->removeElement($selfie);
  691.                 return true;
  692.             }
  693.         }
  694.         return false;
  695.     }
  696.     public function getConfirmedVideos(): Collection
  697.     {
  698.         return $this->videos->filter(function ($mediaFile): bool {
  699.             if (!$mediaFile instanceof Video) {
  700.                 return false;
  701.             }
  702.             return $mediaFile->isConfirmed();
  703.         });
  704.     }
  705.     /**
  706.      * Храним только 1 видео для анкеты
  707.      */
  708.     public function addVideo(string $videoPath, ?string $posterPath = null): Video
  709.     {
  710.         $found = $this->getVideos()->filter(function (Video $video) use ($videoPath): bool {
  711.             return $videoPath === $video->getPath();
  712.         });
  713.         if (!$found->isEmpty())
  714.             return $found->first();
  715.         $video = new Video($this, $videoPath);
  716.         if (null !== $posterPath) {
  717.             $video->setPreviewPath($posterPath);
  718.         }
  719.         //теперь разрешаем много видео
  720.         //$this->videos->clear();
  721.         $this->videos->add($video);
  722.         return $video;
  723.     }
  724.     /**
  725.      * @return Video[]
  726.      */
  727.     public function getVideos(): Collection
  728.     {
  729.         return $this->videos->filter(function ($mediaFile): bool {
  730.             return ($mediaFile instanceof Video);
  731.         });
  732.     }
  733.     public function removeVideo(string $path): bool
  734.     {
  735.         foreach ($this->getVideos() as $video) {
  736.             if ($path === $video->getPath()) {
  737.                 $this->videos->removeElement($video);
  738.                 $this->photos->removeElement($video);
  739.                 return true;
  740.             }
  741.         }
  742.         return false;
  743.     }
  744.     /**
  745.      * Добавляет таск на обработку оригинала видео в подходящий формат
  746.      *
  747.      * @param string $path Путь к файлу оригинала относительно фс очередей
  748.      */
  749.     public function addRawVideo(string $path): FileProcessingTask
  750.     {
  751.         $file = new FileProcessingTask($this, $path);
  752.         $this->processingFiles->add($file);
  753.         return $file;
  754.     }
  755.     public function hasFilesInProcess(): bool
  756.     {
  757.         return $this->videosInProcess() > 0;
  758.     }
  759.     public function videosInProcess(): int
  760.     {
  761.         $inProcess = $this->processingFiles->filter(function (FileProcessingTask $task): bool {
  762.             return !$task->isCompleted();
  763.         });
  764.         return $inProcess->count();
  765.     }
  766.     public function isMediaProcessed(): bool
  767.     {
  768.         foreach ($this->videos as $video)
  769.             if (null === $video->getPreviewPath())
  770.                 return false;
  771.         return true;
  772.     }
  773.     public function getAvatar(): ?Avatar
  774.     {
  775.         return $this->avatar;
  776.     }
  777.     public function setAvatar(string $path): void
  778.     {
  779.         $this->avatar = new Avatar($this, $path);
  780.     }
  781.     public function removeAvatar(): bool
  782.     {
  783.         if (null == $this->avatar)
  784.             return false;
  785.         foreach ($this->photos as $photo) {
  786.             if ($this->avatar->getPath() === $photo->getPath()) {
  787.                 $this->photos->removeElement($photo);
  788.                 break;
  789.             }
  790.         }
  791.         $this->avatar = null;
  792.         return true;
  793.     }
  794.     /**
  795.      * @return CommentByCustomer[]
  796.      */
  797.     public function getComments(): Collection
  798.     {
  799.         return $this->comments->filter(function (CommentByCustomer $comment): bool {
  800.             return null == $comment->getParent();
  801.         });
  802.     }
  803.     /**
  804.      * @return CommentByCustomer[]
  805.      */
  806.     public function getCommentsOrderedByNotReplied(): array
  807.     {
  808.         $comments = $this->comments->filter(function (CommentByCustomer $comment): bool {
  809.             return null == $comment->getParent();
  810.         })->toArray();
  811.         usort($comments, function (CommentByCustomer $commentA, CommentByCustomer $commentB): int {
  812.             if ((null == $commentA->getLastCommentByAdvertiser() && null == $commentB->getLastCommentByAdvertiser())
  813.                 || (null != $commentA->getLastCommentByAdvertiser() && null != $commentB->getLastCommentByAdvertiser())) {
  814.                 if ($commentA->getCreatedAt() == $commentB->getCreatedAt())
  815.                     return $commentA->getId() > $commentB->getId() ? -1 : 1;
  816.                 else
  817.                     return $commentA->getCreatedAt() > $commentB->getCreatedAt() ? -1 : 1;
  818.             }
  819.             if (null == $commentA->getLastCommentByAdvertiser() && null != $commentB->getLastCommentByAdvertiser())
  820.                 return -1;
  821.             else
  822.                 return 1;
  823.         });
  824.         return $comments;
  825.     }
  826.     public function getCreatedAt(): ?\DateTimeImmutable
  827.     {
  828.         return $this->createdAt;
  829.     }
  830.     /**
  831.      * @return CommentByCustomer[]
  832.      */
  833.     public function getCommentsWithoutReply(): Collection
  834.     {
  835.         return $this->comments->filter(function (CommentByCustomer $comment): bool {
  836.             return null == $comment->getParent() && false == $comment->isCommentedByAdvertiser();
  837.         });
  838.     }
  839.     /**
  840.      * @return CommentByCustomer[]
  841.      */
  842.     public function getCommentsWithReply(): Collection
  843.     {
  844.         return $this->comments->filter(function (CommentByCustomer $comment): bool {
  845.             return null == $comment->getParent() && true == $comment->isCommentedByAdvertiser();
  846.         });
  847.     }
  848.     /**
  849.      * @return CommentByCustomer[]
  850.      */
  851.     public function getNewComments(): Collection
  852.     {
  853.         $weekAgo = CarbonImmutable::now()->sub('7 days');
  854.         return $this->comments->filter(function (CommentByCustomer $comment) use ($weekAgo): bool {
  855.             return null == $comment->getParent()
  856.                 && (
  857.                     $comment->getCreatedAt() >= $weekAgo
  858.                     || null == $this->getCommentReply($comment)
  859.                 );
  860.         });
  861.     }
  862.     private function getCommentReply(CommentByCustomer $parent): ?CommentByCustomer
  863.     {
  864.         foreach ($this->comments as $comment)
  865.             if ($comment->getParent() == $parent)
  866.                 return $comment;
  867.         return null;
  868.     }
  869.     public function getOldComments(): Collection
  870.     {
  871.         $weekAgo = CarbonImmutable::now()->sub('7 days');
  872.         return $this->comments->filter(function (CommentByCustomer $comment) use ($weekAgo): bool {
  873.             return null == $comment->getParent()
  874.                 && false == (
  875.                     $comment->getCreatedAt() >= $weekAgo
  876.                     || null == $this->getCommentReply($comment)
  877.                 );
  878.         });
  879.     }
  880.     public function getCommentFromUser(Customer $user): ?CommentByCustomer
  881.     {
  882.         foreach ($this->comments as $comment)
  883.             if (null == $comment->getParent() && null != $comment->getUser() && $user->getId() == $comment->getUser()->getId())
  884.                 return $comment;
  885.         return null;
  886.     }
  887.     //TODO return type
  888.     public function getCity(): City
  889.     {
  890.         return $this->city;
  891.     }
  892.     /** @return Collection<int, ProfileName> */
  893.     public function getProfileNames(): Collection
  894.     {
  895.         return $this->profileNames;
  896.     }
  897.     /**
  898.      * @return Station[]
  899.      */
  900.     public function getStations(): Collection
  901.     {
  902.         return $this->stations;
  903.     }
  904.     public function getMapCoordinate(): ?MapCoordinate
  905.     {
  906.         return $this->mapCoordinate;
  907.     }
  908.     public function getUpdatedAt(): ?\DateTimeImmutable
  909.     {
  910.         return $this->updatedAt;
  911.     }
  912.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): void
  913.     {
  914.         $this->updatedAt = $updatedAt;
  915.         $this->mauticStale30dSentAt = null;
  916.     }
  917.     public function getMauticStale30dSentAt(): ?\DateTimeImmutable
  918.     {
  919.         return $this->mauticStale30dSentAt;
  920.     }
  921.     public function setMauticStale30dSentAt(?\DateTimeImmutable $sentAt): void
  922.     {
  923.         $this->mauticStale30dSentAt = $sentAt;
  924.     }
  925.     public function getModerationStatus(): int
  926.     {
  927.         return $this->moderationStatus;
  928.     }
  929.     public function setModerationStatus(int $status): void
  930.     {
  931.         if (self::MODERATION_STATUS_APPROVED === $status) {
  932.             throw new \RuntimeException(sprintf('Use %s::passModeration() method instead', static::class));
  933.         }
  934.         $validStatuses = [self::MODERATION_STATUS_NOT_PASSED, self::MODERATION_STATUS_APPROVED, self::MODERATION_STATUS_WAITING, self::MODERATION_STATUS_REJECTED];
  935.         if (false === array_search($status, $validStatuses))
  936.             throw new \LogicException('Trying to set an invalid moderation status');
  937.         $this->moderationStatus = $status;
  938.     }
  939.     public function isModerationPassed(): bool
  940.     {
  941.         return $this->moderationStatus == self::MODERATION_STATUS_APPROVED;
  942.     }
  943.     public function isModerationWaiting(): bool
  944.     {
  945.         return $this->moderationStatus == self::MODERATION_STATUS_WAITING;
  946.     }
  947.     public function isModerationRejected(): bool
  948.     {
  949.         return $this->moderationStatus == self::MODERATION_STATUS_REJECTED;
  950.     }
  951.     public function passModeration(?ModerationRequest $moderationRequest = null): void
  952.     {
  953.         $this->moderationStatus = self::MODERATION_STATUS_APPROVED;
  954.         $func = static function ($k, Photo|Video $file) use ($moderationRequest): bool {
  955.             if (!$file->isConfirmed()) {
  956.                 $file->passModeration($moderationRequest);
  957.             }
  958.             return true;
  959.         };
  960.         $this->videos->forAll($func);
  961.     }
  962.     public function delete(): void
  963.     {
  964.         $this->deletePlacementHiding();
  965.         $this->deleteFromAdBoard();
  966.         $now = new \DateTimeImmutable('now');
  967.         $toDelete = [];
  968.         foreach ($this->topPlacements as $topPlacement) {
  969.             if ($topPlacement->getExpiresAt() > $now)
  970.                 $toDelete[] = $topPlacement;
  971.         }
  972.         foreach ($toDelete as $topPlacement)
  973.             $this->topPlacements->removeElement($topPlacement);
  974.         $this->setDeletedAt(Carbon::now());
  975.     }
  976.     public function deletePlacementHiding(): void
  977.     {
  978.         $this->placementHiding = null;
  979.     }
  980.     public function deleteFromAdBoard(): void
  981.     {
  982.         $this->adBoardPlacement = null;
  983.     }
  984.     //TODO return type
  985.     public function undoDelete(): void
  986.     {
  987.         $this->setDeletedAt(); // will pass null by default
  988.     }
  989.     //TODO return type
  990.     public function deleteFromTopPlacement(): void
  991.     {
  992.         //здесь нужна логика отмены конретного размещения
  993. //        $this->topPlacement = null;
  994.     }
  995.     public function getExpressPricing(): ?ExpressPricing
  996.     {
  997.         return $this->expressPricing;
  998.     }
  999.     public function getCarPricing(): ?CarPricing
  1000.     {
  1001.         return $this->carPricing;
  1002.     }
  1003.     //TODO return type
  1004.     /**
  1005.      * @return int[]
  1006.      */
  1007.     public function getClientTypes(): array
  1008.     {
  1009.         return $this->clientTypes ?? [];
  1010.     }
  1011.     /**
  1012.      * @param int[] $clientTypes
  1013.      */
  1014.     public function setClientTypes(array $clientTypes): void
  1015.     {
  1016.         $this->clientTypes = $clientTypes;
  1017.     }
  1018.     public function getMessengers(): ?Messengers
  1019.     {
  1020.         return $this->messengers;
  1021.     }
  1022.     public function getInactivatedAt(): ?\DateTimeImmutable
  1023.     {
  1024.         return $this->inactivatedAt;
  1025.     }
  1026.     public function setInactive(): void
  1027.     {
  1028.         $this->inactivatedAt = CarbonImmutable::now();
  1029.     }
  1030.     public function undoInactive(): void
  1031.     {
  1032.         $this->inactivatedAt = null;
  1033.     }
  1034.     public function isHidden(): bool
  1035.     {
  1036.         return null !== $this->getPlacementHiding();
  1037.     }
  1038.     public function getPlacementHiding(): ?PlacementHiding
  1039.     {
  1040.         return $this->placementHiding;
  1041.     }
  1042.     public function setPlacementHiding(PlacementHiding $placementHiding): void
  1043.     {
  1044.         $this->placementHiding = $placementHiding;
  1045.     }
  1046.     public function hasSelfie(): bool
  1047.     {
  1048.         return $this->selfies->count() > 0;
  1049.     }
  1050.     public function hasVideo(): bool
  1051.     {
  1052.         return $this->videos->count() > 0;
  1053.     }
  1054.     public function isCommented(): bool
  1055.     {
  1056.         return $this->comments->count() > 0;
  1057.     }
  1058.     public function adminApprovalPhoto(): ?AdminApprovalPhoto
  1059.     {
  1060.         return $this->adminApprovalPhoto;
  1061.     }
  1062.     public function setAdminApprovalPhoto(?string $path): void
  1063.     {
  1064.         $this->adminApprovalPhoto = $path ? new AdminApprovalPhoto($this, $path) : null;
  1065.     }
  1066.     public function seo(): ?array
  1067.     {
  1068.         return $this->seo;
  1069.     }
  1070.     public function seoPhoneNumber(): ?string
  1071.     {
  1072.         return $this->seo['phone'] ?? null;
  1073.     }
  1074.     public function setSeoPhoneNumber(string $phoneNumber): void
  1075.     {
  1076.         if (null === $this->seo) {
  1077.             $this->seo = [];
  1078.         }
  1079.         $this->seo['phone'] = $phoneNumber;
  1080.     }
  1081.     public function getPrimaryStation(): ?Station
  1082.     {
  1083.         $station = $this->primaryStation ?? $this->getStations()->first();
  1084.         if (false === $station) {
  1085.             return null;
  1086.         }
  1087.         return $station;
  1088.     }
  1089.     public function setPrimaryStation(?Station $station): void
  1090.     {
  1091.         $this->primaryStation = $station;
  1092.         $this->normalizePrimaryStation();
  1093.     }
  1094.     public function getStationsSortedByPrimary(): array
  1095.     {
  1096.         $stations = $this->stations->toArray();
  1097.         if (!$this->primaryStation) {
  1098.             return $stations;
  1099.         }
  1100.         usort($stations, function (Station $a, Station $b) {
  1101.             if ($a->getId() === $this->primaryStation->getId()) return -1;
  1102.             if ($b->getId() === $this->primaryStation->getId()) return 1;
  1103.             return 0;
  1104.         });
  1105.         return $stations;
  1106.     }
  1107.     public function getDistricts(): array
  1108.     {
  1109.         $districts = [];
  1110.         $addedDistricts = [];
  1111.         foreach ($this->getStationsSortedByPrimary() as $station) {
  1112.             $district = $station->getDistrict();
  1113.             if (null === $district) {
  1114.                 continue;
  1115.             }
  1116.             if (array_key_exists($district->getId(), $addedDistricts)) {
  1117.                 continue;
  1118.             }
  1119.             $districts[] = $district;
  1120.             $addedDistricts[$district->getId()] = true;
  1121.         }
  1122.         return $districts;
  1123.     }
  1124.     public function getDeleteMode(): int
  1125.     {
  1126.         return $this->deleteMode;
  1127.     }
  1128.     public function setDeleteMode(int $deleteMode): self
  1129.     {
  1130.         $this->deleteMode = $deleteMode;
  1131.         return $this;
  1132.     }
  1133.     public function isHardDeleted(): bool
  1134.     {
  1135.         return $this->deleteMode === 2;
  1136.     }
  1137. }