Beispiel #1
0
    public function getPostByDateAndShortname(SwatDate $date, $shortname)
    {
        $post = false;
        if ($this->memcache !== null) {
            $key = $date->formatLikeIntl('yyyyMMdd') . $shortname;
            $key = $this->getPostCacheKey($key);
            $post = $this->memcache->getNs('posts', $key);
        }
        if ($post === false) {
            $sql = $this->getSelectClause();
            $sql .= $this->getWhereClause();
            $sql .= sprintf(' and BlorgPost.shortname = %s and
				date_trunc(\'month\', convertTZ(publish_date, %s)) =
					date_trunc(\'month\', timestamp %s)', $this->db->quote($shortname, 'text'), $this->db->quote($date->getTimezone()->getName(), 'text'), $this->db->quote($date->getDate(), 'date'));
            $this->db->setLimit(1, 0);
            $post_wrapper = SwatDBClassMap::get('BlorgPostWrapper');
            $posts = SwatDB::query($this->db, $sql, $post_wrapper);
            if (in_array('author', $this->fields)) {
                $this->loadPostAuthors($posts);
            }
            if ($this->load_files) {
                $this->loadPostFiles($posts);
            }
            if ($this->load_tags) {
                $this->loadPostTags($posts);
            }
            $post = $posts->getFirst();
            if ($this->memcache !== null) {
                $this->memcache->setNs('posts', $key, $post);
            }
        } else {
            if ($post !== null) {
                $post->setDatabase($this->db);
            }
        }
        return $post;
    }