src/Cms/ContainerBundle/Entity/ModuleFlags.php line 12

Open in your IDE?
  1. <?php
  2. namespace Cms\ContainerBundle\Entity;
  3. use Cms\ModuleBundle\Model\ModuleConfig;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * Class ModuleFlags
  7.  * @package Cms\ContainerBundle\Entity
  8.  * @ORM\Embeddable
  9.  */
  10. class ModuleFlags
  11. {
  12.     /**
  13.      * SCHOOLNOW
  14.      *
  15.      * @var Container|null
  16.      */
  17.     private ?Container $department null;
  18.     /**
  19.      * @var bool
  20.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
  21.      */
  22.     protected $alert false;
  23.     /**
  24.      * @var bool
  25.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
  26.      */
  27.     protected $blog false;
  28.     /**
  29.      * @var bool
  30.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
  31.      */
  32.     protected $calendar false;
  33.     /**
  34.      * @var bool
  35.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
  36.      */
  37.     protected $gallery false;
  38.     /**
  39.      * @var bool
  40.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
  41.      */
  42.     protected $news false;
  43.     /**
  44.      * @var bool
  45.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
  46.      */
  47.     protected $page true;
  48.     /**
  49.      * @var bool
  50.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
  51.      */
  52.     protected $people false;
  53.     /**
  54.      * @var bool
  55.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
  56.      */
  57.     protected $question false;
  58.     /**
  59.      * @var bool
  60.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = true})
  61.      */
  62.     protected $snippet false;
  63.     /**
  64.      * @var bool
  65.      * @ORM\Column(type = "boolean", nullable = false, options={"default" = false})
  66.      */
  67.     protected $feed false;
  68.     /**
  69.      * @internal
  70.      * @param Container|null $department
  71.      * @return $this
  72.      */
  73.     public function associateDepartment(?Container $department): self
  74.     {
  75.         $this->department $department;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return array|bool[]
  80.      */
  81.     public function all()
  82.     {
  83.         return [
  84.             'alert' => $this->isAlert(),
  85.             'blog' => $this->isBlog(),
  86.             'calendar' => $this->isCalendar(),
  87.             'feed' => $this->isFeed(),
  88.             'gallery' => $this->isGallery(),
  89.             'news' => $this->isNews(),
  90.             'page' => $this->isPage(),
  91.             'people' => $this->isPeople(),
  92.             'question' => $this->isQuestion(),
  93.             'snippet' => $this->isSnippet(),
  94.             'video' => $this->isVideo(),
  95.         ];
  96.     }
  97.     /**
  98.      * @return array|string[]
  99.      */
  100.     public function enabled()
  101.     {
  102.         return array_keys(array_filter($this->all()));
  103.     }
  104.     /**
  105.      * @param string|ModuleConfig $module
  106.      * @return bool
  107.      * @throws \Exception
  108.      */
  109.     public function is($module)
  110.     {
  111.         if ($module instanceof ModuleConfig) {
  112.             $module $module->key();
  113.         }
  114.         $callable = array(
  115.             $this,
  116.             sprintf(
  117.                 'is%s',
  118.                 ucfirst($module)
  119.             )
  120.         );
  121.         if ( ! is_callable($callable)) {
  122.             throw new \Exception();
  123.         }
  124.         return (call_user_func($callable) === true);
  125.     }
  126.     /**
  127.      * @param string|ModuleConfig $module
  128.      * @param bool $value
  129.      * @return $this
  130.      * @throws \Exception
  131.      */
  132.     public function set($modulebool $value)
  133.     {
  134.         if ($module instanceof ModuleConfig) {
  135.             $module $module->key();
  136.         }
  137.         $callable = array(
  138.             $this,
  139.             sprintf(
  140.                 'set%s',
  141.                 ucfirst($module)
  142.             )
  143.         );
  144.         if ( ! is_callable($callable)) {
  145.             throw new \Exception();
  146.         }
  147.         return call_user_func($callable$value);
  148.     }
  149.     /**
  150.      * @param $alert
  151.      * @return $this
  152.      */
  153.     public function setAlert($alert)
  154.     {
  155.         $this->alert $alert;
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return bool
  160.      */
  161.     public function isAlert()
  162.     {
  163.         return $this->alert;
  164.     }
  165.     /**
  166.      * @param $blog
  167.      * @return $this
  168.      */
  169.     public function setBlog($blog)
  170.     {
  171.         $this->blog $blog;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return bool
  176.      */
  177.     public function isBlog()
  178.     {
  179.         return $this->blog;
  180.     }
  181.     /**
  182.      * @param $calendar
  183.      * @return $this
  184.      */
  185.     public function setCalendar($calendar)
  186.     {
  187.         $this->calendar $calendar;
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return bool
  192.      */
  193.     public function isCalendar()
  194.     {
  195.         return $this->calendar;
  196.     }
  197.     /**
  198.      * @param $feed
  199.      * @return $this
  200.      */
  201.     public function setFeed($feed)
  202.     {
  203.         $this->feed $feed;
  204.         return $this;
  205.     }
  206.     /**
  207.      * @return bool
  208.      */
  209.     public function isFeed()
  210.     {
  211.         return $this->feed;
  212.     }
  213.     /**
  214.      * @param $gallery
  215.      * @return $this
  216.      */
  217.     public function setGallery($gallery)
  218.     {
  219.         $this->gallery $gallery;
  220.         return $this;
  221.     }
  222.     /**
  223.      * @return bool
  224.      */
  225.     public function isGallery()
  226.     {
  227.         return $this->gallery;
  228.     }
  229.     /**
  230.      * @param $news
  231.      * @return $this
  232.      */
  233.     public function setNews($news)
  234.     {
  235.         $this->news $news;
  236.         return $this;
  237.     }
  238.     /**
  239.      * @return bool
  240.      */
  241.     public function isNews()
  242.     {
  243.         return $this->news;
  244.     }
  245.     /**
  246.      * @param $page
  247.      * @return $this
  248.      */
  249.     public function setPage($page)
  250.     {
  251.         $this->page $page;
  252.         return $this;
  253.     }
  254.     /**
  255.      * @return bool
  256.      */
  257.     public function isPage()
  258.     {
  259.         return $this->page;
  260.     }
  261.     /**
  262.      * @param $people
  263.      * @return $this
  264.      */
  265.     public function setPeople($people)
  266.     {
  267.         $this->people $people;
  268.         return $this;
  269.     }
  270.     /**
  271.      * @return bool
  272.      */
  273.     public function isPeople()
  274.     {
  275.         return $this->people;
  276.     }
  277.     /**
  278.      * @param $question
  279.      * @return $this
  280.      */
  281.     public function setQuestion($question)
  282.     {
  283.         $this->question $question;
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return bool
  288.      */
  289.     public function isQuestion()
  290.     {
  291.         return $this->question;
  292.     }
  293.     /**
  294.      * @param $snippet
  295.      * @return $this
  296.      */
  297.     public function setSnippet($snippet)
  298.     {
  299.         $this->snippet $snippet;
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return bool
  304.      */
  305.     public function isSnippet()
  306.     {
  307.         return $this->snippet;
  308.     }
  309.     /**
  310.      * @param $video
  311.      * @return $this
  312.      */
  313.     public function setVideo($video)
  314.     {
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return bool
  319.      */
  320.     public function isVideo()
  321.     {
  322.         return $this->department && $this->department->isSchoolNow() && $this->isGallery();
  323.     }
  324. }