/** @ORM\PostLoad */ public function postLoadHandler(PageEntity $page, LifecycleEventArgs $event) { $em = $event->getEntityManager(); $page->setExtendedPageCallback(function () use($em, $page) { return $em->getRepository($page->getClass())->findOneBy(array('page' => $page->id)); }); }
/** * @return DirEntity */ public function getDir() { if (!$this->dir) { $this->dir = new DirEntity(); $this->dir->setParent($this->page->getDir()); $this->dir->setInvisible(TRUE); $this->dir->setName(Strings::webalize(get_class($this)) . Strings::random()); } return $this->dir; }
/** * @param PageEntity $parent * @param null $setPrevious * @param PageEntity $previous * @return $this * @throws \Nette\InvalidArgumentException */ public function setParent(PageEntity $parent = NULL, $setPrevious = NULL, PageEntity $previous = NULL) { if ($parent == $this->getParent() && !$setPrevious) { return $this; } if (!$parent && !$this->getNext() && !$this->getPrevious() && !$this->getParent() && !$setPrevious) { return $this; } if ($setPrevious && $previous === $this) { throw new InvalidArgumentException("Previous page is the same as current page."); } $oldParent = $this->getParent(); $oldPrevious = $this->getPrevious(); $oldNext = $this->getNext(); $this->removeFromPosition(); if ($parent) { $this->parent = $parent; if ($setPrevious) { if ($previous) { $this->setNext($previous->next); $this->setPrevious($previous); } else { $this->setNext($parent->getChildren()->first() ?: NULL); } } else { $this->setPrevious($parent->getChildren()->last() ?: NULL); } $parent->children[] = $this; } else { if ($setPrevious) { if ($previous) { $this->setNext($previous->next); $this->setPrevious($previous); } else { $this->setNext($this->getRoot($oldNext ?: ($oldParent ?: $oldPrevious))); } } else { $this->parent = NULL; $this->previous = NULL; $this->next = NULL; } } $this->getMainRoute()->parent = $this->getParent() && $this->getParent()->getMainRoute() ? $this->getParent()->getMainRoute() : NULL; $this->generatePosition(); $this->generateUrl(); return $this; }
/** * @param User $user * @param $permission * @return bool */ public function isAllowedInBackend(User $user, $permission) { return $this->page->isAllowedInBackend($user, $permission); }