Пример #1
0
 public function getPosts()
 {
     $posts = false;
     if ($this->memcache !== null) {
         $key = $this->getPostsCacheKey();
         $ids = $this->memcache->getNs('posts', $key);
         if ($ids !== false) {
             $post_wrapper = SwatDBClassMap::get('BlorgPostWrapper');
             $posts = new $post_wrapper();
             if (count($ids) > 0) {
                 $cached_posts = $this->memcache->getNs('posts', $ids);
                 if (count($cached_posts) !== count($ids)) {
                     // one or more posts are missing from the cache
                     $posts = false;
                 } else {
                     foreach ($cached_posts as $post) {
                         $posts->add($post);
                     }
                 }
             }
             if ($posts !== false) {
                 $posts->setDatabase($this->db);
             }
         }
     }
     if ($posts === false) {
         $sql = $this->getSelectClause();
         $sql .= $this->getWhereClause();
         $sql .= $this->getOrderByClause();
         if ($this->range !== null) {
             $this->db->setLimit($this->range->getLimit(), $this->range->getOffset());
         }
         $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);
         }
         if ($this->memcache !== null) {
             $ids = array();
             foreach ($posts as $id => $post) {
                 $post_key = $key . '_' . $id;
                 $ids[] = $post_key;
                 $this->memcache->setNs('posts', $post_key, $post);
             }
             $this->memcache->setNs('posts', $key, $ids);
         }
     }
     return $posts;
 }
Пример #2
0
    /**
     * Gets a recordset of tag dataobjects.
     *
     * @param SwatDBRange $range optional. Range of tags to retrieve. If not
     *                           specified, all tags are loaded.
     * @param string $order_by_clause optional. SQL order by clause of the tag
     *                                list.
     *
     * @return PinholeTagDataObjectWrapper
     */
    private function getSubTagDataObjects(SwatDBRange $range = null, $order_by_clause = null)
    {
        $args = func_get_args();
        $cache_key = $this->getCacheKey(__FUNCTION__, $args);
        $value = $this->app->getCacheRecordset($cache_key, 'PinholeTagDataObjectWrapper', 'photos');
        if ($value !== false) {
            return $value;
        }
        if ($order_by_clause === null) {
            $order_by_clause = 'PinholeTagDateView.first_modified desc';
        }
        $sql = sprintf('select PinholeTag.*,
				PinholeTagDateView.first_modified,
				PinholeTagDateView.last_modified
			from PinholeTag
			inner join PinholeTagDateView on
				PinholeTagDateView.tag = PinholeTag.id
			where %s
			order by %s', $this->getSubTagWhereClause(), $order_by_clause);
        if ($range !== null) {
            $this->db->setLimit($range->getLimit(), $range->getOffset());
        }
        $tag_data_objects = SwatDB::query($this->db, $sql, 'PinholeTagDataObjectWrapper');
        $this->app->addCacheRecordset($tag_data_objects, $cache_key, 'photos');
        return $tag_data_objects;
    }
Пример #3
0
 /**
  * Gets the photos this tag applies to
  *
  * @param SwatDBRange $range optional. The database range of photos to
  *                            select.
  *
  * @return PinholePhotoWrapper the set of {@link PinholePhoto} objects that
  *                              this tag applies to.
  *
  * @see PinholeAbstractTag::getPhotoCount()
  */
 public function getPhotos(SwatDBRange $range = null)
 {
     if (!$this->photos_loaded) {
         $sql = 'select * from PinholePhoto';
         $join_clauses = implode(' ', $this->getJoinClauses());
         if ($join_clauses != '') {
             $sql .= ' ' . $join_clauses . ' ';
         }
         $where_clause = $this->getWhereClause();
         if ($where_clause != '') {
             $sql .= ' where ' . $where_clause;
         }
         if ($range !== null) {
             $this->db->setRange($range->getLimit(), $range->getOffset());
         }
         $wrapper = SwatDBClassMap::get('PinholePhotoWrapper');
         $this->photos = SwatDB::query($this->db, $sql, $wrapper);
         $this->photos_loaded = true;
     }
     return $this->photos;
 }