src/Entity/CompanyDocumentAddress.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  6. /**
  7.  * @ORM\Entity
  8.  */
  9. class CompanyDocumentAddress extends CompanyAddress
  10. {
  11.     /**
  12.      * @param string $name
  13.      */
  14.     public function __construct(string $name)
  15.     {
  16.         parent::__construct($name);
  17.     }
  18.     public function __clone()
  19.     {
  20.         $this->id null;
  21.     }
  22.     /**
  23.      * @return Company|null
  24.      */
  25.     public function getCompany(): ?Company
  26.     {
  27.         return null;
  28.     }
  29.     /**
  30.      * @return string
  31.      */
  32.     public function getType(): string
  33.     {
  34.         return 'document';
  35.     }
  36.     /**
  37.      * @param AddressInterface $address
  38.      *
  39.      * @return CompanyDocumentAddress
  40.      */
  41.     public static function create(AddressInterface $address): CompanyDocumentAddress
  42.     {
  43.         $obj = new self($address->getName());
  44.         $obj->populate($address);
  45.         return $obj;
  46.     }
  47.     /**
  48.      * @param bool $includeVat
  49.      *
  50.      * @return bool
  51.      */
  52.     public function isEmpty(bool $includeVat true): bool
  53.     {
  54.         $name trim($this->name);
  55.         if (empty($name)) {
  56.             $name null;
  57.         }
  58.         return
  59.             null === $name &&
  60.             null === $this->contactPersonName &&
  61.             null === $this->contactPersonEmail &&
  62.             null === $this->addressRow1 &&
  63.             null === $this->addressRow2 &&
  64.             null === $this->addressRow3 &&
  65.             null === $this->addressRow4 &&
  66.             null === $this->postalCode &&
  67.             null === $this->city &&
  68.             null === $this->country &&
  69.             (!$includeVat || null === $this->vatId);
  70.     }
  71.     /**
  72.      * @param AddressInterface $address
  73.      */
  74.     public function populate(AddressInterface $address): void
  75.     {
  76.         $this->setName($address->getName());
  77.         $this->setContactPersonName($address->getContactPersonName());
  78.         $this->setContactPersonEmail($address->getContactPersonEmail());
  79.         $this->setAddressRow1($address->getAddressRow1());
  80.         $this->setAddressRow2($address->getAddressRow2());
  81.         $this->setAddressRow3($address->getAddressRow3());
  82.         $this->setAddressRow4($address->getAddressRow4());
  83.         $this->setPostalCode($address->getPostalCode());
  84.         $this->setCity($address->getCity());
  85.         $this->setCountry($address->getCountry());
  86.         $this->setVatId($address->getVatId());
  87.     }
  88.     /**
  89.      * @Assert\Callback(groups={"Offer"})
  90.      */
  91.     public function validate(ExecutionContextInterface $context): void
  92.     {
  93.         $name trim($this->name);
  94.         if (empty($name)) {
  95.             $name null;
  96.         }
  97.         if (!$this->isEmpty() && empty($name)) {
  98.             $context->buildViolation('validation.name.empty')
  99.                 ->setTranslationDomain('CompanyAddress')
  100.                 ->atPath('name')
  101.                 ->addViolation();
  102.         }
  103.     }
  104. }