src/App/Entity/System/School.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System;
  3. use App\Entity\Shared\UlidTransitionalInterface;
  4. use App\Entity\Shared\UlidTransitionalTrait;
  5. use App\Entity\System\SocialAccounts\FacebookSocialAccount;
  6. use App\Entity\System\SocialAccounts\InstagramSocialAccount;
  7. use App\Entity\System\SocialAccounts\TwitterSocialAccount;
  8. use Cms\ContainerBundle\Entity\Containers\GenericContainer;
  9. use Cms\CoreBundle\Model\Interfaces\Loggable\LoggableInterface;
  10. use Cms\TenantBundle\Entity\TenantedEntity;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\Common\Collections\Criteria;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Reinder83\BinaryFlags\Bits;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. /**
  18.  * Class School
  19.  * @package App\Entity\System
  20.  *
  21.  * @ORM\Entity(
  22.  *     repositoryClass = "App\Doctrine\Repository\System\SchoolRepository",
  23.  * )
  24.  * @ORM\Table(
  25.  *     name = "sys__school",
  26.  * )
  27.  */
  28. class School extends TenantedEntity implements UlidTransitionalInterfaceLoggableInterface
  29. {
  30.     const TYPES = [
  31.         'district' => self::TYPES__DISTRICT,
  32.         'elementary' => self::TYPES__ELEMENTARY,
  33.         'middle' => self::TYPES__MIDDLE,
  34.         'high' => self::TYPES__HIGH,
  35.         'other' => self::TYPES__OTHER,
  36.     ];
  37.     const ALL_TYPES self::TYPES__DISTRICT
  38.         self::TYPES__ELEMENTARY
  39.         self::TYPES__MIDDLE
  40.         self::TYPES__HIGH
  41.         self::TYPES__OTHER
  42.     ;
  43.     const TYPES__DISTRICT Bits::BIT_1;
  44.     const TYPES__PRIMARY Bits::BIT_2;
  45.     const TYPES__ELEMENTARY Bits::BIT_3;
  46.     const TYPES__INTERMEDIATE Bits::BIT_4;
  47.     const TYPES__MIDDLE Bits::BIT_5;
  48.     const TYPES__JUNIOR_HIGH Bits::BIT_6;
  49.     const TYPES__HIGH Bits::BIT_7;
  50.     const TYPES__VOCATIONAL Bits::BIT_8;
  51.     const TYPES__OTHER Bits::BIT_9;
  52.     use UlidTransitionalTrait;
  53.     /**
  54.      * @var string|null
  55.      *
  56.      * @ORM\Column(
  57.      *     type = "string",
  58.      *     nullable = false,
  59.      * )
  60.      *
  61.      * @Groups({"school", "school_minimal"})
  62.      *
  63.      */
  64.     protected ?string $name null;
  65.     /**
  66.      * @var int
  67.      *
  68.      * @ORM\Column(
  69.      *     type = "integer",
  70.      *     nullable = false,
  71.      *     options = {
  72.      *         "default" = self::TYPES__OTHER,
  73.      *     },
  74.      * )
  75.      *
  76.      *  @Groups({"school", "school_minimal"})
  77.      *
  78.      */
  79.     protected int $type self::TYPES__OTHER;
  80.     /**
  81.      * @var GenericContainer|null
  82.      *
  83.      * @ORM\ManyToOne(
  84.      *     targetEntity = "Cms\ContainerBundle\Entity\Containers\GenericContainer",
  85.      * )
  86.      * @ORM\JoinColumn(
  87.      *     name = "department",
  88.      *     referencedColumnName = "id",
  89.      *     nullable = true,
  90.      *     onDelete = "SET NULL",
  91.      * )
  92.      *
  93.      * @Groups({"department", "department_minimal"})
  94.      */
  95.     protected ?GenericContainer $department null;
  96.     /**
  97.      * @var string|null
  98.      *
  99.      * @ORM\Column(
  100.      *     type = "string",
  101.      *     nullable = true,
  102.      * )
  103.      */
  104.     protected ?string $oneRosterOrg null;
  105.     /**
  106.      * @var Collection|SocialAccount[]
  107.      *
  108.      * @ORM\ManyToMany(
  109.      *     targetEntity = "App\Entity\System\SocialAccount",
  110.      * )
  111.      * @ORM\JoinTable(
  112.      *     name = "sys__school_x_social_account",
  113.      *     joinColumns = {
  114.      *         @ORM\JoinColumn(
  115.      *             name = "school",
  116.      *             referencedColumnName = "id",
  117.      *             onDelete = "CASCADE",
  118.      *         ),
  119.      *     },
  120.      *     inverseJoinColumns = {
  121.      *         @ORM\JoinColumn(
  122.      *             name = "socialAccount",
  123.      *             referencedColumnName = "id",
  124.      *             onDelete = "CASCADE",
  125.      *         ),
  126.      *     },
  127.      * )
  128.      */
  129.     protected Collection $socialAccounts;
  130.     /**
  131.      * @var SchoolDetailsEmbeddable
  132.      *
  133.      * @ORM\Embedded(
  134.      *     class = SchoolDetailsEmbeddable::class,
  135.      *     columnPrefix = "details_"
  136.      * )
  137.      */
  138.     protected SchoolDetailsEmbeddable $details;
  139.     /**
  140.      * @var SchoolBrandingEmbeddable
  141.      *
  142.      * @ORM\Embedded(
  143.      *     class = SchoolBrandingEmbeddable::class,
  144.      *     columnPrefix = "branding_"
  145.      * )
  146.      */
  147.     protected SchoolBrandingEmbeddable $branding;
  148.     /**
  149.      * @var SchoolMobileEmbeddable
  150.      *
  151.      * @ORM\Embedded(
  152.      *     class = SchoolMobileEmbeddable::class,
  153.      *     columnPrefix = "mobile_"
  154.      * )
  155.      */
  156.     protected SchoolMobileEmbeddable $mobile;
  157.     /**
  158.      *
  159.      */
  160.     public function __construct()
  161.     {
  162.         $this->socialAccounts = new ArrayCollection();
  163.         $this->details = new SchoolDetailsEmbeddable();
  164.         $this->branding = new SchoolBrandingEmbeddable();
  165.         $this->mobile = new SchoolMobileEmbeddable();
  166.     }
  167.     /**
  168.      * @return string|null
  169.      *
  170.      */
  171.     public function getName(): ?string
  172.     {
  173.         return $this->name;
  174.     }
  175.     /**
  176.      * @param string $name
  177.      * @return $this
  178.      */
  179.     public function setName(string $name): self
  180.     {
  181.         $this->name $name;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return int
  186.      */
  187.     public function getType(): int
  188.     {
  189.         return $this->type;
  190.     }
  191.     /**
  192.      * @return string
  193.      */
  194.     public function getTypeName(): string
  195.     {
  196.         return array_search($this->getType(), self::TYPES);
  197.     }
  198.     /**
  199.      * @param int $type
  200.      * @return $this
  201.      */
  202.     public function setType(int $type): self
  203.     {
  204.         $this->type $type;
  205.         return $this;
  206.     }
  207.     /**
  208.      * @param int $type
  209.      * @return bool
  210.      */
  211.     public function isType(int $type): bool
  212.     {
  213.         return ($this->getType() === $type);
  214.     }
  215.     /**
  216.      * @return bool
  217.      */
  218.     public function isTypeDistrict(): bool
  219.     {
  220.         return $this->isType(self::TYPES__DISTRICT);
  221.     }
  222.     /**
  223.      * @return GenericContainer|null
  224.      */
  225.     public function getDepartment(): ?GenericContainer
  226.     {
  227.         return $this->department;
  228.     }
  229.     /**
  230.      * @param GenericContainer|null $department
  231.      * @return $this
  232.      */
  233.     public function setDepartment(?GenericContainer $department): self
  234.     {
  235.         $this->department $department;
  236.         return $this;
  237.     }
  238.     /**
  239.      * @return string|null
  240.      */
  241.     public function getOneRosterOrg(): ?string
  242.     {
  243.         return $this->oneRosterOrg;
  244.     }
  245.     /**
  246.      * @param string|null $oneRosterOrg
  247.      * @return $this
  248.      */
  249.     public function setOneRosterOrg(?string $oneRosterOrg): self
  250.     {
  251.         $this->oneRosterOrg $oneRosterOrg;
  252.         return $this;
  253.     }
  254.     /**
  255.      * @param Criteria|null $criteria
  256.      * @return Collection|SocialAccount[]
  257.      */
  258.     public function getSocialAccounts(?Criteria $criteria null): Collection
  259.     {
  260.         if ( ! $this->socialAccounts instanceof Collection) {
  261.             $this->socialAccounts = new ArrayCollection();
  262.         }
  263.         if ( ! empty($criteria)) {
  264.             return $this->socialAccounts->matching($criteria);
  265.         }
  266.         return $this->socialAccounts;
  267.     }
  268.     /**
  269.      * @return Collection|FacebookSocialAccount[]
  270.      */
  271.     public function getFacebookSocialAccounts(): Collection {
  272.         return $this->getSocialAccounts()->filter(function(SocialAccount $socialAccount) {
  273.             return $socialAccount instanceof FacebookSocialAccount;
  274.         });
  275.     }
  276.     /**
  277.      * @return Collection|InstagramSocialAccount[]
  278.      */
  279.     public function getInstagramSocialAccounts(): Collection {
  280.         return $this->getSocialAccounts()->filter(function(SocialAccount $socialAccount) {
  281.             return $socialAccount instanceof InstagramSocialAccount;
  282.         });
  283.     }
  284.     /**
  285.      * @return Collection|TwitterSocialAccount[]
  286.      */
  287.     public function getTwitterSocialAccounts(): Collection {
  288.         return $this->getSocialAccounts()->filter(function(SocialAccount $socialAccount) {
  289.             return $socialAccount instanceof TwitterSocialAccount;
  290.         });
  291.     }
  292.     /**
  293.      * @return SchoolDetailsEmbeddable
  294.      */
  295.     public function getDetails(): SchoolDetailsEmbeddable
  296.     {
  297.         return $this->details;
  298.     }
  299.     /**
  300.      * @return SchoolBrandingEmbeddable
  301.      */
  302.     public function getBranding(): SchoolBrandingEmbeddable
  303.     {
  304.         return $this->branding;
  305.     }
  306.     /**
  307.      * @return SchoolMobileEmbeddable
  308.      */
  309.     public function getMobile(): SchoolMobileEmbeddable
  310.     {
  311.         return $this->mobile;
  312.     }
  313.     /**
  314.      * @return string
  315.      */
  316.     public function __toString(): string
  317.     {
  318.         return $this->getUlidAsString();
  319.     }
  320.     /**
  321.      * {@inheritDoc}
  322.      */
  323.     public function getLoggableDetails(): array
  324.     {
  325.         return [
  326.             'id' => (string) $this->getId(),
  327.             'title' => $this->getName(),
  328.         ];
  329.     }
  330. }