Airship\Cabin\Bridge\Blueprint\Blog::getCategoryTree PHP Method

getCategoryTree() public method

Get a full category tree, recursively, from a given parent
public getCategoryTree ( integer $parent = null, string $col = 'children', array $seen = [], integer $depth ) : array
$parent integer
$col string The "children" column name
$seen array
$depth integer How deep are we?
return array
    public function getCategoryTree($parent = null, string $col = 'children', array $seen = [], int $depth = 0) : array
    {
        if ($parent > 0) {
            $ids = $this->db->escapeValueSet($seen, 'int');
            $rows = $this->db->run("SELECT * FROM hull_blog_categories WHERE categoryid NOT IN {$ids} AND parent = ? ORDER BY name ASC", $parent);
        } else {
            $rows = $this->db->run("SELECT * FROM hull_blog_categories WHERE parent IS NULL OR parent = '0' ORDER BY name ASC");
        }
        if (empty($rows)) {
            return [];
        }
        foreach ($rows as $i => $row) {
            $_seen = $seen;
            $rows[$i]['ancestors'] = $seen;
            $_seen[] = $row['categoryid'];
            $rows[$i][$col] = $this->getCategoryTree($row['categoryid'], $col, $_seen, $depth + 1);
        }
        return $rows;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * View a version of a blog post.
  *
  * @param string $postID
  * @param string $uniqueID
  *
  * @route blog/post/history/{id}/view/{string}
  */
 public function postHistoryView(string $postID = '', string $uniqueID = '')
 {
     $postID = (int) $postID;
     $blog = $this->blog->getBlogPostById($postID);
     if (!$blog || !$this->can('read')) {
         \Airship\redirect($this->airship_cabin_prefix . '/blog/post');
     }
     $blog['tags'] = $this->blog->getTagsForPost($postID);
     $version = $this->blog->getBlogPostVersionByUniqueId($uniqueID);
     if ((int) $version['postid'] !== $postID || empty($version)) {
         \Airship\redirect($this->airship_cabin_prefix . '/blog/post/history/' . $postID);
     }
     if ($this->isSuperUser()) {
         $authors = $this->author->getAll();
     } else {
         $authors = $this->author->getForUser($this->getActiveUserId());
     }
     $categories = $this->blog->getCategoryTree();
     $tags = $this->blog->getTags();
     $this->lens('blog/post_history_view', ['active_link' => 'bridge-link-blog-posts', 'authors' => $authors, 'blogpost' => $blog, 'categories' => $categories, 'tags' => $tags, 'title' => \__('Revision for  Blog Post "%s"', 'default', Util::noHTML($blog['title'])), 'prev_uniqueid' => $this->blog->getPrevVersionUniqueId($postID, (int) $version['versionid']), 'next_uniqueid' => $this->blog->getNextVersionUniqueId($postID, (int) $version['versionid']), 'version' => $version]);
 }