getID()) { // this is the root node return false; } //If this' parents element, is $another_element, then we are finished return ($this->parent->getID() == $another_element->getID()) || $this->parent->isChildOf($another_element); //Otherwise, check recursivley } /****************************************************************************** * * Getters * ******************************************************************************/ /** * @brief Get the parent-ID * * @retval integer * the ID of the parent element * * NULL means, the parent is the root node * * the parent ID of the root node is -1 */ public function getParentID(): int { return $this->parent_id ?? self::ID_ROOT_ELEMENT; //Null means root element } /** * Get the parent of this element. * * @return StructuralDBElement|null The parent element. Null if this element, does not have a parent. */ public function getParent(): ?self { return $this->parent; } /** * Get the comment of the element. * * @param bool $parse_bbcode Should BBCode converted to HTML, before returning * * @return string the comment */ public function getComment(bool $parse_bbcode = true): string { $val = htmlspecialchars($this->comment ?? ''); return $val; } /** * Get the level. * * The level of the root node is -1. * * @return int the level of this element (zero means a most top element * [a subelement of the root node]) */ public function getLevel(): int { if (0 === $this->level) { $element = $this->parent; $parent_id = $element->getParentID(); while ($parent_id > 0) { /** @var StructuralDBElement $element */ $element = $element->parent; $parent_id = $element->getParentID(); ++$this->level; } } return $this->level; } /** * Get the full path. * * @param string $delimeter the delimeter of the returned string * * @return string the full path (incl. the name of this element), delimeted by $delimeter * * @throws Exception if there was an error */ public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW): string { if (!\is_array($this->full_path_strings)) { $this->full_path_strings = array(); $this->full_path_strings[] = $this->getName(); $element = $this; while (null != $element->parent) { $element = $element->parent; $this->full_path_strings[] = $element->getName(); } $this->full_path_strings = array_reverse($this->full_path_strings); } return implode($delimeter, $this->full_path_strings); } /** * Get all subelements of this element. * * @param bool $recursive if true, the search is recursive * * @return static[] all subelements as an array of objects (sorted by their full path) */ public function getSubelements(bool $recursive): PersistentCollection { if (null == $this->children) { $this->children = new ArrayCollection(); } if (!$recursive) { return $this->children; } else { $all_elements = array(); foreach ($this->children as $subelement) { $all_elements[] = $subelement; $all_elements = array_merge($all_elements, $subelement->getSubelements(true)); } return $all_elements; } } /****************************************************************************** * * Setters * ******************************************************************************/ /** * Change the parent ID of this element. * * @param int|null $new_parent_id * the ID of the new parent element * * NULL if the parent should be the root node */ public function setParentID($new_parent_id): self { $this->parent_id = $new_parent_id; return $this; } /** * Set the comment. * * @param string $new_comment the new comment * * @throws Exception if there was an error */ public function setComment(string $new_comment): self { $this->comment = $new_comment; return $this; } /******************************************************************************** * * Tree / Table Builders * *********************************************************************************/ /** * Build a HTML tree with all subcategories of this element. * * This method prints a