<?php
namespace Cms\ContainerBundle\Entity;
use Cms\ModuleBundle\Model\ModuleConfig;
use Doctrine\ORM\Mapping as ORM;
/**
* Class ModuleFlags
* @package Cms\ContainerBundle\Entity
* @ORM\Embeddable
*/
class ModuleFlags
{
/**
* SCHOOLNOW
*
* @var Container|null
*/
private ?Container $department = null;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
*/
protected $alert = false;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
*/
protected $blog = false;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
*/
protected $calendar = false;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
*/
protected $gallery = false;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
*/
protected $news = false;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
*/
protected $page = true;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
*/
protected $people = false;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
*/
protected $question = false;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
*/
protected $snippet = false;
/**
* @var bool
* @ORM\Column(type = "boolean", nullable = false, options={"default" = false})
*/
protected $feed = false;
/**
* @internal
* @param Container|null $department
* @return $this
*/
public function associateDepartment(?Container $department): self
{
$this->department = $department;
return $this;
}
/**
* @return array|bool[]
*/
public function all()
{
return [
'alert' => $this->isAlert(),
'blog' => $this->isBlog(),
'calendar' => $this->isCalendar(),
'feed' => $this->isFeed(),
'gallery' => $this->isGallery(),
'news' => $this->isNews(),
'page' => $this->isPage(),
'people' => $this->isPeople(),
'question' => $this->isQuestion(),
'snippet' => $this->isSnippet(),
'video' => $this->isVideo(),
];
}
/**
* @return array|string[]
*/
public function enabled()
{
return array_keys(array_filter($this->all()));
}
/**
* @param string|ModuleConfig $module
* @return bool
* @throws \Exception
*/
public function is($module)
{
if ($module instanceof ModuleConfig) {
$module = $module->key();
}
$callable = array(
$this,
sprintf(
'is%s',
ucfirst($module)
)
);
if ( ! is_callable($callable)) {
throw new \Exception();
}
return (call_user_func($callable) === true);
}
/**
* @param string|ModuleConfig $module
* @param bool $value
* @return $this
* @throws \Exception
*/
public function set($module, bool $value)
{
if ($module instanceof ModuleConfig) {
$module = $module->key();
}
$callable = array(
$this,
sprintf(
'set%s',
ucfirst($module)
)
);
if ( ! is_callable($callable)) {
throw new \Exception();
}
return call_user_func($callable, $value);
}
/**
* @param $alert
* @return $this
*/
public function setAlert($alert)
{
$this->alert = $alert;
return $this;
}
/**
* @return bool
*/
public function isAlert()
{
return $this->alert;
}
/**
* @param $blog
* @return $this
*/
public function setBlog($blog)
{
$this->blog = $blog;
return $this;
}
/**
* @return bool
*/
public function isBlog()
{
return $this->blog;
}
/**
* @param $calendar
* @return $this
*/
public function setCalendar($calendar)
{
$this->calendar = $calendar;
return $this;
}
/**
* @return bool
*/
public function isCalendar()
{
return $this->calendar;
}
/**
* @param $feed
* @return $this
*/
public function setFeed($feed)
{
$this->feed = $feed;
return $this;
}
/**
* @return bool
*/
public function isFeed()
{
return $this->feed;
}
/**
* @param $gallery
* @return $this
*/
public function setGallery($gallery)
{
$this->gallery = $gallery;
return $this;
}
/**
* @return bool
*/
public function isGallery()
{
return $this->gallery;
}
/**
* @param $news
* @return $this
*/
public function setNews($news)
{
$this->news = $news;
return $this;
}
/**
* @return bool
*/
public function isNews()
{
return $this->news;
}
/**
* @param $page
* @return $this
*/
public function setPage($page)
{
$this->page = $page;
return $this;
}
/**
* @return bool
*/
public function isPage()
{
return $this->page;
}
/**
* @param $people
* @return $this
*/
public function setPeople($people)
{
$this->people = $people;
return $this;
}
/**
* @return bool
*/
public function isPeople()
{
return $this->people;
}
/**
* @param $question
* @return $this
*/
public function setQuestion($question)
{
$this->question = $question;
return $this;
}
/**
* @return bool
*/
public function isQuestion()
{
return $this->question;
}
/**
* @param $snippet
* @return $this
*/
public function setSnippet($snippet)
{
$this->snippet = $snippet;
return $this;
}
/**
* @return bool
*/
public function isSnippet()
{
return $this->snippet;
}
/**
* @param $video
* @return $this
*/
public function setVideo($video)
{
return $this;
}
/**
* @return bool
*/
public function isVideo()
{
return $this->department && $this->department->isSchoolNow() && $this->isGallery();
}
}