public function get_months_for_year($year, $sectionID = false) { $Cache = PerchBlog_Cache::fetch(); $cache_key = 'months_for_year_' . $year; if ($sectionID) { $cache_key .= '_' . $sectionID; } if ($Cache->exists($cache_key)) { return $Cache->get($cache_key); } $sql = 'SELECT DISTINCT year(postDateTime) AS year, month(postDateTime) AS month, CONCAT(year(postDateTime),"-",month(postDateTime),"-01") AS postDateTime, COUNT(*) AS month_qty FROM ' . $this->table . ' p WHERE year(postDateTime) = ' . $this->db->pdb($year) . ' AND p.postStatus=\'Published\' AND p.postDateTime<=' . $this->db->pdb(date('Y-m-d H:i:00')); if ($sectionID) { $sql .= ' AND p.sectionID=' . $this->db->pdb($sectionID); } $sql .= ' GROUP BY year, month ORDER BY month DESC'; $rows = $this->db->get_rows($sql); $Cache->set($cache_key, $rows); return $rows; }
private function _load_blog() { $Cache = PerchBlog_Cache::fetch(); $cached_blogs = $Cache->get('blogs'); if (!$cached_blogs) { $Blogs = new PerchBlog_Blogs(); $blogs = $Blogs->all(); if (PerchUtil::count($blogs)) { $cached_blogs = array(); foreach ($blogs as $Blog) { $cached_blogs[$Blog->id()] = $Blog; } $Cache->set('blogs', $cached_blogs); } } if ($cached_blogs) { if (isset($cached_blogs[$this->blogID()])) { $this->Blog = $cached_blogs[$this->blogID()]; return true; } } return false; }
private function _load_section() { $Cache = PerchBlog_Cache::fetch(); $cached_sections = $Cache->get('sections'); if (!$cached_sections) { $Sections = new PerchBlog_Sections(); $sections = $Sections->all(); if (PerchUtil::count($sections)) { $cached_sections = array(); foreach ($sections as $Section) { $cached_sections[$Section->id()] = $Section; } $Cache->set('sections', $cached_sections); } } if ($cached_sections) { if (isset($cached_sections[$this->sectionID()])) { $this->Section = $cached_sections[$this->sectionID()]; return true; } } return false; }