You are here

class TreeNode in Ubercart 8.4

Data structure to mimic Drupal's menu system.

Hierarchy

Expanded class hierarchy of TreeNode

2 files declare their use of TreeNode
CatalogBlock.php in uc_catalog/src/Plugin/Block/CatalogBlock.php
uc_catalog.module in uc_catalog/uc_catalog.module
Ubercart Catalog module.

File

uc_catalog/src/TreeNode.php, line 8

Namespace

Drupal\uc_catalog
View source
class TreeNode {
  protected $tid = 0;
  protected $name = 'Catalog';
  protected $children = [];
  protected $depth = -1;
  protected $sequence = 0;

  /**
   * Constructor.
   */
  public function __construct($term = NULL) {
    if ($term) {
      $this->tid = $term->tid;
      $this->name = $term->name;
      $this->depth = $term->depth;
      $this->sequence = $term->sequence;
    }
  }

  /**
   * Determines if new child is an immediate descendant or not.
   *
   * This function is completely dependent on the structure of the array
   * returned by taxonomy_get_tree(). Each element in the array knows its
   * depth in the tree and the array is a preorder iteration of the logical
   * tree structure. Therefore, if the parameter is more than one level
   * deeper than $this, it should be passed to the last child of $this.
   */
  public function addChild(&$child) {
    if ($child
      ->getDepth() - $this
      ->getDepth() == 1) {
      $this->children[] = $child;
    }
    else {
      $last_child =& $this->children[count($this->children) - 1];
      $last_child
        ->addChild($child);
    }
  }

  /**
   * Gets the tid of the term.
   *
   * @return string
   *   The tid of the term.
   */
  public function getTid() {
    return $this->tid;
  }

  /**
   * Sets the tid of the term.
   *
   * @param string $tid
   *   The node's tid.
   *
   * @return $this
   */
  public function setTid(string $tid) {
    $this->tid = $tid;
    return $this;
  }

  /**
   * Gets the name of the term.
   *
   * @return string
   *   The name of the term.
   */
  public function getName() {
    return $this->name;
  }

  /**
   * Sets the name of the term.
   *
   * @param string $name
   *   The node's name.
   *
   * @return $this
   */
  public function setName(string $name) {
    $this->name = $name;
    return $this;
  }

  /**
   * Gets the children of the term.
   *
   * @return array
   *   The children of the term.
   */
  public function getChildren() {
    return $this->children;
  }

  /**
   * Sets the children of the term.
   *
   * @param array $children
   *   The node's children.
   *
   * @return $this
   */
  public function setChildren(array $children) {
    $this->children = $children;
    return $this;
  }

  /**
   * Gets the depth of the term.
   *
   * @return string
   *   The name of the term.
   */
  public function getDepth() {
    return $this->depth;
  }

  /**
   * Sets the depth of the term.
   *
   * @param string $depth
   *   The node's name.
   *
   * @return $this
   */
  public function setDepth(string $depth) {
    $this->depth = $depth;
    return $this;
  }

  /**
   * Gets the sequence of the term.
   *
   * @return int
   *   The sequence of the term.
   */
  public function getSequence() {
    return $this->sequence;
  }

  /**
   * Sets the sequence of the term.
   *
   * @param int $sequence
   *   The term's sequence.
   *
   * @return $this
   */
  public function setSequence($sequence) {
    $this->sequence = $sequence;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TreeNode::$children protected property
TreeNode::$depth protected property
TreeNode::$name protected property
TreeNode::$sequence protected property
TreeNode::$tid protected property
TreeNode::addChild public function Determines if new child is an immediate descendant or not.
TreeNode::getChildren public function Gets the children of the term.
TreeNode::getDepth public function Gets the depth of the term.
TreeNode::getName public function Gets the name of the term.
TreeNode::getSequence public function Gets the sequence of the term.
TreeNode::getTid public function Gets the tid of the term.
TreeNode::setChildren public function Sets the children of the term.
TreeNode::setDepth public function Sets the depth of the term.
TreeNode::setName public function Sets the name of the term.
TreeNode::setSequence public function Sets the sequence of the term.
TreeNode::setTid public function Sets the tid of the term.
TreeNode::__construct public function Constructor.