public function getSubtree($post_id, $parent_id = null)
 {
     $post_id = (int) $post_id;
     $parent_id = (int) $parent_id;
     $q = new waDbQuery($this);
     if ($post_id) {
         $q->where("post_id = {$post_id}");
     }
     if ($parent_id) {
         $parent = $this->getById($parent_id);
         if (!$parent) {
             $q->where('id = ' . $parent_id);
         } else {
             $where = "`{$this->left}`  >= {$parent[$this->left]} AND\n                    `{$this->right}` <= {$parent[$this->right]}";
             $q->where($where);
         }
     }
     return $q->fetchAll('id');
 }
 /**
  *
  * Query for getting descendants
  *
  * @param int|null $parent_id
  * @param boolean $include_parent
  * @return waDbQuery
  */
 public function descendants($parent_id, $include_parent = false)
 {
     $query = new waDbQuery($this);
     if ($parent_id) {
         $parent_id = (int) $parent_id;
         $parent = $this->getById($parent_id);
         if (!$parent) {
             return $query->where('id = ' . $parent_id);
         }
     } else {
         $parent = null;
     }
     $op = !$include_parent ? array('>', '<') : array('>=', '<=');
     if ($parent) {
         $where = "\n                `{$this->left}`  {$op[0]} {$parent[$this->left]} AND\n                `{$this->right}` {$op[1]} {$parent[$this->right]}\n            ";
         if ($this->root) {
             $where .= " AND `{$this->root}` = {$parent[$this->root]}";
         }
         $query->where($where);
     }
     return $query;
 }
Beispiel #3
0
 /**
  * Set order and returns waDbQuery
  *
  * @param string $order
  * @return waDbQuery
  */
 public function order($order)
 {
     $query = new waDbQuery($this);
     return $query->order($order);
 }
Beispiel #4
0
 /**
  *
  * Query for getting descendants
  *
  * @param mixed $parent
  *     int parent ID
  *     array parent info
  *     false|null query for all tree
  * @param boolean $include_parent
  * @return waDbQuery
  */
 public function descendants($parent, $include_parent = false)
 {
     $query = new waDbQuery($this);
     if (is_numeric($parent) && $parent) {
         $parent_id = (int) $parent;
         $parent = $this->getById($parent);
         if (!$parent) {
             return $query->where('id = ' . $parent_id);
         }
     }
     $op = !$include_parent ? array('>', '<') : array('>=', '<=');
     if ($parent) {
         $where = "\n                `{$this->left}`  {$op[0]} {$parent[$this->left]} AND\n                `{$this->right}` {$op[1]} {$parent[$this->right]}\n            ";
         $query->where($where);
     }
     return $query;
 }