<?phpnamespace App\Package\Openform\Entity;// use Symfony\Component\HttpFoundation\File\UploadedFile;use App\Package\Block\EntityParentTrait\BlockParentTrait;// use App\Package\File\Tools\FileManager\FileManager,// App\Package\Toolkit\SimpleFunctions\SimpleFunctions,// App\Package\Toolkit\Exception\Exception\Exception;use Doctrine\ORM\Event\PreFlushEventArgs;/** * Page * * This is a standard entity (can be enriched with business logic) which extends an anemic entity. * Feel free to build a mind control software here. * * @author Openform Entity Generator * @copyright 2019 Openform */class Page extends \App\Package\Openform\EntityAnemic\AnemicPage implements \App\Package\Openform\EntityInterface\PageInterface{// zaremowano gdyż funkcja o takiej samej nazwie ale statyczna jest odpalana w searchIndexerze// a ta wygląda na nieużywaną // public function getRootParent() // {// return ucfirst(substr(str_replace('page_','',$this->getIdName()), 0, -1));// } public function isSelfOrDescendantOf($idName) { $parent = $this; $result = false; while ($parent) { if ($parent->getIdName() == $idName) { $result = true; break; } if ($parent->getParent()) { $parent = $parent->getParent(); } else { break; } } return $result; } public function isDescendantOf($descendantIdName) { $parent = $this->getParent(); $result = false; while ($parent) { if ($parent->getIdName() == $descendantIdName) { $result = true; break; } if ($parent->getParent()) { $parent = $parent->getParent(); } else { break; } } return $result; } use BlockParentTrait; /** needed do bloków sekcji z textem */ private $blockSection; public function getBlockSection() { return $this->getSection(); } public function __construct() { $this->statable = true; $this->editable = true; $this->deletable = true; $this->subpageable = true; $this->mainMenu = false; $this->footMenu = false; $this->barMenu = false; $this->shortMenu = false; $this->showTop = false; $this->footMenuOrd = 0; $this->footMenu2Ord = 0; $this->initFileManager(); parent::__construct(); } /** * Need for lang changer * @param string $locale * @return \App\Package\Openform\Entity\Page */ public function setTranslatableLocale($locale) { $this->locale = $locale; return $this; } /** * {@inheritDoc} */ public function addBlock(PageBlock $block) : parent { $this->customAddBlock($block); return $this; } /** * {@inheritDoc} */ public function removeBlock(PageBlock $block) : bool { return $this->customRemoveBlock($block); } /** * {@inheritDoc} * from BlockParentTrait for sideBlocks */ protected $blocksSideMarkedToRemove = []; public function addSideBlock(PageSideBlock $block) : parent { $this->SideBlock[] = $block; $block->setParent($this); return $this; } public function removeSideBlock(PageSideBlock $block) : bool { $status = $this->SideBlock->removeElement($block); if ($status && ! in_array($block, $this->blocksSideMarkedToRemove)) { $this->blocksSideMarkedToRemove[] = $block; } return $status; } public function preFlush(PreFlushEventArgs $args) : void { $em = $args->getEntityManager(); foreach($this->blocksMarkedToRemove as $blockToRemove) { $em->remove( $blockToRemove ); } foreach($this->blocksSideMarkedToRemove as $blockToRemove) { $em->remove( $blockToRemove ); } return; } // --- SUPPORTIVE METHODS // --- EVENT // --- DOCTRINE EVENTS /** * After entity is constructed by EntityManager * * @return void */ public function postLoad() : void { $this->initFileManager(); $this->oldImagePath = $this->imagePath; return; } /** * After EntityManager remove was called on entity * * @return void */ public function preRemove() : void { if ($this->imagePath) { $this->fileManager->removeFile( $this->imagePath ); } return; } /** * Return visible parent * @param string $locale * @return \App\Package\Openform\EntityInterface\PageInterface|NULL */ public function getVisibleParent(string $locale) { if($this->Parent && $this->Parent->getStat() && $this->Parent->getTranslation()[$locale]->getTitle() ) return $this->getParent(); else return null; } }