src/Entity/Garages/Garage.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Garages;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  7. use App\Annotation\SiteAware;
  8. use App\Entity\AbstractBase;
  9. use App\Entity\Address;
  10. use App\Entity\Interfaces\CodeInterface;
  11. use App\Entity\Interfaces\ImageInterface;
  12. use App\Entity\Interfaces\PublishedInterface;
  13. use App\Entity\Interfaces\SiteInterface;
  14. use App\Entity\Interfaces\SlugInterface;
  15. use App\Entity\MiniAbstractBase;
  16. use App\Entity\Promotions\LocalPromotion;
  17. use App\Entity\Province;
  18. use App\Entity\PurchaseTracking\GaragePurchase;
  19. use App\Entity\Traits\HasImageTrait;
  20. use App\Entity\Traits\NameTrait;
  21. use App\Entity\Traits\PhoneTrait;
  22. use App\Entity\Traits\PublishedTrait;
  23. use App\Entity\Traits\SiteTrait;
  24. use App\Entity\Traits\SlugTrait;
  25. use App\Entity\User;
  26. use App\Enum\SiteEnum;
  27. use App\Repository\Garages\GarageRepository;
  28. use Doctrine\Common\Collections\ArrayCollection;
  29. use Doctrine\Common\Collections\Collection;
  30. use Doctrine\ORM\Mapping as ORM;
  31. use Gedmo\Mapping\Annotation as Gedmo;
  32. use Symfony\Component\HttpFoundation\File\File;
  33. use Symfony\Component\Security\Core\User\UserInterface;
  34. use Symfony\Component\Serializer\Annotation\Groups;
  35. use Symfony\Component\Validator\Constraints as Assert;
  36. use Symfony\Component\Validator\Constraints\Callback;
  37. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  38. use Symfony\Component\Validator\Mapping\ClassMetadata;
  39. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  40. /**
  41.  * @ApiResource(
  42.  *     shortName="garage",
  43.  *     normalizationContext={"groups"={"api:read", "garage:read"}, "swagger_definition_name"="Read"},
  44.  *     denormalizationContext={"groups"={"garage:write"}, "swagger_definition_name"="Write"},
  45.  *     collectionOperations={"get"},
  46.  *     itemOperations={"get", "put"}
  47.  * )
  48.  *
  49.  * @ApiFilter(BooleanFilter::class, properties={"published"})
  50.  *
  51.  * @ORM\Table(name="vulco_garage", indexes={@ORM\Index(name="garage_site_idx", columns={"site"})}, uniqueConstraints={@ORM\UniqueConstraint(name="garage_site_slug_idx", columns={"site", "slug"})})
  52.  *
  53.  * @ORM\Entity(repositoryClass=GarageRepository::class)
  54.  *
  55.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  56.  *
  57.  * @SiteAware(siteFieldName="site")
  58.  *
  59.  * @Vich\Uploadable
  60.  */
  61. class Garage extends AbstractBase implements CodeInterfaceImageInterfacePublishedInterfaceSiteInterfaceSlugInterface
  62. {
  63.     use HasImageTrait;
  64.     use NameTrait;
  65.     use PhoneTrait;
  66.     use PublishedTrait;
  67.     use SiteTrait;
  68.     use SlugTrait;
  69.     public const DEFAULT_POINTS_LIMIT 4800.0;
  70.     /**
  71.      * @ApiProperty(identifier=false)
  72.      *
  73.      * @ORM\Id
  74.      *
  75.      * @ORM\GeneratedValue
  76.      *
  77.      * @ORM\Column(type="integer")
  78.      *
  79.      * @Groups({"api:read"})
  80.      */
  81.     protected int $id;
  82.     /**
  83.      * @Vich\UploadableField(mapping="garage_image", fileNameProperty="imageName")
  84.      */
  85.     private ?File $image null;
  86.     /**
  87.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="garages")
  88.      *
  89.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  90.      */
  91.     private ?User $owner null;
  92.     /**
  93.      * @ORM\OneToOne(targetEntity="App\Entity\Address", cascade={"persist"}, orphanRemoval=true, fetch="EAGER")
  94.      *
  95.      * @ORM\JoinColumn(name="address_id", referencedColumnName="id")
  96.      */
  97.     private Address $address;
  98.     /**
  99.      * @ORM\OneToOne(targetEntity="App\Entity\Garages\GarageSchedules", cascade={"persist"}, orphanRemoval=true, fetch="EAGER")
  100.      *
  101.      * @ORM\JoinColumn(name="schedules_id", referencedColumnName="id")
  102.      */
  103.     private GarageSchedules $schedules;
  104.     /**
  105.      * @ORM\ManyToMany(targetEntity="App\Entity\Garages\GarageService")
  106.      *
  107.      * @ORM\JoinTable(name="vulco_garage_to_service_relation",
  108.      *     joinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")},
  109.      *     inverseJoinColumns={@ORM\JoinColumn(name="garage_service_id", referencedColumnName="id")}
  110.      * )
  111.      */
  112.     private ?Collection $services;
  113.     /**
  114.      * @ORM\ManyToMany(targetEntity="App\Entity\Garages\GarageFacility")
  115.      *
  116.      * @ORM\JoinTable(name="vulco_garage_to_facility_relation",
  117.      *     joinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")},
  118.      *     inverseJoinColumns={@ORM\JoinColumn(name="garage_facility_id", referencedColumnName="id")}
  119.      * )
  120.      */
  121.     private ?Collection $facilities;
  122.     /**
  123.      * @ORM\OneToMany(targetEntity="App\Entity\Promotions\LocalPromotion", mappedBy="garage", cascade={"persist", "remove"}, orphanRemoval=true)
  124.      */
  125.     private ?Collection $localPromotions;
  126.     /**
  127.      * @ORM\ManyToMany(targetEntity="App\Entity\Garages\GarageVehicleType")
  128.      *
  129.      * @ORM\JoinTable(name="vulco_garage_vechicle_type_relation",
  130.      *     joinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")},
  131.      *     inverseJoinColumns={@ORM\JoinColumn(name="vehicle_type_id", referencedColumnName="id")}
  132.      * )
  133.      */
  134.     private ?Collection $typeVehicles;
  135.     /**
  136.      * @ORM\ManyToMany(targetEntity="App\Entity\Address", cascade={"persist", "remove"}, orphanRemoval=true)
  137.      *
  138.      * @ORM\JoinTable(name="vulco_garage_additional_addresses",
  139.      *     joinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")},
  140.      *     inverseJoinColumns={@ORM\JoinColumn(name="address_id", referencedColumnName="id")}
  141.      * )
  142.      */
  143.     private ?Collection $additionalAddresses;
  144.     /**
  145.      * @ORM\OneToMany(targetEntity="App\Entity\PurchaseTracking\GaragePurchase", mappedBy="garage", orphanRemoval=true)
  146.      */
  147.     private ?Collection $purchases;
  148.     /**
  149.      * @ORM\OneToOne(targetEntity="App\Entity\Garages\GarageAboutUs", orphanRemoval=true, fetch="EAGER", cascade={"persist"})
  150.      *
  151.      * @ORM\JoinColumn(name="garage_about_us_id", referencedColumnName="id")
  152.      */
  153.     private ?GarageAboutUs $aboutUs;
  154.     /**
  155.      * @ORM\OneToOne(targetEntity="App\Entity\Garages\GarageOwner", mappedBy="garage")
  156.      */
  157.     private ?GarageOwner $garageOwner null;
  158.     /**
  159.      * @ORM\Column(type="string", length=255, nullable=false)
  160.      *
  161.      * @Groups({"garage:read"})
  162.      */
  163.     private string $name;
  164.     /**
  165.      * @ApiProperty(identifier=true)
  166.      *
  167.      * @ORM\Column(type="string", length=255, nullable=false, unique=true)
  168.      *
  169.      * @Groups({"garage:read"})
  170.      */
  171.     private string $code;
  172.     /**
  173.      * @ORM\Column(type="string", length=255, nullable=false)
  174.      */
  175.     private string $cif;
  176.     /**
  177.      * @ORM\Column(type="string", length=255, nullable=false)
  178.      *
  179.      * @Gedmo\Slug(fields={"name"}, unique=true)
  180.      */
  181.     private string $slug;
  182.     /**
  183.      * @ORM\Column(type="string", length=255)
  184.      */
  185.     private string $companyName;
  186.     /**
  187.      * @ORM\Column(type="string", length=255, nullable=true)
  188.      */
  189.     private ?string $mobile null;
  190.     /**
  191.      * @ORM\Column(type="string", length=255, nullable=true)
  192.      */
  193.     private ?string $mobileAssociated null;
  194.     /**
  195.      * España (prefijo 34 => 11 caracteres) o Portugal (prefijo 351 => 12 caracteres).
  196.      *
  197.      * @Assert\Regex(pattern="/^\d{11}$|^\d{12}$/")
  198.      *
  199.      * @ORM\Column(type="string", length=255, nullable=true)
  200.      */
  201.     private ?string $whatsapp null;
  202.     /**
  203.      * Móvil con whatsapp para recibir comunicaciones comerciales
  204.      * España (prefijo 34 => 11 caracteres) o Portugal (prefijo 351 => 12 caracteres).
  205.      *
  206.      * @ORM\Column(type="string", length=255, nullable=true, unique=true)
  207.      *
  208.      * @Assert\Regex(pattern="/^\d{11}$|^\d{12}$/")
  209.  *
  210.      */
  211.     private ?string $whatsappCampaigns null;
  212.     /**
  213.      * @ORM\Column(type="string", length=255, nullable=true)
  214.      */
  215.     private ?string $whatsappCampaignsName null;
  216.     /**
  217.      * @ORM\Column(type="string", length=255, nullable=true)
  218.      */
  219.     private ?string $website null;
  220.     /**
  221.      * @ORM\Column(type="string", length=255, nullable=true)
  222.      */
  223.     private ?string $fax null;
  224.     /**
  225.      * @ORM\Column(type="boolean", nullable=true)
  226.      */
  227.     private ?bool $sms null;
  228.     /**
  229.      * @ORM\Column(type="string", length=255, nullable=false)
  230.      *
  231.      * @Assert\Email()
  232.      *
  233.      * @Groups({"garage:read"})
  234.      */
  235.     private string $email;
  236.     /**
  237.      * @ORM\Column(type="text", length=10000, nullable=true)
  238.      */
  239.     private ?string $budgetEmail null;
  240.     /**
  241.      * @ORM\Column(type="text", length=10000, nullable=true)
  242.      */
  243.     private ?string $garageAppointmentNotificationEmails null;
  244.     /**
  245.      * @ORM\Column(type="string", length=255, nullable=true)
  246.      */
  247.     private ?string $timetableMorning null;
  248.     /**
  249.      * @ORM\Column(type="string", length=255, nullable=true)
  250.      */
  251.     private ?string $timetableAfternoon null;
  252.     /**
  253.      * @ORM\Column(type="string", length=255, nullable=true)
  254.      */
  255.     private ?string $timetableSaturday null;
  256.     /**
  257.      * @ORM\Column(type="boolean", nullable=false)
  258.      */
  259.     private bool $worksWithCollective;
  260.     /**
  261.      * @ORM\Column(type="string", length=255, nullable=true)
  262.      */
  263.     private ?string $otherServices null;
  264.     /**
  265.      * @ORM\Column(type="string", length=255, nullable=true)
  266.      */
  267.     private ?string $imageName null;
  268.     /**
  269.      * @ORM\Column(type="string", length=255, nullable=true)
  270.      */
  271.     private ?string $internObservations null;
  272.     /**
  273.      * @ORM\Column(type="boolean", nullable=false, options={"default": 0})
  274.      */
  275.     private bool $maintenancePlansEnabled false;
  276.     /**
  277.      * @ORM\Column(type="array", nullable=true)
  278.      */
  279.     private ?array $maintenancePlans null;
  280.     /**
  281.      * @ORM\Column(type="string", length=255, nullable=true)
  282.      */
  283.     private ?string $garageECImageName null;
  284.     /**
  285.      * @ORM\Column(type="text", length=10000, nullable=true)
  286.      */
  287.     private ?string $garageECImageUrl null;
  288.     /**
  289.      * @ORM\Column(type="text", length=10000, nullable=true)
  290.      */
  291.     private ?string $eCommerceWarningMessage null;
  292.     /**
  293.      * @ORM\Column(type="string", length=255, nullable=true)
  294.      */
  295.     private ?string $legalInformation null;
  296.     /**
  297.      * @ORM\Column(type="string", length=255, nullable=true)
  298.      */
  299.     private ?string $legalInformationCa null;
  300.     /**
  301.      * @ORM\Column(type="text", length=10000, nullable=true)
  302.      */
  303.     private ?string $featuredBox null;
  304.     /**
  305.      * @ORM\Column(type="text", length=10000, nullable=true)
  306.      */
  307.     private ?string $featuredBoxCa null;
  308.     /**
  309.      * @ORM\Column(type="text", length=10000, nullable=true)
  310.      */
  311.     private ?string $facebookUrl null;
  312.     /**
  313.      * @ORM\Column(type="text", length=10000, nullable=true)
  314.      */
  315.     private ?string $twitterUrl null;
  316.     /**
  317.      * @ORM\Column(type="text", length=10000, nullable=true)
  318.      */
  319.     private ?string $instagramUrl null;
  320.     /**
  321.      * @ORM\Column(type="boolean", nullable=false, options={"default": 0})
  322.      */
  323.     private bool $eCommerceWebsite false;
  324.     /**
  325.      * @ORM\Column(type="boolean", nullable=false, options={"default": 0})
  326.      */
  327.     private bool $catalanLanguage false;
  328.     /**
  329.      * @ORM\Column(type="float", nullable=false, options={"default": 4800})
  330.      */
  331.     private float $pointsLimit self::DEFAULT_POINTS_LIMIT;
  332.     /**
  333.      * @ORM\Column(type="string", length=255, nullable=true)
  334.      */
  335.     private ?string $ERP null;
  336.     /**
  337.      * @ORM\Column(type="string", length=255, nullable=true)
  338.      */
  339.     private ?string $gerente null;
  340.     /**
  341.      * @ORM\Column(type="boolean", nullable=false, options={"default": 1})
  342.      */
  343.     private bool $allowBudgetRequest true;
  344.     /**
  345.      * @ORM\Column(type="boolean", nullable=false, options={"default": 1})
  346.      */
  347.     private bool $allowGarageAppointment true;
  348.     /**
  349.      * @ORM\Column(type="boolean", nullable=false, options={"default": 0})
  350.      * The garage has GRIPS software
  351.      */
  352.     private bool $grips false;
  353.     /**
  354.      * @ORM\Column(type="boolean", nullable=false, options={"default": 0})
  355.      * El taller está adherido a la tarifa de Vulco interna para camiones y aparecerá en el mapa del site para camiones
  356.      */
  357.     private bool $vulcoTruckRate false;
  358.     public function __construct()
  359.     {
  360.         $this->services = new ArrayCollection();
  361.         $this->localPromotions = new ArrayCollection();
  362.         $this->facilities = new ArrayCollection();
  363.         $this->typeVehicles = new ArrayCollection();
  364.         $this->additionalAddresses = new ArrayCollection();
  365.         $this->purchases = new ArrayCollection();
  366.         $this->schedules = new GarageSchedules();
  367.         $this->aboutUs = new GarageAboutUs();
  368.     }
  369.     public function __clone() {
  370.         if ($this->id) {
  371.             if (!is_null($this->owner)) {
  372.                 $this->owner = clone $this->owner;
  373.             }
  374.             if (!is_null($this->address)) {
  375.                 $this->address = clone $this->address;
  376.             }
  377.             if (!is_null($this->schedules)) {
  378.                 $this->schedules = clone $this->schedules;
  379.             }
  380.             if (!is_null($this->services)) {
  381.                 $this->services = clone $this->services;
  382.             }
  383.             if (!is_null($this->facilities)) {
  384.                 $this->facilities = clone $this->facilities;
  385.             }
  386.             if (!is_null($this->localPromotions)) {
  387.                 $this->localPromotions = clone $this->localPromotions;
  388.             }
  389.             if (!is_null($this->typeVehicles)) {
  390.                 $this->typeVehicles = clone $this->typeVehicles;
  391.             }
  392.             if (!is_null($this->additionalAddresses)) {
  393.                 $additionalAddresses $this->getAdditionalAddresses();
  394.                 $this->additionalAddresses = new ArrayCollection();
  395.                 if (count($additionalAddresses) > 0) {
  396.                     foreach ($additionalAddresses as $address) {
  397.                         $addressClone = clone $address;
  398.                         $this->additionalAddresses->add($addressClone);
  399.                     }
  400.                 }
  401.             }
  402.             if (!is_null($this->purchases)) {
  403.                 $this->purchases = clone $this->purchases;
  404.             }
  405.             if (!is_null($this->aboutUs)) {
  406.                 $this->aboutUs = clone $this->aboutUs;
  407.             }
  408.             if (!is_null($this->garageOwner)) {
  409.                 $this->garageOwner = clone $this->garageOwner;
  410.             }
  411.         }
  412.     }
  413.     public static function loadValidatorMetadata(ClassMetadata $metadata): void
  414.     {
  415.         $metadata->addConstraint(new Callback('validate'));
  416.     }
  417.     public function validate(ExecutionContextInterface $context): void
  418.     {
  419.         $areBudgetEmailsValid $this->internalEmailsValidationCheck($this->getBudgetEmail());
  420.         $areGarageAppointmentNotificationEmailsValid $this->internalEmailsValidationCheck($this->getGarageAppointmentNotificationEmails());
  421.         if (!$areBudgetEmailsValid) {
  422.             $context->buildViolation(SiteEnum::SITE_STR_ES === $this->getSite() ? 'ERROR! Alguna dirección de correo electrónico introducida no es correcta o no están separados por coma.' 'ERRO! Quaisquer endereços de e-mail inseridos não estão corretos ou não estão separados por vírgulas.')
  423.                 ->atPath('budgetEmail')
  424.                 ->addViolation()
  425.             ;
  426.         }
  427.         if (!$areGarageAppointmentNotificationEmailsValid) {
  428.             $context->buildViolation(SiteEnum::SITE_STR_ES === $this->getSite() ? 'ERROR! Alguna dirección de correo electrónico introducida no es correcta o no están separados por coma.' 'ERRO! Quaisquer endereços de e-mail inseridos não estão corretos ou não estão separados por vírgulas.')
  429.                 ->atPath('garageAppointmentNotificationEmails')
  430.                 ->addViolation()
  431.             ;
  432.         }
  433.     }
  434.     private function internalEmailsValidationCheck(?string $internalEmailsString): bool
  435.     {
  436.         $areIneternalEmailsValid true;
  437.         if ($internalEmailsString) {
  438.             $trimmedString trim($internalEmailsString);
  439.             $emailsArray explode(','$trimmedString);
  440.             foreach ($emailsArray as $email) {
  441.                 if (false === filter_var($emailFILTER_VALIDATE_EMAIL)) {
  442.                     $areIneternalEmailsValid false;
  443.                     break;
  444.                 }
  445.             }
  446.         }
  447.         return $areIneternalEmailsValid;
  448.     }
  449.     public function getOwner(): ?User
  450.     {
  451.         return $this->owner;
  452.     }
  453.     public function setOwner(?User $owner): self
  454.     {
  455.         $this->owner $owner;
  456.         return $this;
  457.     }
  458.     public function getAddress(): Address
  459.     {
  460.         return $this->address;
  461.     }
  462.     public function setAddress(Address $address): self
  463.     {
  464.         $this->address $address;
  465.         return $this;
  466.     }
  467.     public function getSchedules(): GarageSchedules
  468.     {
  469.         return $this->schedules;
  470.     }
  471.     public function setSchedules(GarageSchedules $schedules): self
  472.     {
  473.         $this->schedules $schedules;
  474.         return $this;
  475.     }
  476.     public function hasService(GarageService $service): bool
  477.     {
  478.         $result false;
  479.         /** @var GarageService $item */
  480.         foreach ($this->getServices() as $item) {
  481.             if ($service->getId() === $item->getId()) {
  482.                 $result true;
  483.                 break;
  484.             }
  485.         }
  486.         return $result;
  487.     }
  488.     public function getServices(): ?Collection
  489.     {
  490.         return $this->services;
  491.     }
  492.     public function setServices(?Collection $services): self
  493.     {
  494.         $this->services $services;
  495.         return $this;
  496.     }
  497.     public function addService(GarageService $service): self
  498.     {
  499.         if (!$this->services->contains($service)) {
  500.             $this->services->add($service);
  501.         }
  502.         return $this;
  503.     }
  504.     public function removeService(GarageService $service): self
  505.     {
  506.         if ($this->services->contains($service)) {
  507.             $this->services->removeElement($service);
  508.         }
  509.         return $this;
  510.     }
  511.     public function hasFacility(GarageFacility $facility): bool
  512.     {
  513.         $result false;
  514.         /** @var GarageFacility $item */
  515.         foreach ($this->getFacilities() as $item) {
  516.             if ($facility->getId() === $item->getId()) {
  517.                 $result true;
  518.                 break;
  519.             }
  520.         }
  521.         return $result;
  522.     }
  523.     public function getFacilities(): ?Collection
  524.     {
  525.         return $this->facilities;
  526.     }
  527.     public function setFacilities(?Collection $facilities): self
  528.     {
  529.         $this->facilities $facilities;
  530.         return $this;
  531.     }
  532.     public function addFacility(GarageFacility $facility): self
  533.     {
  534.         if (!$this->facilities->contains($facility)) {
  535.             $this->facilities->add($facility);
  536.         }
  537.         return $this;
  538.     }
  539.     public function removeFacility(GarageFacility $facility): self
  540.     {
  541.         if ($this->facilities->contains($facility)) {
  542.             $this->facilities->removeElement($facility);
  543.         }
  544.         return $this;
  545.     }
  546.     public function getLocalPromotions(): ?Collection
  547.     {
  548.         return $this->localPromotions;
  549.     }
  550.     public function setLocalPromotions(?Collection $localPromotions): self
  551.     {
  552.         $this->localPromotions $localPromotions;
  553.         return $this;
  554.     }
  555.     public function addLocalPromotion(LocalPromotion $localPromotion): self
  556.     {
  557.         if (!$this->localPromotions->contains($localPromotion)) {
  558.             $this->localPromotions->add($localPromotion);
  559.         }
  560.         return $this;
  561.     }
  562.     public function removeLocalPromotion(LocalPromotion $localPromotion): self
  563.     {
  564.         if ($this->localPromotions->contains($localPromotion)) {
  565.             $this->localPromotions->removeElement($localPromotion);
  566.         }
  567.         return $this;
  568.     }
  569.     public function hasTypeVehicle(GarageVehicleType $typeVehicle): bool
  570.     {
  571.         $result false;
  572.         /** @var GarageVehicleType $item */
  573.         foreach ($this->getTypeVehicles() as $item) {
  574.             if ($typeVehicle->getId() === $item->getId()) {
  575.                 $result true;
  576.                 break;
  577.             }
  578.         }
  579.         return $result;
  580.     }
  581.     public function getTypeVehicles(): ?Collection
  582.     {
  583.         return $this->typeVehicles;
  584.     }
  585.     public function setTypeVehicles(?Collection $typeVehicles): self
  586.     {
  587.         $this->typeVehicles $typeVehicles;
  588.         return $this;
  589.     }
  590.     public function addTypeVehicle(GarageVehicleType $typeVehicle): self
  591.     {
  592.         if (!$this->typeVehicles->contains($typeVehicle)) {
  593.             $this->typeVehicles->add($typeVehicle);
  594.         }
  595.         return $this;
  596.     }
  597.     public function removeTypeVehicle(GarageVehicleType $typeVehicle): self
  598.     {
  599.         if ($this->typeVehicles->contains($typeVehicle)) {
  600.             $this->typeVehicles->removeElement($typeVehicle);
  601.         }
  602.         return $this;
  603.     }
  604.     public function getAdditionalAddresses(): ?Collection
  605.     {
  606.         return $this->additionalAddresses;
  607.     }
  608.     public function setAdditionalAddresses(?Collection $additionalAddresses): self
  609.     {
  610.         $this->additionalAddresses $additionalAddresses;
  611.         return $this;
  612.     }
  613.     public function addAdditionalAddresses(Address $additionalAddress): self
  614.     {
  615.         if (!$this->additionalAddresses->contains($additionalAddress)) {
  616.             $this->additionalAddresses->add($additionalAddress);
  617.         }
  618.         return $this;
  619.     }
  620.     public function removeAdditionalAddresses(Address $additionalAddress): self
  621.     {
  622.         if ($this->additionalAddresses->contains($additionalAddress)) {
  623.             $this->additionalAddresses->removeElement($additionalAddress);
  624.         }
  625.         return $this;
  626.     }
  627.     public function getPurchases(): ?Collection
  628.     {
  629.         return $this->purchases;
  630.     }
  631.     public function setPurchases(?Collection $purchases): self
  632.     {
  633.         $this->purchases $purchases;
  634.         return $this;
  635.     }
  636.     public function getAboutUs(): ?GarageAboutUs
  637.     {
  638.         return $this->aboutUs;
  639.     }
  640.     public function setAboutUs(?GarageAboutUs $aboutUs): self
  641.     {
  642.         $this->aboutUs $aboutUs;
  643.         return $this;
  644.     }
  645.     public function getGarageOwner(): ?GarageOwner
  646.     {
  647.         return $this->garageOwner;
  648.     }
  649.     public function setGarageOwner(GarageOwner $garageOwner): self
  650.     {
  651.         $this->garageOwner $garageOwner;
  652.         return $this;
  653.     }
  654.     public function getRelatedAddresses(): array
  655.     {
  656.         $result = [];
  657.         $result[] = $this->getAddress();
  658.         /** @var Address $additionalAddress */
  659.         foreach ($this->getAdditionalAddresses() as $additionalAddress) {
  660.             $result[] = $additionalAddress;
  661.         }
  662.         return $result;
  663.     }
  664.     public function isOwner(UserInterface $user): bool
  665.     {
  666.         if ($this->getOwner() && ($user->getId() === $this->getOwner()->getId())) {
  667.             return true;
  668.         }
  669.         return false;
  670.     }
  671.     public function isCoordinator(UserInterface $user): bool
  672.     {
  673.         return $user->getWorkProvinces() && $user->getWorkProvinces()->contains($this->getAddress()->getProvince());
  674.     }
  675.     public function province(): ?Province
  676.     {
  677.         return $this->address->getProvince() ?: null;
  678.     }
  679.     public function provinceName(): ?string
  680.     {
  681.         return $this->province() ? $this->province()->getName() : null;
  682.     }
  683.     public function getCode(): string
  684.     {
  685.         return $this->code;
  686.     }
  687.     public function setCode(string $code): self
  688.     {
  689.         $this->code $code;
  690.         return $this;
  691.     }
  692.     public function getCif(): string
  693.     {
  694.         return $this->cif;
  695.     }
  696.     public function setCif(string $cif): self
  697.     {
  698.         $this->cif $cif;
  699.         return $this;
  700.     }
  701.     public function getCompanyName(): string
  702.     {
  703.         return $this->companyName;
  704.     }
  705.     public function setCompanyName(string $companyName): self
  706.     {
  707.         $this->companyName $companyName;
  708.         return $this;
  709.     }
  710.     public function getMobile(): ?string
  711.     {
  712.         return $this->mobile;
  713.     }
  714.     public function setMobile(?string $mobile): self
  715.     {
  716.         $this->mobile $mobile;
  717.         return $this;
  718.     }
  719.     public function getMobileAssociated(): ?string
  720.     {
  721.         return $this->mobileAssociated;
  722.     }
  723.     public function setMobileAssociated(?string $mobileAssociated): self
  724.     {
  725.         $this->mobileAssociated $mobileAssociated;
  726.         return $this;
  727.     }
  728.     public function getWhatsapp(): ?string
  729.     {
  730.         return $this->whatsapp;
  731.     }
  732.     public function setWhatsapp(?string $whatsapp): self
  733.     {
  734.         $this->whatsapp $whatsapp;
  735.         return $this;
  736.     }
  737.     public function getWhatsappCampaigns(): ?string
  738.     {
  739.         return $this->whatsappCampaigns;
  740.     }
  741.     public function setWhatsappCampaigns(?string $whatsappCampaigns): self
  742.     {
  743.         $this->whatsappCampaigns $whatsappCampaigns;
  744.         return $this;
  745.     }
  746.     public function getWhatsappCampaignsName(): ?string
  747.     {
  748.         return $this->whatsappCampaignsName;
  749.     }
  750.     public function setWhatsappCampaignsName(?string $whatsappCampaignsName): self
  751.     {
  752.         $this->whatsappCampaignsName $whatsappCampaignsName;
  753.         return $this;
  754.     }
  755.     public function getWebsite(): ?string
  756.     {
  757.         return $this->website;
  758.     }
  759.     public function setWebsite(?string $website): self
  760.     {
  761.         $this->website $website;
  762.         return $this;
  763.     }
  764.     public function getFax(): ?string
  765.     {
  766.         return $this->fax;
  767.     }
  768.     public function setFax(?string $fax): self
  769.     {
  770.         $this->fax $fax;
  771.         return $this;
  772.     }
  773.     public function getSms(): ?bool
  774.     {
  775.         return $this->sms;
  776.     }
  777.     public function setSms(?bool $sms): self
  778.     {
  779.         $this->sms $sms;
  780.         return $this;
  781.     }
  782.     public function getEmail(): string
  783.     {
  784.         return $this->email;
  785.     }
  786.     public function setEmail(string $email): self
  787.     {
  788.         $this->email $email;
  789.         return $this;
  790.     }
  791.     public function getBudgetEmail(): ?string
  792.     {
  793.         return $this->budgetEmail;
  794.     }
  795.     public function setBudgetEmail(?string $budgetEmail): self
  796.     {
  797.         $this->budgetEmail $budgetEmail;
  798.         return $this;
  799.     }
  800.     public function getGarageAppointmentNotificationEmails(): ?string
  801.     {
  802.         return $this->garageAppointmentNotificationEmails;
  803.     }
  804.     public function getGarageAppointmentNotificationEmailsExplodedArrayOrDefaultEmailInstead()
  805.     {
  806.         $result $this->getEmail();
  807.         if ($this->getGarageAppointmentNotificationEmails()) {
  808.             $result explode(','$this->getGarageAppointmentNotificationEmails());
  809.         }
  810.         return $result;
  811.     }
  812.     public function setGarageAppointmentNotificationEmails(?string $garageAppointmentNotificationEmails): self
  813.     {
  814.         $this->garageAppointmentNotificationEmails $garageAppointmentNotificationEmails;
  815.         return $this;
  816.     }
  817.     public function getTimetableMorning(): ?string
  818.     {
  819.         return $this->timetableMorning;
  820.     }
  821.     public function setTimetableMorning(?string $timetableMorning): self
  822.     {
  823.         $this->timetableMorning $timetableMorning;
  824.         return $this;
  825.     }
  826.     public function getTimetableAfternoon(): ?string
  827.     {
  828.         return $this->timetableAfternoon;
  829.     }
  830.     public function setTimetableAfternoon(?string $timetableAfternoon): self
  831.     {
  832.         $this->timetableAfternoon $timetableAfternoon;
  833.         return $this;
  834.     }
  835.     public function getTimetableSaturday(): ?string
  836.     {
  837.         return $this->timetableSaturday;
  838.     }
  839.     public function setTimetableSaturday(?string $timetableSaturday): self
  840.     {
  841.         $this->timetableSaturday $timetableSaturday;
  842.         return $this;
  843.     }
  844.     public function isWorksWithCollective(): bool
  845.     {
  846.         return $this->worksWithCollective;
  847.     }
  848.     public function setWorksWithCollective(bool $worksWithCollective): self
  849.     {
  850.         $this->worksWithCollective $worksWithCollective;
  851.         return $this;
  852.     }
  853.     public function getOtherServices(): ?string
  854.     {
  855.         return $this->otherServices;
  856.     }
  857.     public function setOtherServices(?string $otherServices): self
  858.     {
  859.         $this->otherServices $otherServices;
  860.         return $this;
  861.     }
  862.     public function getImageName(): ?string
  863.     {
  864.         return $this->imageName;
  865.     }
  866.     public function setImageName(?string $imageName): self
  867.     {
  868.         $this->imageName $imageName;
  869.         return $this;
  870.     }
  871.     public function getInternObservations(): ?string
  872.     {
  873.         return $this->internObservations;
  874.     }
  875.     public function setInternObservations(?string $internObservations): self
  876.     {
  877.         $this->internObservations $internObservations;
  878.         return $this;
  879.     }
  880.     public function isMaintenancePlansEnabled(): bool
  881.     {
  882.         return $this->maintenancePlansEnabled;
  883.     }
  884.     public function setMaintenancePlansEnabled(bool $maintenancePlansEnabled): self
  885.     {
  886.         $this->maintenancePlansEnabled $maintenancePlansEnabled;
  887.         return $this;
  888.     }
  889.     public function getMaintenancePlans(): ?array
  890.     {
  891.         return $this->maintenancePlans;
  892.     }
  893.     public function setMaintenancePlans(?array $maintenancePlans): self
  894.     {
  895.         $this->maintenancePlans $maintenancePlans;
  896.         return $this;
  897.     }
  898.     public function addMaintenancePlan($plan): self
  899.     {
  900.         if (!in_array($plan$this->maintenancePlanstrue)) {
  901.             $this->maintenancePlans[] = $plan;
  902.         }
  903.         return $this;
  904.     }
  905.     public function hasMaintenancePlan($plan): bool
  906.     {
  907.         return in_array(strtoupper($plan), $this->getMaintenancePlans(), true);
  908.     }
  909.     public function getGarageECImageName(): ?string
  910.     {
  911.         return $this->garageECImageName;
  912.     }
  913.     public function setGarageECImageName(?string $garageECImageName): self
  914.     {
  915.         $this->garageECImageName $garageECImageName;
  916.         return $this;
  917.     }
  918.     public function getGarageECImageUrl(): ?string
  919.     {
  920.         return $this->garageECImageUrl;
  921.     }
  922.     public function setGarageECImageUrl(?string $garageECImageUrl): self
  923.     {
  924.         $this->garageECImageUrl $garageECImageUrl;
  925.         return $this;
  926.     }
  927.     public function getECommerceWarningMessage(): ?string
  928.     {
  929.         return $this->eCommerceWarningMessage;
  930.     }
  931.     public function setECommerceWarningMessage(?string $eCommerceWarningMessage): self
  932.     {
  933.         $this->eCommerceWarningMessage $eCommerceWarningMessage;
  934.         return $this;
  935.     }
  936.     public function getLegalInformation(): ?string
  937.     {
  938.         return $this->legalInformation;
  939.     }
  940.     public function setLegalInformation(?string $legalInformation): self
  941.     {
  942.         $this->legalInformation $legalInformation;
  943.         return $this;
  944.     }
  945.     public function getLegalInformationCa(): ?string
  946.     {
  947.         return $this->legalInformationCa;
  948.     }
  949.     public function setLegalInformationCa(?string $legalInformationCa): self
  950.     {
  951.         $this->legalInformationCa $legalInformationCa;
  952.         return $this;
  953.     }
  954.     public function getFeaturedBox(): ?string
  955.     {
  956.         return $this->featuredBox;
  957.     }
  958.     public function setFeaturedBox(?string $featuredBox): self
  959.     {
  960.         $this->featuredBox $featuredBox;
  961.         return $this;
  962.     }
  963.     public function getFeaturedBoxCa(): ?string
  964.     {
  965.         return $this->featuredBoxCa;
  966.     }
  967.     public function setFeaturedBoxCa(?string $featuredBoxCa): self
  968.     {
  969.         $this->featuredBoxCa $featuredBoxCa;
  970.         return $this;
  971.     }
  972.     public function getFacebookUrl(): ?string
  973.     {
  974.         return $this->facebookUrl;
  975.     }
  976.     public function setFacebookUrl(?string $facebookUrl): self
  977.     {
  978.         $this->facebookUrl $facebookUrl;
  979.         return $this;
  980.     }
  981.     public function getTwitterUrl(): ?string
  982.     {
  983.         return $this->twitterUrl;
  984.     }
  985.     public function setTwitterUrl(?string $twitterUrl): self
  986.     {
  987.         $this->twitterUrl $twitterUrl;
  988.         return $this;
  989.     }
  990.     public function getInstagramUrl(): ?string
  991.     {
  992.         return $this->instagramUrl;
  993.     }
  994.     public function setInstagramUrl(?string $instagramUrl): self
  995.     {
  996.         $this->instagramUrl $instagramUrl;
  997.         return $this;
  998.     }
  999.     public function isECommerceWebsite(): bool
  1000.     {
  1001.         return $this->eCommerceWebsite;
  1002.     }
  1003.     public function setECommerceWebsite(bool $eCommerceWebsite): self
  1004.     {
  1005.         $this->eCommerceWebsite $eCommerceWebsite;
  1006.         return $this;
  1007.     }
  1008.     public function isCatalanLanguage(): bool
  1009.     {
  1010.         return $this->catalanLanguage;
  1011.     }
  1012.     public function setCatalanLanguage(bool $catalanLanguage): self
  1013.     {
  1014.         $this->catalanLanguage $catalanLanguage;
  1015.         return $this;
  1016.     }
  1017.     public function getPointsLimit(): float
  1018.     {
  1019.         return $this->pointsLimit;
  1020.     }
  1021.     public function setPointsLimit(float $pointsLimit): self
  1022.     {
  1023.         $this->pointsLimit $pointsLimit;
  1024.         return $this;
  1025.     }
  1026.     public function getERP(): ?string
  1027.     {
  1028.         return $this->ERP;
  1029.     }
  1030.     public function setERP(?string $ERP): self
  1031.     {
  1032.         $this->ERP $ERP;
  1033.         return $this;
  1034.     }
  1035.     public function getGerente(): ?string
  1036.     {
  1037.         return $this->gerente;
  1038.     }
  1039.     public function setGerente(?string $gerente): self
  1040.     {
  1041.         $this->gerente $gerente;
  1042.         return $this;
  1043.     }
  1044.     public function isAllowBudgetRequest(): bool
  1045.     {
  1046.         return $this->allowBudgetRequest;
  1047.     }
  1048.     public function setAllowBudgetRequest(bool $allowBudgetRequest): self
  1049.     {
  1050.         $this->allowBudgetRequest $allowBudgetRequest;
  1051.         return $this;
  1052.     }
  1053.     public function isAllowGarageAppointment(): bool
  1054.     {
  1055.         return $this->allowGarageAppointment;
  1056.     }
  1057.     public function setAllowGarageAppointment(bool $allowGarageAppointment): self
  1058.     {
  1059.         $this->allowGarageAppointment $allowGarageAppointment;
  1060.         return $this;
  1061.     }
  1062.     public function isGrips(): bool
  1063.     {
  1064.         return $this->grips;
  1065.     }
  1066.     public function setGrips(bool $grips): self
  1067.     {
  1068.         $this->grips $grips;
  1069.         return $this;
  1070.     }
  1071.     public function isVulcoTruckRate(): bool
  1072.     {
  1073.         return $this->vulcoTruckRate;
  1074.     }
  1075.     public function setVulcoTruckRate(bool $vulcoTruckRate): self
  1076.     {
  1077.         $this->vulcoTruckRate $vulcoTruckRate;
  1078.         return $this;
  1079.     }
  1080.     public function getNameAndCodeString(): string
  1081.     {
  1082.         return $this->name.' ('.$this->code.')';
  1083.     }
  1084.     public function getNameAndCodeStringAndProvince(): string
  1085.     {
  1086.         return $this->name.' ('.$this->code.')'.' - '.$this->provinceName();
  1087.     }
  1088.     public function getPurchasesOf(int $year): ?array
  1089.     {
  1090.         $purchases = [];
  1091.         /** @var GaragePurchase $purchase */
  1092.         foreach ($this->purchases as $purchase) {
  1093.             if ($purchase->getYear() === $year) {
  1094.                 $purchases[] = $purchase;
  1095.             }
  1096.         }
  1097.         return $purchases;
  1098.     }
  1099.     public function diff(Garage $before): array
  1100.     {
  1101.         $diff = array();
  1102.         // general data
  1103.         if ($this->mobileAssociated !== $before->mobileAssociated) {
  1104.             $diff[] = ['garage.mobile_associated'$this->mobileAssociated];
  1105.         }
  1106.         if ($this->phone !== $before->phone) {
  1107.             $diff[] = ['garage.phone'$this->phone];
  1108.         }
  1109.         if ($this->mobile !== $before->mobile) {
  1110.             $diff[] = ['garage.mobile'$this->mobile];
  1111.         }
  1112.         if ($this->whatsapp !== $before->whatsapp) {
  1113.             $diff[] = ['garage.whatsapp'$this->whatsapp];
  1114.         }
  1115.         if ($this->whatsappCampaigns !== $before->whatsappCampaigns) {
  1116.             $diff[] = ['garage.whatsapp_campaigns'$this->whatsappCampaigns];
  1117.         }
  1118.         if ($this->whatsappCampaignsName !== $before->whatsappCampaignsName) {
  1119.             $diff[] = ['garage.whatsapp_campaigns_name'$this->whatsappCampaignsName];
  1120.         }
  1121.         if ($this->facebookUrl !== $before->facebookUrl) {
  1122.             $diff[] = ['garage.facebook'$this->facebookUrl];
  1123.         }
  1124.         if ($this->twitterUrl !== $before->twitterUrl) {
  1125.             $diff[] = ['garage.twitter'$this->twitterUrl];
  1126.         }
  1127.         if ($this->instagramUrl !== $before->instagramUrl) {
  1128.             $diff[] = ['garage.instagram'$this->instagramUrl];
  1129.         }
  1130.         // timetable_data
  1131.         $schedulesDiff $this->schedules->diff($before->schedules);
  1132.         if (!empty($schedulesDiff)) {
  1133.             $diff[] = ['garage.form.timetable_data'$schedulesDiff];
  1134.         }
  1135.         // address
  1136.         $addressDiff $this->address->diff($before->address);
  1137.         if (!empty($addressDiff)) {
  1138.             $diff[] = ['garage.form.address_data'$addressDiff];
  1139.         }
  1140.         // additional_addresses_data
  1141.         if ($this->additionalAddresses->isEmpty() && !$before->additionalAddresses->isEmpty()){
  1142.             $diff[] = ['garage.form.additional_addresses_data''todas las direcciones eliminadas'];
  1143.         } else if (!$this->additionalAddresses->isEmpty() && $before->additionalAddresses->isEmpty()) {
  1144.             foreach ($this->additionalAddresses as $address) {
  1145.                 $diff[] = ['garage.form.additional_address_data'$address->displayRawFields()];
  1146.             }
  1147.         } else if (!$this->additionalAddresses->isEmpty() && !$before->additionalAddresses->isEmpty()
  1148.             && (count($this->additionalAddresses) < count($before->additionalAddresses))) {
  1149.             $diff[] = ['garage.form.additional_addresses_data''hay cambios en las direcciones'];
  1150.         } else if (!$this->additionalAddresses->isEmpty() && !$before->additionalAddresses->isEmpty()
  1151.             && (count($this->additionalAddresses) > count($before->additionalAddresses))) {
  1152.             $diff[] = ['garage.form.additional_addresses_data''hay cambios en las direcciones'];
  1153.         } else if (!$this->additionalAddresses->isEmpty() && !$before->additionalAddresses->isEmpty()
  1154.             && (count($this->additionalAddresses) === count($before->additionalAddresses)))
  1155.         {
  1156.             $additionalAddresses $this->additionalAddresses->getValues(); // because an ArrayCollection could have not sequential indexes
  1157.             $beforeAddresses $before->additionalAddresses->getValues();
  1158.             for ($i 0$i count($additionalAddresses); $i++) {
  1159.                 //if ($additionalAddresses[$i]) { // puede que solo haya las que han sido modificadas
  1160.                     $addressDiff $additionalAddresses[$i]->diff($beforeAddresses[$i]);
  1161.                     if (!empty($addressDiff)) {
  1162.                         $diff[] = ['garage.form.additional_address_data'$additionalAddresses[$i]->displayRawFields()];
  1163.                     }
  1164.                 //}
  1165.             }
  1166.         }
  1167.         // typeVehicles
  1168.         if (empty($this->typeVehicles) && !empty($before->typeVehicles)
  1169.         ) {
  1170.             $diff[] = ['garage.form.vehicle_types_data''ítems eliminados'];
  1171.         } else {
  1172.             if (
  1173.                 (!empty($this->typeVehicles) && empty($before->typeVehicles))
  1174.                 || (!empty($this->typeVehicles) && !empty($before->typeVehicles) && (count($this->typeVehicles) !== count($before->typeVehicles)))
  1175.             )
  1176.             {
  1177.                 $typeVehiclesNames = array();
  1178.                 /** @var GarageVehicleType $item */
  1179.                 foreach ($this->typeVehicles as $item) {
  1180.                     $typeVehiclesNames[] = $item->getName();
  1181.                 }
  1182.                 $diff[] = ['garage.form.vehicle_types_data'implode(', '$typeVehiclesNames)];
  1183.             }
  1184.         }
  1185.         // facilities
  1186.         if (empty($this->facilities) && !empty($before->facilities)
  1187.         ) {
  1188.             $diff[] = ['garage.form.comforts_data''ítems eliminados'];
  1189.         } else {
  1190.             if (
  1191.                 (!empty($this->facilities) && empty($before->facilities))
  1192.                 || (!empty($this->facilities) && !empty($before->facilities) && (count($this->facilities) !== count($before->facilities)))
  1193.             )
  1194.             {
  1195.                 $facilitiesNames = array();
  1196.                 /** @var GarageFacility $item */
  1197.                 foreach ($this->facilities as $item) {
  1198.                     $facilitiesNames[] = $item->getName();
  1199.                 }
  1200.                 $diff[] = ['garage.form.comforts_data'implode(', '$facilitiesNames)];
  1201.             }
  1202.         }
  1203.         // services
  1204.         if (empty($this->services) && !empty($before->services)
  1205.         ) {
  1206.             $diff[] = ['garage.form.services_data''ítems eliminados'];
  1207.         } else {
  1208.             if (
  1209.                 (!empty($this->services) && empty($before->services))
  1210.                 || (!empty($this->services) && !empty($before->services) && (count($this->services) !== count($before->services)))
  1211.             )
  1212.             {
  1213.                 $servicesNames = array();
  1214.                 /** @var GarageService $item */
  1215.                 foreach ($this->services as $item) {
  1216.                     $servicesNames[] = $item->getName();
  1217.                 }
  1218.                 $diff[] = ['garage.form.services_data'implode(', '$servicesNames)];
  1219.             }
  1220.         }
  1221.         return $diff;
  1222.     }
  1223.     public function __toString(): string
  1224.     {
  1225.         return $this->id $this->getName() : MiniAbstractBase::DEFAULT_EMPTY_STRING;
  1226.     }
  1227. }