<?php
namespace App\Entity\System;
use App\Entity\Structs\AddressEmbeddable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Embeddable()
*/
class SchoolDetailsEmbeddable
{
const LINKS = [
self::LINKS__WEBSITE,
self::LINKS__FACEBOOK,
self::LINKS__TWITTER,
self::LINKS__YOUTUBE,
self::LINKS__INSTAGRAM,
];
const LINKS__WEBSITE = 'website';
const LINKS__FACEBOOK = 'facebook';
const LINKS__TWITTER = 'twitter';
const LINKS__YOUTUBE = 'youtube';
const LINKS__INSTAGRAM = 'instagram';
/**
* @var AddressEmbeddable
*
* @ORM\Embedded(
* class = AddressEmbeddable::class,
* columnPrefix = "address_"
* )
*/
protected AddressEmbeddable $address;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $phone = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $fax = null;
/**
* @var array|null|string[]
*
* @ORM\Column(
* type = "json",
* nullable = true,
* )
*/
protected ?array $links = [];
/**
* @var array|null|string[]
*
* @ORM\Column(
* type = "json",
* nullable = true,
* )
*/
protected ?array $inquiryEmails = [];
/**
* @var array|null|string[]
*
* @ORM\Column(
* type = "json",
* nullable = true,
* )
*/
protected ?array $checkupEmails = [];
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $sisUrl = null;
/**
* @var bool
*
* @ORM\Column(
* type = "boolean",
* nullable = false,
* options = {
* "default" = true,
* },
* )
*/
protected bool $contactManagement = true;
/**
*
*/
public function __construct()
{
$this->address = new AddressEmbeddable();
}
/**
* @return AddressEmbeddable
*/
public function getAddress(): AddressEmbeddable
{
return $this->address;
}
/**
* @param array $names
* @return array|string[]
*/
public function getLinks(array $names = []): array
{
if ( ! $names) {
return $this->links ?? [];
}
$filtered = [];
foreach ($names as $name) {
$filtered[$name] = $this->getLink($name);
}
return $filtered;
}
/**
* @param array $links
* @return $this
*/
public function setLinks(array $links): self
{
foreach (array_keys($links) as $name) {
if ( ! in_array($name, self::LINKS)) {
unset($links['name']);
}
}
ksort($links);
$this->links = array_filter($links);
return $this;
}
/**
* @param string $name
* @return bool
*/
public function hasLink(string $name): bool
{
return isset($this->links[$name]);
}
/**
* @param string $name
* @return string|null
*/
public function getLink(string $name): ?string
{
return ($this->hasLink($name)) ? ($this->links[$name] ?: null) : null;
}
/**
* @param string $name
* @param string|null $link
* @return $this
*/
public function setLink(string $name, ?string $link): self
{
if ( ! in_array($name, self::LINKS)) {
throw new \Exception();
}
if ( ! $link) {
unset($this->links[$name]);
} else {
$this->links[$name] = $link;
ksort($this->links);
}
return $this;
}
/**
* @return string|null
*/
public function getPhone(): ?string
{
return $this->phone;
}
/**
* @param string|null $phone
* @return $this
*/
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
/**
* @return string|null
*/
public function getFax(): ?string
{
return $this->fax;
}
/**
* @param string|null $fax
* @return $this
*/
public function setFax(?string $fax): self
{
$this->fax = $fax;
return $this;
}
/**
* @return bool
*/
public function hasInquiryEmails(): bool
{
return (count($this->getInquiryEmails()) > 0);
}
/**
* @return array|string[]
*/
public function getInquiryEmails(): array
{
return $this->inquiryEmails ?? [];
}
/**
* @param array $inquiryEmails
* @return $this
*/
public function setInquiryEmails(array $inquiryEmails): self
{
$this->inquiryEmails = array_values(array_filter(array_unique($inquiryEmails)));
sort($this->inquiryEmails);
return $this;
}
/**
* @return array|string[]
*/
public function getCheckupEmails(): array
{
return $this->checkupEmails ?? [];
}
/**
* @param array $checkupEmails
* @return $this
*/
public function setCheckupEmails(array $checkupEmails): self
{
$this->checkupEmails = array_values(array_filter(array_unique($checkupEmails)));
sort($this->checkupEmails);
return $this;
}
/**
* @return string|null
*/
public function getSisUrl(): ?string
{
return $this->sisUrl;
}
/**
* @param string|null $sisUrl
* @return $this
*/
public function setSisUrl(?string $sisUrl): self
{
$this->sisUrl = $sisUrl;
return $this;
}
/**
* @return bool
*/
public function isContactManagement(): bool
{
return $this->contactManagement;
}
/**
* @param bool $contactManagement
* @return self
*/
public function setContactManagement(bool $contactManagement): self
{
$this->contactManagement = $contactManagement;
return $this;
}
}