<?php
namespace App\Entity\System;
use App\Entity\Shared\UlidTransitionalInterface;
use App\Entity\Shared\UlidTransitionalTrait;
use App\Entity\System\SocialAccounts\FacebookSocialAccount;
use App\Entity\System\SocialAccounts\InstagramSocialAccount;
use App\Entity\System\SocialAccounts\TwitterSocialAccount;
use Cms\ContainerBundle\Entity\Containers\GenericContainer;
use Cms\CoreBundle\Model\Interfaces\Loggable\LoggableInterface;
use Cms\TenantBundle\Entity\TenantedEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Reinder83\BinaryFlags\Bits;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Class School
* @package App\Entity\System
*
* @ORM\Entity(
* repositoryClass = "App\Doctrine\Repository\System\SchoolRepository",
* )
* @ORM\Table(
* name = "sys__school",
* )
*/
class School extends TenantedEntity implements UlidTransitionalInterface, LoggableInterface
{
const TYPES = [
'district' => self::TYPES__DISTRICT,
'elementary' => self::TYPES__ELEMENTARY,
'middle' => self::TYPES__MIDDLE,
'high' => self::TYPES__HIGH,
'other' => self::TYPES__OTHER,
];
const ALL_TYPES = self::TYPES__DISTRICT
| self::TYPES__ELEMENTARY
| self::TYPES__MIDDLE
| self::TYPES__HIGH
| self::TYPES__OTHER
;
const TYPES__DISTRICT = Bits::BIT_1;
const TYPES__PRIMARY = Bits::BIT_2;
const TYPES__ELEMENTARY = Bits::BIT_3;
const TYPES__INTERMEDIATE = Bits::BIT_4;
const TYPES__MIDDLE = Bits::BIT_5;
const TYPES__JUNIOR_HIGH = Bits::BIT_6;
const TYPES__HIGH = Bits::BIT_7;
const TYPES__VOCATIONAL = Bits::BIT_8;
const TYPES__OTHER = Bits::BIT_9;
use UlidTransitionalTrait;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = false,
* )
*
* @Groups({"school", "school_minimal"})
*
*/
protected ?string $name = null;
/**
* @var int
*
* @ORM\Column(
* type = "integer",
* nullable = false,
* options = {
* "default" = self::TYPES__OTHER,
* },
* )
*
* @Groups({"school", "school_minimal"})
*
*/
protected int $type = self::TYPES__OTHER;
/**
* @var GenericContainer|null
*
* @ORM\ManyToOne(
* targetEntity = "Cms\ContainerBundle\Entity\Containers\GenericContainer",
* )
* @ORM\JoinColumn(
* name = "department",
* referencedColumnName = "id",
* nullable = true,
* onDelete = "SET NULL",
* )
*
* @Groups({"department", "department_minimal"})
*/
protected ?GenericContainer $department = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $oneRosterOrg = null;
/**
* @var Collection|SocialAccount[]
*
* @ORM\ManyToMany(
* targetEntity = "App\Entity\System\SocialAccount",
* )
* @ORM\JoinTable(
* name = "sys__school_x_social_account",
* joinColumns = {
* @ORM\JoinColumn(
* name = "school",
* referencedColumnName = "id",
* onDelete = "CASCADE",
* ),
* },
* inverseJoinColumns = {
* @ORM\JoinColumn(
* name = "socialAccount",
* referencedColumnName = "id",
* onDelete = "CASCADE",
* ),
* },
* )
*/
protected Collection $socialAccounts;
/**
* @var SchoolDetailsEmbeddable
*
* @ORM\Embedded(
* class = SchoolDetailsEmbeddable::class,
* columnPrefix = "details_"
* )
*/
protected SchoolDetailsEmbeddable $details;
/**
* @var SchoolBrandingEmbeddable
*
* @ORM\Embedded(
* class = SchoolBrandingEmbeddable::class,
* columnPrefix = "branding_"
* )
*/
protected SchoolBrandingEmbeddable $branding;
/**
* @var SchoolMobileEmbeddable
*
* @ORM\Embedded(
* class = SchoolMobileEmbeddable::class,
* columnPrefix = "mobile_"
* )
*/
protected SchoolMobileEmbeddable $mobile;
/**
*
*/
public function __construct()
{
$this->socialAccounts = new ArrayCollection();
$this->details = new SchoolDetailsEmbeddable();
$this->branding = new SchoolBrandingEmbeddable();
$this->mobile = new SchoolMobileEmbeddable();
}
/**
* @return string|null
*
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* @return string
*/
public function getTypeName(): string
{
return array_search($this->getType(), self::TYPES);
}
/**
* @param int $type
* @return $this
*/
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
/**
* @param int $type
* @return bool
*/
public function isType(int $type): bool
{
return ($this->getType() === $type);
}
/**
* @return bool
*/
public function isTypeDistrict(): bool
{
return $this->isType(self::TYPES__DISTRICT);
}
/**
* @return GenericContainer|null
*/
public function getDepartment(): ?GenericContainer
{
return $this->department;
}
/**
* @param GenericContainer|null $department
* @return $this
*/
public function setDepartment(?GenericContainer $department): self
{
$this->department = $department;
return $this;
}
/**
* @return string|null
*/
public function getOneRosterOrg(): ?string
{
return $this->oneRosterOrg;
}
/**
* @param string|null $oneRosterOrg
* @return $this
*/
public function setOneRosterOrg(?string $oneRosterOrg): self
{
$this->oneRosterOrg = $oneRosterOrg;
return $this;
}
/**
* @param Criteria|null $criteria
* @return Collection|SocialAccount[]
*/
public function getSocialAccounts(?Criteria $criteria = null): Collection
{
if ( ! $this->socialAccounts instanceof Collection) {
$this->socialAccounts = new ArrayCollection();
}
if ( ! empty($criteria)) {
return $this->socialAccounts->matching($criteria);
}
return $this->socialAccounts;
}
/**
* @return Collection|FacebookSocialAccount[]
*/
public function getFacebookSocialAccounts(): Collection {
return $this->getSocialAccounts()->filter(function(SocialAccount $socialAccount) {
return $socialAccount instanceof FacebookSocialAccount;
});
}
/**
* @return Collection|InstagramSocialAccount[]
*/
public function getInstagramSocialAccounts(): Collection {
return $this->getSocialAccounts()->filter(function(SocialAccount $socialAccount) {
return $socialAccount instanceof InstagramSocialAccount;
});
}
/**
* @return Collection|TwitterSocialAccount[]
*/
public function getTwitterSocialAccounts(): Collection {
return $this->getSocialAccounts()->filter(function(SocialAccount $socialAccount) {
return $socialAccount instanceof TwitterSocialAccount;
});
}
/**
* @return SchoolDetailsEmbeddable
*/
public function getDetails(): SchoolDetailsEmbeddable
{
return $this->details;
}
/**
* @return SchoolBrandingEmbeddable
*/
public function getBranding(): SchoolBrandingEmbeddable
{
return $this->branding;
}
/**
* @return SchoolMobileEmbeddable
*/
public function getMobile(): SchoolMobileEmbeddable
{
return $this->mobile;
}
/**
* @return string
*/
public function __toString(): string
{
return $this->getUlidAsString();
}
/**
* {@inheritDoc}
*/
public function getLoggableDetails(): array
{
return [
'id' => (string) $this->getId(),
'title' => $this->getName(),
];
}
}