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 loadPage() {
54 return $this->loadStandardPage($this->newResultObject());
57 protected function willFilterPage(array $posts) {
58 // We require blogs to do visibility checks, so load them unconditionally.
59 $blog_phids = mpull($posts, 'getBlogPHID');
61 $blogs = id(new PhameBlogQuery())
62 ->setViewer($this->getViewer())
63 ->needProfileImage(true)
64 ->withPHIDs($blog_phids)
67 $blogs = mpull($blogs, null, 'getPHID');
68 foreach ($posts as $key => $post) {
69 $blog_phid = $post->getBlogPHID();
71 $blog = idx($blogs, $blog_phid);
73 $this->didRejectResult($post);
78 $post->attachBlog($blog);
81 if ($this->needHeaderImage
) {
82 $file_phids = mpull($posts, 'getHeaderImagePHID');
83 $file_phids = array_filter($file_phids);
85 $files = id(new PhabricatorFileQuery())
86 ->setParentQuery($this)
87 ->setViewer($this->getViewer())
88 ->withPHIDs($file_phids)
90 $files = mpull($files, null, 'getPHID');
95 foreach ($posts as $post) {
96 $file = idx($files, $post->getHeaderImagePHID());
98 $post->attachHeaderImageFile($file);
106 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
107 $where = parent
::buildWhereClauseParts($conn);
109 if ($this->ids
!== null) {
116 if ($this->phids
!== null) {
123 if ($this->bloggerPHIDs
!== null) {
126 'p.bloggerPHID IN (%Ls)',
127 $this->bloggerPHIDs
);
130 if ($this->visibility
!== null) {
133 'p.visibility IN (%Ld)',
137 if ($this->publishedAfter
!== null) {
140 'p.datePublished > %d',
141 $this->publishedAfter
);
144 if ($this->blogPHIDs
!== null) {
147 'p.blogPHID in (%Ls)',
154 public function getBuiltinOrders() {
156 'datePublished' => array(
157 'vector' => array('datePublished', 'id'),
158 'name' => pht('Publish Date'),
160 ) + parent
::getBuiltinOrders();
163 public function getOrderableColumns() {
164 return parent
::getOrderableColumns() +
array(
165 'datePublished' => array(
166 'table' => $this->getPrimaryTableAlias(),
167 'column' => 'datePublished',
174 protected function newPagingMapFromPartialObject($object) {
176 'id' => (int)$object->getID(),
177 'datePublished' => (int)$object->getDatePublished(),
181 public function getQueryApplicationClass() {
182 // TODO: Does setting this break public blogs?
186 protected function getPrimaryTableAlias() {