Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phame / query / PhameBlogQuery.php
blobb4018c78eb8ee0fb0764c7ebfd0a6aa9c86f7910
1 <?php
3 final class PhameBlogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
5 private $ids;
6 private $phids;
7 private $domain;
8 private $statuses;
10 private $needBloggers;
11 private $needProfileImage;
12 private $needHeaderImage;
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
19 public function withPHIDs(array $phids) {
20 $this->phids = $phids;
21 return $this;
24 public function withDomain($domain) {
25 $this->domain = $domain;
26 return $this;
29 public function withStatuses(array $status) {
30 $this->statuses = $status;
31 return $this;
34 public function needProfileImage($need) {
35 $this->needProfileImage = $need;
36 return $this;
39 public function needHeaderImage($need) {
40 $this->needHeaderImage = $need;
41 return $this;
44 public function newResultObject() {
45 return new PhameBlog();
48 protected function loadPage() {
49 return $this->loadStandardPage($this->newResultObject());
52 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
53 $where = parent::buildWhereClauseParts($conn);
55 if ($this->statuses !== null) {
56 $where[] = qsprintf(
57 $conn,
58 'b.status IN (%Ls)',
59 $this->statuses);
62 if ($this->ids !== null) {
63 $where[] = qsprintf(
64 $conn,
65 'b.id IN (%Ls)',
66 $this->ids);
69 if ($this->phids !== null) {
70 $where[] = qsprintf(
71 $conn,
72 'b.phid IN (%Ls)',
73 $this->phids);
76 if ($this->domain !== null) {
77 $where[] = qsprintf(
78 $conn,
79 'b.domain = %s',
80 $this->domain);
83 return $where;
86 protected function didFilterPage(array $blogs) {
87 if ($this->needProfileImage) {
88 $default = null;
90 $file_phids = mpull($blogs, 'getProfileImagePHID');
91 $file_phids = array_filter($file_phids);
92 if ($file_phids) {
93 $files = id(new PhabricatorFileQuery())
94 ->setParentQuery($this)
95 ->setViewer($this->getViewer())
96 ->withPHIDs($file_phids)
97 ->execute();
98 $files = mpull($files, null, 'getPHID');
99 } else {
100 $files = array();
103 foreach ($blogs as $blog) {
104 $file = idx($files, $blog->getProfileImagePHID());
105 if (!$file) {
106 if (!$default) {
107 $default = PhabricatorFile::loadBuiltin(
108 $this->getViewer(),
109 'blog.png');
111 $file = $default;
113 $blog->attachProfileImageFile($file);
117 if ($this->needHeaderImage) {
118 $file_phids = mpull($blogs, 'getHeaderImagePHID');
119 $file_phids = array_filter($file_phids);
120 if ($file_phids) {
121 $files = id(new PhabricatorFileQuery())
122 ->setParentQuery($this)
123 ->setViewer($this->getViewer())
124 ->withPHIDs($file_phids)
125 ->execute();
126 $files = mpull($files, null, 'getPHID');
127 } else {
128 $files = array();
131 foreach ($blogs as $blog) {
132 $file = idx($files, $blog->getHeaderImagePHID());
133 if ($file) {
134 $blog->attachHeaderImageFile($file);
138 return $blogs;
141 public function getQueryApplicationClass() {
142 // TODO: Can we set this without breaking public blogs?
143 return null;
146 protected function getPrimaryTableAlias() {
147 return 'b';