src/App/Entity/System/SchoolDetailsEmbeddable.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System;
  3. use App\Entity\Structs\AddressEmbeddable;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Embeddable()
  7.  */
  8. class SchoolDetailsEmbeddable
  9. {
  10.     const LINKS = [
  11.         self::LINKS__WEBSITE,
  12.         self::LINKS__FACEBOOK,
  13.         self::LINKS__TWITTER,
  14.         self::LINKS__YOUTUBE,
  15.         self::LINKS__INSTAGRAM,
  16.     ];
  17.     const LINKS__WEBSITE 'website';
  18.     const LINKS__FACEBOOK 'facebook';
  19.     const LINKS__TWITTER 'twitter';
  20.     const LINKS__YOUTUBE 'youtube';
  21.     const LINKS__INSTAGRAM 'instagram';
  22.     /**
  23.      * @var AddressEmbeddable
  24.      *
  25.      * @ORM\Embedded(
  26.      *     class = AddressEmbeddable::class,
  27.      *     columnPrefix = "address_"
  28.      * )
  29.      */
  30.     protected AddressEmbeddable $address;
  31.     /**
  32.      * @var string|null
  33.      *
  34.      * @ORM\Column(
  35.      *     type = "string",
  36.      *     nullable = true,
  37.      * )
  38.      */
  39.     protected ?string $phone null;
  40.     /**
  41.      * @var string|null
  42.      *
  43.      * @ORM\Column(
  44.      *     type = "string",
  45.      *     nullable = true,
  46.      * )
  47.      */
  48.     protected ?string $fax null;
  49.     /**
  50.      * @var array|null|string[]
  51.      *
  52.      * @ORM\Column(
  53.      *     type = "json",
  54.      *     nullable = true,
  55.      * )
  56.      */
  57.     protected ?array $links = [];
  58.     /**
  59.      * @var array|null|string[]
  60.      *
  61.      * @ORM\Column(
  62.      *     type = "json",
  63.      *     nullable = true,
  64.      * )
  65.      */
  66.     protected ?array $inquiryEmails = [];
  67.     /**
  68.      * @var array|null|string[]
  69.      *
  70.      * @ORM\Column(
  71.      *     type = "json",
  72.      *     nullable = true,
  73.      * )
  74.      */
  75.     protected ?array $checkupEmails = [];
  76.     /**
  77.      * @var string|null
  78.      *
  79.      * @ORM\Column(
  80.      *     type = "string",
  81.      *     nullable = true,
  82.      * )
  83.      */
  84.     protected ?string $sisUrl null;
  85.     /**
  86.      * @var bool
  87.      *
  88.      * @ORM\Column(
  89.      *     type = "boolean",
  90.      *     nullable = false,
  91.      *     options = {
  92.      *         "default" = true,
  93.      *     },
  94.      * )
  95.      */
  96.     protected bool $contactManagement true;
  97.     /**
  98.      *
  99.      */
  100.     public function __construct()
  101.     {
  102.         $this->address = new AddressEmbeddable();
  103.     }
  104.     /**
  105.      * @return AddressEmbeddable
  106.      */
  107.     public function getAddress(): AddressEmbeddable
  108.     {
  109.         return $this->address;
  110.     }
  111.     /**
  112.      * @param array $names
  113.      * @return array|string[]
  114.      */
  115.     public function getLinks(array $names = []): array
  116.     {
  117.         if ( ! $names) {
  118.             return $this->links ?? [];
  119.         }
  120.         $filtered = [];
  121.         foreach ($names as $name) {
  122.             $filtered[$name] = $this->getLink($name);
  123.         }
  124.         return $filtered;
  125.     }
  126.     /**
  127.      * @param array $links
  128.      * @return $this
  129.      */
  130.     public function setLinks(array $links): self
  131.     {
  132.         foreach (array_keys($links) as $name) {
  133.             if ( ! in_array($nameself::LINKS)) {
  134.                 unset($links['name']);
  135.             }
  136.         }
  137.         ksort($links);
  138.         $this->links array_filter($links);
  139.         return $this;
  140.     }
  141.     /**
  142.      * @param string $name
  143.      * @return bool
  144.      */
  145.     public function hasLink(string $name): bool
  146.     {
  147.         return isset($this->links[$name]);
  148.     }
  149.     /**
  150.      * @param string $name
  151.      * @return string|null
  152.      */
  153.     public function getLink(string $name): ?string
  154.     {
  155.         return ($this->hasLink($name)) ? ($this->links[$name] ?: null) : null;
  156.     }
  157.     /**
  158.      * @param string $name
  159.      * @param string|null $link
  160.      * @return $this
  161.      */
  162.     public function setLink(string $name, ?string $link): self
  163.     {
  164.         if ( ! in_array($nameself::LINKS)) {
  165.             throw new \Exception();
  166.         }
  167.         if ( ! $link) {
  168.             unset($this->links[$name]);
  169.         } else {
  170.             $this->links[$name] = $link;
  171.             ksort($this->links);
  172.         }
  173.         return $this;
  174.     }
  175.     /**
  176.      * @return string|null
  177.      */
  178.     public function getPhone(): ?string
  179.     {
  180.         return $this->phone;
  181.     }
  182.     /**
  183.      * @param string|null $phone
  184.      * @return $this
  185.      */
  186.     public function setPhone(?string $phone): self
  187.     {
  188.         $this->phone $phone;
  189.         return $this;
  190.     }
  191.     /**
  192.      * @return string|null
  193.      */
  194.     public function getFax(): ?string
  195.     {
  196.         return $this->fax;
  197.     }
  198.     /**
  199.      * @param string|null $fax
  200.      * @return $this
  201.      */
  202.     public function setFax(?string $fax): self
  203.     {
  204.         $this->fax $fax;
  205.         return $this;
  206.     }
  207.     /**
  208.      * @return bool
  209.      */
  210.     public function hasInquiryEmails(): bool
  211.     {
  212.         return (count($this->getInquiryEmails()) > 0);
  213.     }
  214.     /**
  215.      * @return array|string[]
  216.      */
  217.     public function getInquiryEmails(): array
  218.     {
  219.         return $this->inquiryEmails ?? [];
  220.     }
  221.     /**
  222.      * @param array $inquiryEmails
  223.      * @return $this
  224.      */
  225.     public function setInquiryEmails(array $inquiryEmails): self
  226.     {
  227.         $this->inquiryEmails array_values(array_filter(array_unique($inquiryEmails)));
  228.         sort($this->inquiryEmails);
  229.         return $this;
  230.     }
  231.     /**
  232.      * @return array|string[]
  233.      */
  234.     public function getCheckupEmails(): array
  235.     {
  236.         return $this->checkupEmails ?? [];
  237.     }
  238.     /**
  239.      * @param array $checkupEmails
  240.      * @return $this
  241.      */
  242.     public function setCheckupEmails(array $checkupEmails): self
  243.     {
  244.         $this->checkupEmails array_values(array_filter(array_unique($checkupEmails)));
  245.         sort($this->checkupEmails);
  246.         return $this;
  247.     }
  248.     /**
  249.      * @return string|null
  250.      */
  251.     public function getSisUrl(): ?string
  252.     {
  253.         return $this->sisUrl;
  254.     }
  255.     /**
  256.      * @param string|null $sisUrl
  257.      * @return $this
  258.      */
  259.     public function setSisUrl(?string $sisUrl): self
  260.     {
  261.         $this->sisUrl $sisUrl;
  262.         return $this;
  263.     }
  264.     /**
  265.      * @return bool
  266.      */
  267.     public function isContactManagement(): bool
  268.     {
  269.         return $this->contactManagement;
  270.     }
  271.     /**
  272.      * @param bool $contactManagement
  273.      * @return self
  274.      */
  275.     public function setContactManagement(bool $contactManagement): self
  276.     {
  277.         $this->contactManagement $contactManagement;
  278.         return $this;
  279.     }
  280. }