src/App/Model/Mobile/Shortcut.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Model\Mobile;
  3. use JsonSerializable;
  4. use Serializable;
  5. /**
  6.  *
  7.  */
  8. final class Shortcut implements SerializableJsonSerializable
  9. {
  10.     const ICONS = [
  11.         'covid' => 'COVID-19',
  12.         'health' => 'Health and Safety',
  13.         'directory' => 'Directory',
  14.         'bell' => 'Bell Schedule',
  15.         'budget' => 'Budgets',
  16.         'lunch' => 'Lunch Menu',
  17.         'agenda' => 'Agenda and Minutes',
  18.         'principal' => 'Principal and Minutes',
  19.         'board' => 'Board of Education',
  20.         'pto' => 'PTO',
  21.         'helpdesk' => 'Helpdesk',
  22.         'title-ix' => 'Title IX',
  23.         'links' => 'Links',
  24.         'calendar' => 'Calendar',
  25.         'bus' => 'Bus Routes',
  26.         'backpack' => 'Virtual Backpack',
  27.         'handbook' => 'Handbook',
  28.         'forms' => 'Forms',
  29.         'documents' => 'Documents',
  30.         'grades' => 'Check Grades',
  31.         'pay-lunch' => 'Pay Lunch Fees',
  32.         'photo-gallery' => 'Photo Gallery',
  33.         'uniform' => 'Spirit Wear',
  34.     ];
  35.     /**
  36.      * @var bool
  37.      */
  38.     protected bool $promoted false;
  39.     /**
  40.      * @var string|null
  41.      */
  42.     protected ?string $icon null;
  43.     /**
  44.      * @var string|null
  45.      */
  46.     protected ?string $name null;
  47.     /**
  48.      * @var string|null
  49.      */
  50.     protected ?string $link null;
  51.     /**
  52.      * @return bool
  53.      */
  54.     public function isBlank(): bool
  55.     {
  56.         return empty($this->getName()) || empty($this->getLink());
  57.     }
  58.     /**
  59.      * @return bool
  60.      */
  61.     public function isPromoted(): bool
  62.     {
  63.         return $this->promoted;
  64.     }
  65.     /**
  66.      * @param bool $promoted
  67.      * @return $this
  68.      */
  69.     public function setPromoted(bool $promoted): self
  70.     {
  71.         $this->promoted $promoted;
  72.         return $this;
  73.     }
  74.     /**
  75.      * @return string|null
  76.      */
  77.     public function getIcon(): ?string
  78.     {
  79.         return $this->icon;
  80.     }
  81.     /**
  82.      * @param string|null $icon
  83.      * @return $this
  84.      */
  85.     public function setIcon(?string $icon): self
  86.     {
  87.         if ( ! array_key_exists($iconself::ICONS)) {
  88.             $icon null;
  89.         }
  90.         $this->icon $icon;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return string|null
  95.      */
  96.     public function getName(): ?string
  97.     {
  98.         return $this->name;
  99.     }
  100.     /**
  101.      * @param string|null $name
  102.      * @return $this
  103.      */
  104.     public function setName(?string $name): self
  105.     {
  106.         $this->name $name;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @return string|null
  111.      */
  112.     public function getLink(): ?string
  113.     {
  114.         return $this->link;
  115.     }
  116.     /**
  117.      * @param string|null $link
  118.      * @return $this
  119.      */
  120.     public function setLink(?string $link): self
  121.     {
  122.         $this->link $link;
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return array
  127.      */
  128.     public function toArray(): array
  129.     {
  130.         return [
  131.             'name' => $this->getName(),
  132.             'icon' => $this->getIcon(),
  133.             'link' => $this->getLink(),
  134.             'promoted' => $this->isPromoted(),
  135.         ];
  136.     }
  137.     /**
  138.      * {@inheritDoc}
  139.      */
  140.     public function jsonSerialize(): array
  141.     {
  142.         return $this->toArray();
  143.     }
  144.     /**
  145.      * {@inheritDoc}
  146.      */
  147.     public function serialize(): string
  148.     {
  149.         return json_encode($this);
  150.     }
  151.     /**
  152.      * {@inheritDoc}
  153.      */
  154.     public function unserialize($data): void
  155.     {
  156.         $this->fromArray(
  157.             json_decode($datatrue)
  158.         );
  159.     }
  160.     /**
  161.      * @param array $data
  162.      * @return $this
  163.      */
  164.     public function fromArray(array $data): self
  165.     {
  166.         return $this
  167.             ->setPromoted($data['promoted'] ?: false)
  168.             ->setIcon($data['icon'] ?: null)
  169.             ->setName($data['name'] ?: null)
  170.             ->setLink($data['link'] ?: null)
  171.         ;
  172.     }
  173.     /**
  174.      * @param array $data
  175.      * @return Shortcut
  176.      */
  177.     static public function build(array $data): Shortcut
  178.     {
  179.         return (new Shortcut())->fromArray($data);
  180.     }
  181. }