src/Package/Openform/Entity/Page.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Package\Openform\Entity;
  3. // use Symfony\Component\HttpFoundation\File\UploadedFile;
  4. use App\Package\Block\EntityParentTrait\BlockParentTrait;
  5. // use App\Package\File\Tools\FileManager\FileManager,
  6. //     App\Package\Toolkit\SimpleFunctions\SimpleFunctions,
  7. //     App\Package\Toolkit\Exception\Exception\Exception;
  8. use Doctrine\ORM\Event\PreFlushEventArgs;
  9. /**
  10.  * Page
  11.  * 
  12.  * This is a standard entity (can be enriched with business logic) which extends an anemic entity.
  13.  * Feel free to build a mind control software here.
  14.  *  
  15.  * @author     Openform Entity Generator
  16.  * @copyright  2019 Openform
  17.  */
  18. class Page extends \App\Package\Openform\EntityAnemic\AnemicPage implements \App\Package\Openform\EntityInterface\PageInterface
  19. {
  20. // zaremowano gdyż funkcja o takiej samej nazwie ale statyczna jest odpalana w searchIndexerze
  21. // a ta wygląda na nieużywaną    
  22. //    public function getRootParent() 
  23. //    {
  24. //        return ucfirst(substr(str_replace('page_','',$this->getIdName()), 0, -1));
  25. //    }
  26.     public function isSelfOrDescendantOf($idName
  27.     {
  28.         $parent $this;
  29.         $result false;
  30.         while ($parent) {
  31.             if ($parent->getIdName() == $idName) {
  32.                 $result true;
  33.                 break;
  34.             }
  35.             if ($parent->getParent()) {
  36.                 $parent $parent->getParent();
  37.             } else {
  38.                 break;
  39.             }
  40.         }
  41.         return $result;
  42.     }
  43.     
  44.     public function isDescendantOf($descendantIdName
  45.     {
  46.         $parent $this->getParent();
  47.         $result false;
  48.         while ($parent) {
  49.             if ($parent->getIdName() == $descendantIdName) {
  50.                 $result true;
  51.                 break;
  52.             }
  53.             if ($parent->getParent()) {
  54.                 $parent $parent->getParent();
  55.             } else {
  56.                 break;
  57.             }
  58.         }
  59.         return $result;
  60.     }
  61.     
  62.     use BlockParentTrait;
  63.     /** needed do bloków sekcji z textem */
  64.     private $blockSection;
  65.     public function getBlockSection() 
  66.     {
  67.         return $this->getSection();
  68.     }
  69.     
  70.     public function __construct()
  71.     {
  72.         $this->statable    true;
  73.         $this->editable    true;
  74.         $this->deletable   true;
  75.         $this->subpageable true;
  76.         $this->mainMenu false;
  77.         $this->footMenu false;
  78.         $this->barMenu false;
  79.         $this->shortMenu false;
  80.         $this->showTop false;
  81.         
  82.         $this->footMenuOrd 0;
  83.         $this->footMenu2Ord 0;
  84.         
  85.         $this->initFileManager();
  86.         parent::__construct();
  87.     }
  88.     /**
  89.      * Need for lang changer
  90.      * @param string $locale
  91.      * @return \App\Package\Openform\Entity\Page
  92.      */
  93.     public function setTranslatableLocale($locale) {
  94.         $this->locale $locale;
  95.         return $this;
  96.     }
  97.     /**
  98.      * {@inheritDoc}
  99.      */
  100.     public function addBlock(PageBlock $block) : parent
  101.     {
  102.         $this->customAddBlock($block);
  103.         return $this;
  104.     }
  105.     /**
  106.      * {@inheritDoc}
  107.      */
  108.     public function removeBlock(PageBlock $block) : bool
  109.     {
  110.         return $this->customRemoveBlock($block);        
  111.     }
  112.     
  113.     /**
  114.      * {@inheritDoc}
  115.      * from BlockParentTrait for sideBlocks
  116.      */
  117.     protected $blocksSideMarkedToRemove = [];
  118.     
  119.     public function addSideBlock(PageSideBlock $block) : parent
  120.     {
  121.         $this->SideBlock[] = $block;
  122.         $block->setParent($this);
  123.         return $this;
  124.     }
  125.     public function removeSideBlock(PageSideBlock $block) : bool
  126.     {
  127.         $status $this->SideBlock->removeElement($block);
  128.         if ($status && ! in_array($block$this->blocksSideMarkedToRemove)) {
  129.             $this->blocksSideMarkedToRemove[] = $block;
  130.         }
  131.         return $status;        
  132.     }
  133.     public function preFlush(PreFlushEventArgs $args) : void
  134.     {
  135.         $em $args->getEntityManager();
  136.         foreach($this->blocksMarkedToRemove as $blockToRemove) {
  137.             $em->remove$blockToRemove );
  138.         }
  139.         
  140.         foreach($this->blocksSideMarkedToRemove as $blockToRemove) {
  141.             $em->remove$blockToRemove );
  142.         }
  143.         return;
  144.     }
  145.     
  146.     // --- SUPPORTIVE METHODS
  147.     // --- EVENT
  148.     // --- DOCTRINE EVENTS
  149.     /**
  150.      * After entity is constructed by EntityManager
  151.      *
  152.      * @return void
  153.      */
  154.     public function postLoad() : void
  155.     {
  156.         $this->initFileManager();
  157.         $this->oldImagePath $this->imagePath;
  158.         return;
  159.     }
  160.     /**
  161.      * After EntityManager remove was called on entity
  162.      *
  163.      * @return void
  164.      */
  165.     public function preRemove() : void
  166.     {
  167.         if ($this->imagePath) {
  168.             $this->fileManager->removeFile$this->imagePath );
  169.         }
  170.         return;
  171.     }
  172.     
  173.     /**
  174.      * Return visible parent
  175.      * @param string $locale
  176.      * @return \App\Package\Openform\EntityInterface\PageInterface|NULL
  177.      */
  178.     public function getVisibleParent(string $locale
  179.     {
  180.         if($this->Parent && $this->Parent->getStat() && $this->Parent->getTranslation()[$locale]->getTitle() )
  181.             return $this->getParent();
  182.         else 
  183.             return null;
  184.     }
  185.    
  186. }