<?php
namespace App\Entity\Garages;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use App\Annotation\SiteAware;
use App\Entity\AbstractBase;
use App\Entity\Address;
use App\Entity\Interfaces\CodeInterface;
use App\Entity\Interfaces\ImageInterface;
use App\Entity\Interfaces\PublishedInterface;
use App\Entity\Interfaces\SiteInterface;
use App\Entity\Interfaces\SlugInterface;
use App\Entity\MiniAbstractBase;
use App\Entity\Promotions\LocalPromotion;
use App\Entity\Province;
use App\Entity\PurchaseTracking\GaragePurchase;
use App\Entity\Traits\HasImageTrait;
use App\Entity\Traits\NameTrait;
use App\Entity\Traits\PhoneTrait;
use App\Entity\Traits\PublishedTrait;
use App\Entity\Traits\SiteTrait;
use App\Entity\Traits\SlugTrait;
use App\Entity\User;
use App\Enum\SiteEnum;
use App\Repository\Garages\GarageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ApiResource(
* shortName="garage",
* normalizationContext={"groups"={"api:read", "garage:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"garage:write"}, "swagger_definition_name"="Write"},
* collectionOperations={"get"},
* itemOperations={"get", "put"}
* )
*
* @ApiFilter(BooleanFilter::class, properties={"published"})
*
* @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"})})
*
* @ORM\Entity(repositoryClass=GarageRepository::class)
*
* @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
*
* @SiteAware(siteFieldName="site")
*
* @Vich\Uploadable
*/
class Garage extends AbstractBase implements CodeInterface, ImageInterface, PublishedInterface, SiteInterface, SlugInterface
{
use HasImageTrait;
use NameTrait;
use PhoneTrait;
use PublishedTrait;
use SiteTrait;
use SlugTrait;
public const DEFAULT_POINTS_LIMIT = 4800.0;
/**
* @ApiProperty(identifier=false)
*
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Groups({"api:read"})
*/
protected int $id;
/**
* @Vich\UploadableField(mapping="garage_image", fileNameProperty="imageName")
*/
private ?File $image = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="garages")
*
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private ?User $owner = null;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Address", cascade={"persist"}, orphanRemoval=true, fetch="EAGER")
*
* @ORM\JoinColumn(name="address_id", referencedColumnName="id")
*/
private Address $address;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Garages\GarageSchedules", cascade={"persist"}, orphanRemoval=true, fetch="EAGER")
*
* @ORM\JoinColumn(name="schedules_id", referencedColumnName="id")
*/
private GarageSchedules $schedules;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Garages\GarageService")
*
* @ORM\JoinTable(name="vulco_garage_to_service_relation",
* joinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="garage_service_id", referencedColumnName="id")}
* )
*/
private ?Collection $services;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Garages\GarageFacility")
*
* @ORM\JoinTable(name="vulco_garage_to_facility_relation",
* joinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="garage_facility_id", referencedColumnName="id")}
* )
*/
private ?Collection $facilities;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Promotions\LocalPromotion", mappedBy="garage", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private ?Collection $localPromotions;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Garages\GarageVehicleType")
*
* @ORM\JoinTable(name="vulco_garage_vechicle_type_relation",
* joinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="vehicle_type_id", referencedColumnName="id")}
* )
*/
private ?Collection $typeVehicles;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Address", cascade={"persist", "remove"}, orphanRemoval=true)
*
* @ORM\JoinTable(name="vulco_garage_additional_addresses",
* joinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="address_id", referencedColumnName="id")}
* )
*/
private ?Collection $additionalAddresses;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PurchaseTracking\GaragePurchase", mappedBy="garage", orphanRemoval=true)
*/
private ?Collection $purchases;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Garages\GarageAboutUs", orphanRemoval=true, fetch="EAGER", cascade={"persist"})
*
* @ORM\JoinColumn(name="garage_about_us_id", referencedColumnName="id")
*/
private ?GarageAboutUs $aboutUs;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Garages\GarageOwner", mappedBy="garage")
*/
private ?GarageOwner $garageOwner = null;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*
* @Groups({"garage:read"})
*/
private string $name;
/**
* @ApiProperty(identifier=true)
*
* @ORM\Column(type="string", length=255, nullable=false, unique=true)
*
* @Groups({"garage:read"})
*/
private string $code;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private string $cif;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*
* @Gedmo\Slug(fields={"name"}, unique=true)
*/
private string $slug;
/**
* @ORM\Column(type="string", length=255)
*/
private string $companyName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $mobile = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $mobileAssociated = null;
/**
* España (prefijo 34 => 11 caracteres) o Portugal (prefijo 351 => 12 caracteres).
*
* @Assert\Regex(pattern="/^\d{11}$|^\d{12}$/")
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $whatsapp = null;
/**
* Móvil (sin prefijo) con whatsapp para recibir comunicaciones comerciales
*
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
*
* @Assert\Regex(pattern="/^\d{11}$|^\d{12}$/")
*
*/
private ?string $whatsappCampaigns = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $whatsappCampaignsName = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $website = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $fax = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $sms = null;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*
* @Assert\Email()
*
* @Groups({"garage:read"})
*/
private string $email;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $budgetEmail = null;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $garageAppointmentNotificationEmails = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $timetableMorning = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $timetableAfternoon = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $timetableSaturday = null;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private bool $worksWithCollective;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $otherServices = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $imageName = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $internObservations = null;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": 0})
*/
private bool $maintenancePlansEnabled = false;
/**
* @ORM\Column(type="array", nullable=true)
*/
private ?array $maintenancePlans = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $garageECImageName = null;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $garageECImageUrl = null;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $eCommerceWarningMessage = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $legalInformation = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $legalInformationCa = null;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $featuredBox = null;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $featuredBoxCa = null;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $facebookUrl = null;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $twitterUrl = null;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $instagramUrl = null;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": 0})
*/
private bool $eCommerceWebsite = false;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": 0})
*/
private bool $catalanLanguage = false;
/**
* @ORM\Column(type="float", nullable=false, options={"default": 4800})
*/
private float $pointsLimit = self::DEFAULT_POINTS_LIMIT;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $ERP = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $gerente = null;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": 1})
*/
private bool $allowBudgetRequest = true;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": 1})
*/
private bool $allowGarageAppointment = true;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": 0})
* The garage has GRIPS software
*/
private bool $grips = false;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": 0})
* El taller está adherido a la tarifa de Vulco interna para camiones y aparecerá en el mapa del site para camiones
*/
private bool $vulcoTruckRate = false;
public function __construct()
{
$this->services = new ArrayCollection();
$this->localPromotions = new ArrayCollection();
$this->facilities = new ArrayCollection();
$this->typeVehicles = new ArrayCollection();
$this->additionalAddresses = new ArrayCollection();
$this->purchases = new ArrayCollection();
$this->schedules = new GarageSchedules();
$this->aboutUs = new GarageAboutUs();
}
public function __clone() {
if ($this->id) {
if (!is_null($this->owner)) {
$this->owner = clone $this->owner;
}
if (!is_null($this->address)) {
$this->address = clone $this->address;
}
if (!is_null($this->schedules)) {
$this->schedules = clone $this->schedules;
}
if (!is_null($this->services)) {
$this->services = clone $this->services;
}
if (!is_null($this->facilities)) {
$this->facilities = clone $this->facilities;
}
if (!is_null($this->localPromotions)) {
$this->localPromotions = clone $this->localPromotions;
}
if (!is_null($this->typeVehicles)) {
$this->typeVehicles = clone $this->typeVehicles;
}
if (!is_null($this->additionalAddresses)) {
$additionalAddresses = $this->getAdditionalAddresses();
$this->additionalAddresses = new ArrayCollection();
if (count($additionalAddresses) > 0) {
foreach ($additionalAddresses as $address) {
$addressClone = clone $address;
$this->additionalAddresses->add($addressClone);
}
}
}
if (!is_null($this->purchases)) {
$this->purchases = clone $this->purchases;
}
if (!is_null($this->aboutUs)) {
$this->aboutUs = clone $this->aboutUs;
}
if (!is_null($this->garageOwner)) {
$this->garageOwner = clone $this->garageOwner;
}
}
}
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addConstraint(new Callback('validate'));
}
public function validate(ExecutionContextInterface $context): void
{
$areBudgetEmailsValid = $this->internalEmailsValidationCheck($this->getBudgetEmail());
$areGarageAppointmentNotificationEmailsValid = $this->internalEmailsValidationCheck($this->getGarageAppointmentNotificationEmails());
if (!$areBudgetEmailsValid) {
$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.')
->atPath('budgetEmail')
->addViolation()
;
}
if (!$areGarageAppointmentNotificationEmailsValid) {
$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.')
->atPath('garageAppointmentNotificationEmails')
->addViolation()
;
}
}
private function internalEmailsValidationCheck(?string $internalEmailsString): bool
{
$areIneternalEmailsValid = true;
if ($internalEmailsString) {
$trimmedString = trim($internalEmailsString);
$emailsArray = explode(',', $trimmedString);
foreach ($emailsArray as $email) {
if (false === filter_var($email, FILTER_VALIDATE_EMAIL)) {
$areIneternalEmailsValid = false;
break;
}
}
}
return $areIneternalEmailsValid;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(?User $owner): self
{
$this->owner = $owner;
return $this;
}
public function getAddress(): Address
{
return $this->address;
}
public function setAddress(Address $address): self
{
$this->address = $address;
return $this;
}
public function getSchedules(): GarageSchedules
{
return $this->schedules;
}
public function setSchedules(GarageSchedules $schedules): self
{
$this->schedules = $schedules;
return $this;
}
public function hasService(GarageService $service): bool
{
$result = false;
/** @var GarageService $item */
foreach ($this->getServices() as $item) {
if ($service->getId() === $item->getId()) {
$result = true;
break;
}
}
return $result;
}
public function getServices(): ?Collection
{
return $this->services;
}
public function setServices(?Collection $services): self
{
$this->services = $services;
return $this;
}
public function addService(GarageService $service): self
{
if (!$this->services->contains($service)) {
$this->services->add($service);
}
return $this;
}
public function removeService(GarageService $service): self
{
if ($this->services->contains($service)) {
$this->services->removeElement($service);
}
return $this;
}
public function hasFacility(GarageFacility $facility): bool
{
$result = false;
/** @var GarageFacility $item */
foreach ($this->getFacilities() as $item) {
if ($facility->getId() === $item->getId()) {
$result = true;
break;
}
}
return $result;
}
public function getFacilities(): ?Collection
{
return $this->facilities;
}
public function setFacilities(?Collection $facilities): self
{
$this->facilities = $facilities;
return $this;
}
public function addFacility(GarageFacility $facility): self
{
if (!$this->facilities->contains($facility)) {
$this->facilities->add($facility);
}
return $this;
}
public function removeFacility(GarageFacility $facility): self
{
if ($this->facilities->contains($facility)) {
$this->facilities->removeElement($facility);
}
return $this;
}
public function getLocalPromotions(): ?Collection
{
return $this->localPromotions;
}
public function setLocalPromotions(?Collection $localPromotions): self
{
$this->localPromotions = $localPromotions;
return $this;
}
public function addLocalPromotion(LocalPromotion $localPromotion): self
{
if (!$this->localPromotions->contains($localPromotion)) {
$this->localPromotions->add($localPromotion);
}
return $this;
}
public function removeLocalPromotion(LocalPromotion $localPromotion): self
{
if ($this->localPromotions->contains($localPromotion)) {
$this->localPromotions->removeElement($localPromotion);
}
return $this;
}
public function hasTypeVehicle(GarageVehicleType $typeVehicle): bool
{
$result = false;
/** @var GarageVehicleType $item */
foreach ($this->getTypeVehicles() as $item) {
if ($typeVehicle->getId() === $item->getId()) {
$result = true;
break;
}
}
return $result;
}
public function getTypeVehicles(): ?Collection
{
return $this->typeVehicles;
}
public function setTypeVehicles(?Collection $typeVehicles): self
{
$this->typeVehicles = $typeVehicles;
return $this;
}
public function addTypeVehicle(GarageVehicleType $typeVehicle): self
{
if (!$this->typeVehicles->contains($typeVehicle)) {
$this->typeVehicles->add($typeVehicle);
}
return $this;
}
public function removeTypeVehicle(GarageVehicleType $typeVehicle): self
{
if ($this->typeVehicles->contains($typeVehicle)) {
$this->typeVehicles->removeElement($typeVehicle);
}
return $this;
}
public function getAdditionalAddresses(): ?Collection
{
return $this->additionalAddresses;
}
public function setAdditionalAddresses(?Collection $additionalAddresses): self
{
$this->additionalAddresses = $additionalAddresses;
return $this;
}
public function addAdditionalAddresses(Address $additionalAddress): self
{
if (!$this->additionalAddresses->contains($additionalAddress)) {
$this->additionalAddresses->add($additionalAddress);
}
return $this;
}
public function removeAdditionalAddresses(Address $additionalAddress): self
{
if ($this->additionalAddresses->contains($additionalAddress)) {
$this->additionalAddresses->removeElement($additionalAddress);
}
return $this;
}
public function getPurchases(): ?Collection
{
return $this->purchases;
}
public function setPurchases(?Collection $purchases): self
{
$this->purchases = $purchases;
return $this;
}
public function getAboutUs(): ?GarageAboutUs
{
return $this->aboutUs;
}
public function setAboutUs(?GarageAboutUs $aboutUs): self
{
$this->aboutUs = $aboutUs;
return $this;
}
public function getGarageOwner(): ?GarageOwner
{
return $this->garageOwner;
}
public function setGarageOwner(GarageOwner $garageOwner): self
{
$this->garageOwner = $garageOwner;
return $this;
}
public function getRelatedAddresses(): array
{
$result = [];
$result[] = $this->getAddress();
/** @var Address $additionalAddress */
foreach ($this->getAdditionalAddresses() as $additionalAddress) {
$result[] = $additionalAddress;
}
return $result;
}
public function isOwner(UserInterface $user): bool
{
if ($this->getOwner() && ($user->getId() === $this->getOwner()->getId())) {
return true;
}
return false;
}
public function isCoordinator(UserInterface $user): bool
{
return $user->getWorkProvinces() && $user->getWorkProvinces()->contains($this->getAddress()->getProvince());
}
public function province(): ?Province
{
return $this->address->getProvince() ?: null;
}
public function provinceName(): ?string
{
return $this->province() ? $this->province()->getName() : null;
}
public function getCode(): string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getCif(): string
{
return $this->cif;
}
public function setCif(string $cif): self
{
$this->cif = $cif;
return $this;
}
public function getCompanyName(): string
{
return $this->companyName;
}
public function setCompanyName(string $companyName): self
{
$this->companyName = $companyName;
return $this;
}
public function getMobile(): ?string
{
return $this->mobile;
}
public function setMobile(?string $mobile): self
{
$this->mobile = $mobile;
return $this;
}
public function getMobileAssociated(): ?string
{
return $this->mobileAssociated;
}
public function setMobileAssociated(?string $mobileAssociated): self
{
$this->mobileAssociated = $mobileAssociated;
return $this;
}
public function getWhatsapp(): ?string
{
return $this->whatsapp;
}
public function setWhatsapp(?string $whatsapp): self
{
$this->whatsapp = $whatsapp;
return $this;
}
public function getWhatsappCampaigns(): ?string
{
return $this->whatsappCampaigns;
}
public function setWhatsappCampaigns(?string $whatsappCampaigns): self
{
$this->whatsappCampaigns = $whatsappCampaigns;
return $this;
}
public function getWhatsappCampaignsName(): ?string
{
return $this->whatsappCampaignsName;
}
public function setWhatsappCampaignsName(?string $whatsappCampaignsName): self
{
$this->whatsappCampaignsName = $whatsappCampaignsName;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): self
{
$this->website = $website;
return $this;
}
public function getFax(): ?string
{
return $this->fax;
}
public function setFax(?string $fax): self
{
$this->fax = $fax;
return $this;
}
public function getSms(): ?bool
{
return $this->sms;
}
public function setSms(?bool $sms): self
{
$this->sms = $sms;
return $this;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getBudgetEmail(): ?string
{
return $this->budgetEmail;
}
public function setBudgetEmail(?string $budgetEmail): self
{
$this->budgetEmail = $budgetEmail;
return $this;
}
public function getGarageAppointmentNotificationEmails(): ?string
{
return $this->garageAppointmentNotificationEmails;
}
public function getGarageAppointmentNotificationEmailsExplodedArrayOrDefaultEmailInstead()
{
$result = $this->getEmail();
if ($this->getGarageAppointmentNotificationEmails()) {
$result = explode(',', $this->getGarageAppointmentNotificationEmails());
}
return $result;
}
public function setGarageAppointmentNotificationEmails(?string $garageAppointmentNotificationEmails): self
{
$this->garageAppointmentNotificationEmails = $garageAppointmentNotificationEmails;
return $this;
}
public function getTimetableMorning(): ?string
{
return $this->timetableMorning;
}
public function setTimetableMorning(?string $timetableMorning): self
{
$this->timetableMorning = $timetableMorning;
return $this;
}
public function getTimetableAfternoon(): ?string
{
return $this->timetableAfternoon;
}
public function setTimetableAfternoon(?string $timetableAfternoon): self
{
$this->timetableAfternoon = $timetableAfternoon;
return $this;
}
public function getTimetableSaturday(): ?string
{
return $this->timetableSaturday;
}
public function setTimetableSaturday(?string $timetableSaturday): self
{
$this->timetableSaturday = $timetableSaturday;
return $this;
}
public function isWorksWithCollective(): bool
{
return $this->worksWithCollective;
}
public function setWorksWithCollective(bool $worksWithCollective): self
{
$this->worksWithCollective = $worksWithCollective;
return $this;
}
public function getOtherServices(): ?string
{
return $this->otherServices;
}
public function setOtherServices(?string $otherServices): self
{
$this->otherServices = $otherServices;
return $this;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageName(?string $imageName): self
{
$this->imageName = $imageName;
return $this;
}
public function getInternObservations(): ?string
{
return $this->internObservations;
}
public function setInternObservations(?string $internObservations): self
{
$this->internObservations = $internObservations;
return $this;
}
public function isMaintenancePlansEnabled(): bool
{
return $this->maintenancePlansEnabled;
}
public function setMaintenancePlansEnabled(bool $maintenancePlansEnabled): self
{
$this->maintenancePlansEnabled = $maintenancePlansEnabled;
return $this;
}
public function getMaintenancePlans(): ?array
{
return $this->maintenancePlans;
}
public function setMaintenancePlans(?array $maintenancePlans): self
{
$this->maintenancePlans = $maintenancePlans;
return $this;
}
public function addMaintenancePlan($plan): self
{
if (!in_array($plan, $this->maintenancePlans, true)) {
$this->maintenancePlans[] = $plan;
}
return $this;
}
public function hasMaintenancePlan($plan): bool
{
return in_array(strtoupper($plan), $this->getMaintenancePlans(), true);
}
public function getGarageECImageName(): ?string
{
return $this->garageECImageName;
}
public function setGarageECImageName(?string $garageECImageName): self
{
$this->garageECImageName = $garageECImageName;
return $this;
}
public function getGarageECImageUrl(): ?string
{
return $this->garageECImageUrl;
}
public function setGarageECImageUrl(?string $garageECImageUrl): self
{
$this->garageECImageUrl = $garageECImageUrl;
return $this;
}
public function getECommerceWarningMessage(): ?string
{
return $this->eCommerceWarningMessage;
}
public function setECommerceWarningMessage(?string $eCommerceWarningMessage): self
{
$this->eCommerceWarningMessage = $eCommerceWarningMessage;
return $this;
}
public function getLegalInformation(): ?string
{
return $this->legalInformation;
}
public function setLegalInformation(?string $legalInformation): self
{
$this->legalInformation = $legalInformation;
return $this;
}
public function getLegalInformationCa(): ?string
{
return $this->legalInformationCa;
}
public function setLegalInformationCa(?string $legalInformationCa): self
{
$this->legalInformationCa = $legalInformationCa;
return $this;
}
public function getFeaturedBox(): ?string
{
return $this->featuredBox;
}
public function setFeaturedBox(?string $featuredBox): self
{
$this->featuredBox = $featuredBox;
return $this;
}
public function getFeaturedBoxCa(): ?string
{
return $this->featuredBoxCa;
}
public function setFeaturedBoxCa(?string $featuredBoxCa): self
{
$this->featuredBoxCa = $featuredBoxCa;
return $this;
}
public function getFacebookUrl(): ?string
{
return $this->facebookUrl;
}
public function setFacebookUrl(?string $facebookUrl): self
{
$this->facebookUrl = $facebookUrl;
return $this;
}
public function getTwitterUrl(): ?string
{
return $this->twitterUrl;
}
public function setTwitterUrl(?string $twitterUrl): self
{
$this->twitterUrl = $twitterUrl;
return $this;
}
public function getInstagramUrl(): ?string
{
return $this->instagramUrl;
}
public function setInstagramUrl(?string $instagramUrl): self
{
$this->instagramUrl = $instagramUrl;
return $this;
}
public function isECommerceWebsite(): bool
{
return $this->eCommerceWebsite;
}
public function setECommerceWebsite(bool $eCommerceWebsite): self
{
$this->eCommerceWebsite = $eCommerceWebsite;
return $this;
}
public function isCatalanLanguage(): bool
{
return $this->catalanLanguage;
}
public function setCatalanLanguage(bool $catalanLanguage): self
{
$this->catalanLanguage = $catalanLanguage;
return $this;
}
public function getPointsLimit(): float
{
return $this->pointsLimit;
}
public function setPointsLimit(float $pointsLimit): self
{
$this->pointsLimit = $pointsLimit;
return $this;
}
public function getERP(): ?string
{
return $this->ERP;
}
public function setERP(?string $ERP): self
{
$this->ERP = $ERP;
return $this;
}
public function getGerente(): ?string
{
return $this->gerente;
}
public function setGerente(?string $gerente): self
{
$this->gerente = $gerente;
return $this;
}
public function isAllowBudgetRequest(): bool
{
return $this->allowBudgetRequest;
}
public function setAllowBudgetRequest(bool $allowBudgetRequest): self
{
$this->allowBudgetRequest = $allowBudgetRequest;
return $this;
}
public function isAllowGarageAppointment(): bool
{
return $this->allowGarageAppointment;
}
public function setAllowGarageAppointment(bool $allowGarageAppointment): self
{
$this->allowGarageAppointment = $allowGarageAppointment;
return $this;
}
public function isGrips(): bool
{
return $this->grips;
}
public function setGrips(bool $grips): self
{
$this->grips = $grips;
return $this;
}
public function isVulcoTruckRate(): bool
{
return $this->vulcoTruckRate;
}
public function setVulcoTruckRate(bool $vulcoTruckRate): self
{
$this->vulcoTruckRate = $vulcoTruckRate;
return $this;
}
public function getNameAndCodeString(): string
{
return $this->name.' ('.$this->code.')';
}
public function getNameAndCodeStringAndProvince(): string
{
return $this->name.' ('.$this->code.')'.' - '.$this->provinceName();
}
public function getPurchasesOf(int $year): ?array
{
$purchases = [];
/** @var GaragePurchase $purchase */
foreach ($this->purchases as $purchase) {
if ($purchase->getYear() === $year) {
$purchases[] = $purchase;
}
}
return $purchases;
}
public function diff(Garage $before): array
{
$diff = array();
// general data
if ($this->mobileAssociated !== $before->mobileAssociated) {
$diff[] = ['garage.mobile_associated', $this->mobileAssociated];
}
if ($this->phone !== $before->phone) {
$diff[] = ['garage.phone', $this->phone];
}
if ($this->mobile !== $before->mobile) {
$diff[] = ['garage.mobile', $this->mobile];
}
if ($this->whatsapp !== $before->whatsapp) {
$diff[] = ['garage.whatsapp', $this->whatsapp];
}
if ($this->whatsappCampaigns !== $before->whatsappCampaigns) {
$diff[] = ['garage.whatsapp_campaigns', $this->whatsappCampaigns];
}
if ($this->whatsappCampaignsName !== $before->whatsappCampaignsName) {
$diff[] = ['garage.whatsapp_campaigns_name', $this->whatsappCampaignsName];
}
if ($this->facebookUrl !== $before->facebookUrl) {
$diff[] = ['garage.facebook', $this->facebookUrl];
}
if ($this->twitterUrl !== $before->twitterUrl) {
$diff[] = ['garage.twitter', $this->twitterUrl];
}
if ($this->instagramUrl !== $before->instagramUrl) {
$diff[] = ['garage.instagram', $this->instagramUrl];
}
// timetable_data
$schedulesDiff = $this->schedules->diff($before->schedules);
if (!empty($schedulesDiff)) {
$diff[] = ['garage.form.timetable_data', $schedulesDiff];
}
// address
$addressDiff = $this->address->diff($before->address);
if (!empty($addressDiff)) {
$diff[] = ['garage.form.address_data', $addressDiff];
}
// additional_addresses_data
if ($this->additionalAddresses->isEmpty() && !$before->additionalAddresses->isEmpty()){
$diff[] = ['garage.form.additional_addresses_data', 'todas las direcciones eliminadas'];
} else if (!$this->additionalAddresses->isEmpty() && $before->additionalAddresses->isEmpty()) {
foreach ($this->additionalAddresses as $address) {
$diff[] = ['garage.form.additional_address_data', $address->displayRawFields()];
}
} else if (!$this->additionalAddresses->isEmpty() && !$before->additionalAddresses->isEmpty()
&& (count($this->additionalAddresses) < count($before->additionalAddresses))) {
$diff[] = ['garage.form.additional_addresses_data', 'hay cambios en las direcciones'];
} else if (!$this->additionalAddresses->isEmpty() && !$before->additionalAddresses->isEmpty()
&& (count($this->additionalAddresses) > count($before->additionalAddresses))) {
$diff[] = ['garage.form.additional_addresses_data', 'hay cambios en las direcciones'];
} else if (!$this->additionalAddresses->isEmpty() && !$before->additionalAddresses->isEmpty()
&& (count($this->additionalAddresses) === count($before->additionalAddresses)))
{
$additionalAddresses = $this->additionalAddresses->getValues(); // because an ArrayCollection could have not sequential indexes
$beforeAddresses = $before->additionalAddresses->getValues();
for ($i = 0; $i < count($additionalAddresses); $i++) {
//if ($additionalAddresses[$i]) { // puede que solo haya las que han sido modificadas
$addressDiff = $additionalAddresses[$i]->diff($beforeAddresses[$i]);
if (!empty($addressDiff)) {
$diff[] = ['garage.form.additional_address_data', $additionalAddresses[$i]->displayRawFields()];
}
//}
}
}
// typeVehicles
if (empty($this->typeVehicles) && !empty($before->typeVehicles)
) {
$diff[] = ['garage.form.vehicle_types_data', 'ítems eliminados'];
} else {
if (
(!empty($this->typeVehicles) && empty($before->typeVehicles))
|| (!empty($this->typeVehicles) && !empty($before->typeVehicles) && (count($this->typeVehicles) !== count($before->typeVehicles)))
)
{
$typeVehiclesNames = array();
/** @var GarageVehicleType $item */
foreach ($this->typeVehicles as $item) {
$typeVehiclesNames[] = $item->getName();
}
$diff[] = ['garage.form.vehicle_types_data', implode(', ', $typeVehiclesNames)];
}
}
// facilities
if (empty($this->facilities) && !empty($before->facilities)
) {
$diff[] = ['garage.form.comforts_data', 'ítems eliminados'];
} else {
if (
(!empty($this->facilities) && empty($before->facilities))
|| (!empty($this->facilities) && !empty($before->facilities) && (count($this->facilities) !== count($before->facilities)))
)
{
$facilitiesNames = array();
/** @var GarageFacility $item */
foreach ($this->facilities as $item) {
$facilitiesNames[] = $item->getName();
}
$diff[] = ['garage.form.comforts_data', implode(', ', $facilitiesNames)];
}
}
// services
if (empty($this->services) && !empty($before->services)
) {
$diff[] = ['garage.form.services_data', 'ítems eliminados'];
} else {
if (
(!empty($this->services) && empty($before->services))
|| (!empty($this->services) && !empty($before->services) && (count($this->services) !== count($before->services)))
)
{
$servicesNames = array();
/** @var GarageService $item */
foreach ($this->services as $item) {
$servicesNames[] = $item->getName();
}
$diff[] = ['garage.form.services_data', implode(', ', $servicesNames)];
}
}
return $diff;
}
public function __toString(): string
{
return $this->id ? $this->getName() : MiniAbstractBase::DEFAULT_EMPTY_STRING;
}
}