Airship\Cabin\Hull\Blueprint\Blog::getBlogMenu PHP Method

getBlogMenu() public method

Gets the data necessary for the side menu on blog pages
public getBlogMenu ( ) : array
return array
    public function getBlogMenu() : array
    {
        $years = [];
        $getYears = $this->db->run("SELECT DISTINCT\n                date_part('year', published) AS blogyear,\n                date_part('month', published) AS blogmonth\n            FROM\n                hull_blog_posts\n            WHERE\n                status\n                AND published <= current_timestamp\n            GROUP BY\n                date_part('year', published),\n                date_part('month', published)\n            ORDER BY\n                blogyear DESC,\n                blogmonth ASC\n            ");
        if (!empty($getYears)) {
            foreach ($getYears as $yr) {
                $dt = new \DateTime($yr['blogyear'] . '-' . $yr['blogmonth'] . '-01');
                $y = intval($yr['blogyear']);
                if ($yr['blogmonth'] < 10) {
                    // Left-pad with a single zero
                    $yr['blogmonth'] = '0' . $yr['blogmonth'];
                }
                $years[$y][$yr['blogmonth']] = $dt->format('F');
            }
        }
        return ['years' => $years, 'categories' => $this->getCategoryTree(), 'uncategorized' => $this->countByCategories([]), 'tags' => $this->getTagCloud()];
    }

Usage Example

Example #1
0
 /**
  * This function is called after the dependencies have been injected by
  * AutoPilot. Think of it as a user-land constructor.
  */
 public function airshipLand()
 {
     $this->blog = $this->blueprint('Blog');
     $this->airship_lens_object->store('blogmenu', $this->blog->getBlogMenu());
 }