src/Entity/Content/Menu.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Content;
  3. use Symfony\Component\Validator\Constraints AS Constraints;
  4. use Symfony\Component\Validator\Constraints AS Assert;
  5. use Doctrine\ORM\Mapping AS ORM;
  6. use Ramsey\Uuid\Uuid;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\Content\MenuRepository")
  9.  * @ORM\Table(name="content_menu")
  10.  */
  11. class Menu
  12. {
  13.     /**
  14.     * @ORM\Id
  15.     * @ORM\GeneratedValue(strategy="AUTO")
  16.     * @ORM\Column(type="integer")
  17.     */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="uuid")
  21.      * @Assert\Uuid
  22.      */
  23.      protected $uuid;
  24.     /**
  25.      * @var \DateTime
  26.      *
  27.      * @ORM\Column(type="datetime", nullable=false)
  28.      */
  29.     private $created;
  30.     /**
  31.      * @var \DateTime
  32.      *
  33.      * @ORM\Column(type="datetime", nullable=false)
  34.      */
  35.     private $modified;
  36.     /**
  37.      * @ORM\Column(type="string", length=60, nullable=false)
  38.      */
  39.     private $identifier;
  40.     /**
  41.      * @ORM\Column(type="string", length=60, nullable=false)
  42.      */
  43.     private $name;
  44.     
  45.     /**
  46.      * @ORM\Column(type="boolean", nullable=true)
  47.      */
  48.     private $isLocked;
  49.     /**
  50.      * @ORM\Column(type="boolean", nullable=true)
  51.      */
  52.     private $disableChildItems;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity="MenuItem", mappedBy="menu", cascade={"all"})
  55.      * @ORM\OrderBy({"displayOrder" = "ASC"})
  56.      **/
  57.     private $menuItems;
  58.     
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity="\App\Entity\Settings\Language")
  61.      **/
  62.     private $language;
  63.     public function __construct()
  64.     {
  65.         // UUID
  66.         if(!$this->getUuid())
  67.         {
  68.             $uuid Uuid::uuid1();
  69.             $this->setUuid($uuid->toString());
  70.         }
  71.         // Set some defaults
  72.         $this->setCreated(new \DateTime());
  73.         $this->setModified(new \DateTime());
  74.         if(!$this->getIsLocked())
  75.             $this->setIsLocked(false);
  76.         if(!$this->getDisableChildItems())
  77.             $this->setDisableChildItems(false);
  78.         $this->menuItems = array();
  79.     }
  80.     
  81.     public function getTopLevelMenuItems()
  82.     {
  83.         $menuItemAray = array();
  84.         $menuItems $this->getMenuItems();
  85.         if(!count($menuItems))
  86.             return $menuItemAray;
  87.         
  88.         // Loop items
  89.         foreach($menuItems AS $someItem)
  90.         {
  91.             if(!$someItem->getParent())
  92.                 $menuItemAray[] = $someItem;
  93.         }
  94.         return $menuItemAray;
  95.     }
  96.     public function __toString()
  97.     {
  98.         return $this->getName();
  99.     }
  100.     public function getId()
  101.     {
  102.         return $this->id;
  103.     }
  104.     public function setUuid($uuid)
  105.     {
  106.         $this->uuid $uuid;
  107.         return $this;
  108.     }
  109.     public function getUuid()
  110.     {
  111.         return $this->uuid;
  112.     }
  113.     public function setCreated(\DateTime $created)
  114.     {
  115.         $this->created $created;
  116.     }
  117.     public function getCreated()
  118.     {
  119.         return $this->created;
  120.     }
  121.     public function setModified(\DateTime $modified)
  122.     {
  123.         $this->modified $modified;
  124.     }
  125.     public function getModified()
  126.     {
  127.         return $this->modified;
  128.     }
  129.     public function getName()
  130.     {
  131.         return $this->name;
  132.     }
  133.     public function setName(string $name)
  134.     {
  135.         $this->name $name;
  136.     }
  137.     public function getIdentifier()
  138.     {
  139.         return $this->identifier;
  140.     }
  141.     public function setIdentifier(string $identifier)
  142.     {
  143.         $this->identifier $identifier;
  144.     }
  145.     public function getIsLocked()
  146.     {
  147.         return $this->isLocked;
  148.     }
  149.     public function setIsLocked($isLocked)
  150.     {
  151.         $this->isLocked $isLocked;
  152.     }
  153.     public function getDisableChildItems()
  154.     {
  155.         return $this->disableChildItems;
  156.     }
  157.     public function setDisableChildItems($disableChildItems)
  158.     {
  159.         $this->disableChildItems $disableChildItems;
  160.     }
  161.     public function addMenuItem(\App\Entity\Content\MenuItem $menuItem)
  162.     {
  163.         if(!in_array($menuItem, (array)$this->menuItems))
  164.             $this->menuItems[] = $menuItem;
  165.         if($menuItem->getMenu() != $this)
  166.             $menuItem->setMenu($this);
  167.         return $this;
  168.     }
  169.     public function removeMenuItem(\App\Entity\Content\MenuItem $menuItem)
  170.     {
  171.         $this->menuItems->removeElement($menuItem);
  172.         $menuItem->setMenu(null);
  173.     }
  174.     public function getMenuItems()
  175.     {
  176.         return $this->menuItems;
  177.     }
  178.     
  179.     public function setLanguage(\App\Entity\Settings\Language $language null)
  180.     {
  181.         $this->language $language;
  182.     }
  183.     public function getLanguage()
  184.     {
  185.         return $this->language;
  186.     }
  187. }