3 final class PhamePostQuery
extends PhabricatorCursorPagedPolicyAwareQuery
{
9 private $publishedAfter;
12 private $needHeaderImage;
14 public function withIDs(array $ids) {
19 public function withPHIDs(array $phids) {
20 $this->phids
= $phids;
24 public function withBloggerPHIDs(array $blogger_phids) {
25 $this->bloggerPHIDs
= $blogger_phids;
29 public function withBlogPHIDs(array $blog_phids) {
30 $this->blogPHIDs
= $blog_phids;
34 public function withVisibility(array $visibility) {
35 $this->visibility
= $visibility;
39 public function withPublishedAfter($time) {
40 $this->publishedAfter
= $time;
44 public function needHeaderImage($need) {
45 $this->needHeaderImage
= $need;
49 public function newResultObject() {
50 return new PhamePost();
53 protected function willFilterPage(array $posts) {
54 // We require blogs to do visibility checks, so load them unconditionally.
55 $blog_phids = mpull($posts, 'getBlogPHID');
57 $blogs = id(new PhameBlogQuery())
58 ->setViewer($this->getViewer())
59 ->needProfileImage(true)
60 ->withPHIDs($blog_phids)
63 $blogs = mpull($blogs, null, 'getPHID');
64 foreach ($posts as $key => $post) {
65 $blog_phid = $post->getBlogPHID();
67 $blog = idx($blogs, $blog_phid);
69 $this->didRejectResult($post);
74 $post->attachBlog($blog);
77 if ($this->needHeaderImage
) {
78 $file_phids = mpull($posts, 'getHeaderImagePHID');
79 $file_phids = array_filter($file_phids);
81 $files = id(new PhabricatorFileQuery())
82 ->setParentQuery($this)
83 ->setViewer($this->getViewer())
84 ->withPHIDs($file_phids)
86 $files = mpull($files, null, 'getPHID');
91 foreach ($posts as $post) {
92 $file = idx($files, $post->getHeaderImagePHID());
94 $post->attachHeaderImageFile($file);
102 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
103 $where = parent
::buildWhereClauseParts($conn);
105 if ($this->ids
!== null) {
112 if ($this->phids
!== null) {
119 if ($this->bloggerPHIDs
!== null) {
122 'p.bloggerPHID IN (%Ls)',
123 $this->bloggerPHIDs
);
126 if ($this->visibility
!== null) {
129 'p.visibility IN (%Ld)',
133 if ($this->publishedAfter
!== null) {
136 'p.datePublished > %d',
137 $this->publishedAfter
);
140 if ($this->blogPHIDs
!== null) {
143 'p.blogPHID in (%Ls)',
150 public function getBuiltinOrders() {
152 'datePublished' => array(
153 'vector' => array('datePublished', 'id'),
154 'name' => pht('Publish Date'),
156 ) + parent
::getBuiltinOrders();
159 public function getOrderableColumns() {
160 return parent
::getOrderableColumns() +
array(
161 'datePublished' => array(
162 'table' => $this->getPrimaryTableAlias(),
163 'column' => 'datePublished',
170 protected function newPagingMapFromPartialObject($object) {
172 'id' => (int)$object->getID(),
173 'datePublished' => (int)$object->getDatePublished(),
177 public function getQueryApplicationClass() {
178 // TODO: Does setting this break public blogs?
182 protected function getPrimaryTableAlias() {