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'); }