<?php
namespace App\Model\Mobile;
use JsonSerializable;
use Serializable;
/**
*
*/
final class Shortcut implements Serializable, JsonSerializable
{
const ICONS = [
'covid' => 'COVID-19',
'health' => 'Health and Safety',
'directory' => 'Directory',
'bell' => 'Bell Schedule',
'budget' => 'Budgets',
'lunch' => 'Lunch Menu',
'agenda' => 'Agenda and Minutes',
'principal' => 'Principal and Minutes',
'board' => 'Board of Education',
'pto' => 'PTO',
'helpdesk' => 'Helpdesk',
'title-ix' => 'Title IX',
'links' => 'Links',
'calendar' => 'Calendar',
'bus' => 'Bus Routes',
'backpack' => 'Virtual Backpack',
'handbook' => 'Handbook',
'forms' => 'Forms',
'documents' => 'Documents',
'grades' => 'Check Grades',
'pay-lunch' => 'Pay Lunch Fees',
'photo-gallery' => 'Photo Gallery',
'uniform' => 'Spirit Wear',
];
/**
* @var bool
*/
protected bool $promoted = false;
/**
* @var string|null
*/
protected ?string $icon = null;
/**
* @var string|null
*/
protected ?string $name = null;
/**
* @var string|null
*/
protected ?string $link = null;
/**
* @return bool
*/
public function isBlank(): bool
{
return empty($this->getName()) || empty($this->getLink());
}
/**
* @return bool
*/
public function isPromoted(): bool
{
return $this->promoted;
}
/**
* @param bool $promoted
* @return $this
*/
public function setPromoted(bool $promoted): self
{
$this->promoted = $promoted;
return $this;
}
/**
* @return string|null
*/
public function getIcon(): ?string
{
return $this->icon;
}
/**
* @param string|null $icon
* @return $this
*/
public function setIcon(?string $icon): self
{
if ( ! array_key_exists($icon, self::ICONS)) {
$icon = null;
}
$this->icon = $icon;
return $this;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string|null $name
* @return $this
*/
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return string|null
*/
public function getLink(): ?string
{
return $this->link;
}
/**
* @param string|null $link
* @return $this
*/
public function setLink(?string $link): self
{
$this->link = $link;
return $this;
}
/**
* @return array
*/
public function toArray(): array
{
return [
'name' => $this->getName(),
'icon' => $this->getIcon(),
'link' => $this->getLink(),
'promoted' => $this->isPromoted(),
];
}
/**
* {@inheritDoc}
*/
public function jsonSerialize(): array
{
return $this->toArray();
}
/**
* {@inheritDoc}
*/
public function serialize(): string
{
return json_encode($this);
}
/**
* {@inheritDoc}
*/
public function unserialize($data): void
{
$this->fromArray(
json_decode($data, true)
);
}
/**
* @param array $data
* @return $this
*/
public function fromArray(array $data): self
{
return $this
->setPromoted($data['promoted'] ?: false)
->setIcon($data['icon'] ?: null)
->setName($data['name'] ?: null)
->setLink($data['link'] ?: null)
;
}
/**
* @param array $data
* @return Shortcut
*/
static public function build(array $data): Shortcut
{
return (new Shortcut())->fromArray($data);
}
}