Example #1
0
 public static function getPostWithComments($postId)
 {
     $params = array('descending' => true, 'startkey' => array($postId, array()), 'endkey' => array($postId), 'include_docs' => true);
     $postAndComments = self::getDb()->view('post', 'with-comments', $params, Sopha_View_Result::RETURN_ARRAY);
     if (count($postAndComments) == 0) {
         return null;
     }
     $post = $postAndComments->current();
     if ($post['@doctype'] != 'Post') {
         throw new ErrorException("Unexpected doctype in view result: " . $post['@doctype']);
     }
     $post = new self($post);
     for ($postAndComments->next(); $postAndComments->valid(); $postAndComments->next()) {
         $post->_loadComment($postAndComments->current());
     }
     return $post;
 }