id; } public function setIsWrapped($isWrapped) { $this->isWrapped = $isWrapped; return $this; } public function getIsWrapped() { return $this->isWrapped; } public function setUnwrapped_content($unwrapped_content) { $this->unwrapped_content = $unwrapped_content; return $this; } public function getUnwrapped_content() { return $this->unwrapped_content; } /** * Set position. * * @param int $position * * @return Block */ public function setPosition($position) { $this->position = $position; return $this; } /** * Get position. * * @return int */ public function getPosition() { return $this->position; } /** * Set identifier. * * @param string $identifier * * @return Block */ public function setIdentifier($identifier) { $this->identifier = $identifier; return $this; } /** * Get identifier. * * @return string */ public function getIdentifier() { return $this->identifier; } /** * Set name. * * @param string $name * * @return Block */ public function setName($name) { $this->name = $name; return $this; } /** * Get name. * * @return string */ public function getName() { return $this->name; } /** * Set content. * * @param string $content * * @return Block */ public function setContent($content) { $this->content = $content; return $this; } /** * Get content. * * @return string */ public function getContent() { return $this->content; } /** * Set content. * * @param string $json_content * * @return Block */ public function setJsonContent($json_content) { $this->json_content = $json_content; return $this; } /** * Get content. * * @return string */ public function getJsonContent() { return $this->json_content; } /** * Set parent. * * @return Block */ public function setParent(?Block $parent = null) { $this->parent = $parent; return $this; } /** * Get parent. * * @return Block */ public function getParent() { return $this->parent; } /** * @return Collection */ public function getChildren() { return $this->children; } public function addChild(Block $child) { $this->children[] = $child; $child->setParent($this); } /** * Constructor. */ public function __construct() { $this->blocks = new \Doctrine\Common\Collections\ArrayCollection(); $this->children = new \Doctrine\Common\Collections\ArrayCollection(); $this->photos = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Add photo. * * @return Block */ public function addPhoto(Block $photo) { $this->photos[] = $photo; return $this; } /** * Remove photo. */ public function removePhoto(Block $photo) { $this->photos->removeElement($photo); } /** * Get photos. * * @return Photo[]|Collection */ public function getPhotos(): Collection { return $this->photos; } /** * Set root. * * @return Block */ public function setRoot(?Block $root = null) { $this->root = $root; return $this; } /** * Get root. * * @return Block */ public function getRoot() { return $this->root; } /** * Get blocks. * * @return Collection */ public function getBlocks() { return $this->blocks; } /** Get blocks hierarchy * returns only root blocks with cached children. * * @return Collection */ public function getBlocksHierarchy() { if (!$this->blocksHierarchy) { $this->blocksHierarchy = $this::buildBlocksHierarchy($this->getBlocks()); } return $this->blocksHierarchy; } public static function buildBlocksHierarchy(Collection $blocks): BlockCollection { /** @var Block[] $block_ids */ $block_ids = []; $blocksHierarchy = new BlockCollection(); /** @var Block $block */ foreach ($blocks as $index => $block) { if ($block->children instanceof PersistentCollection) { $block->children->setInitialized(true); } $block_ids[$block->getId()] = $block; if ($block->getParent() !== $block->getRoot()) { $block_ids[$block->getParent()->getId()]->addChild($block); } else { $blocksHierarchy[] = $block; } } return $blocksHierarchy; } /** * Add block. * * @return Block */ public function addBlock(Block $block) { $this->blocks[] = $block; return $this; } /** * Remove block. */ public function removeBlock(Block $block) { $this->blocks->removeElement($block); } /** * Remove child. */ public function removeChild(Block $child) { $this->children->removeElement($child); } public function setId(int $id): void { $this->id = $id; } }