Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / phame / query / PhameBlogQuery.php
blobb730f3c4aaa5560e0636c474886144c0db10144a
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 buildWhereClauseParts(AphrontDatabaseConnection $conn) {
49 $where = parent::buildWhereClauseParts($conn);
51 if ($this->statuses !== null) {
52 $where[] = qsprintf(
53 $conn,
54 'b.status IN (%Ls)',
55 $this->statuses);
58 if ($this->ids !== null) {
59 $where[] = qsprintf(
60 $conn,
61 'b.id IN (%Ls)',
62 $this->ids);
65 if ($this->phids !== null) {
66 $where[] = qsprintf(
67 $conn,
68 'b.phid IN (%Ls)',
69 $this->phids);
72 if ($this->domain !== null) {
73 $where[] = qsprintf(
74 $conn,
75 'b.domain = %s',
76 $this->domain);
79 return $where;
82 protected function didFilterPage(array $blogs) {
83 if ($this->needProfileImage) {
84 $default = null;
86 $file_phids = mpull($blogs, 'getProfileImagePHID');
87 $file_phids = array_filter($file_phids);
88 if ($file_phids) {
89 $files = id(new PhabricatorFileQuery())
90 ->setParentQuery($this)
91 ->setViewer($this->getViewer())
92 ->withPHIDs($file_phids)
93 ->execute();
94 $files = mpull($files, null, 'getPHID');
95 } else {
96 $files = array();
99 foreach ($blogs as $blog) {
100 $file = idx($files, $blog->getProfileImagePHID());
101 if (!$file) {
102 if (!$default) {
103 $default = PhabricatorFile::loadBuiltin(
104 $this->getViewer(),
105 'blog.png');
107 $file = $default;
109 $blog->attachProfileImageFile($file);
113 if ($this->needHeaderImage) {
114 $file_phids = mpull($blogs, 'getHeaderImagePHID');
115 $file_phids = array_filter($file_phids);
116 if ($file_phids) {
117 $files = id(new PhabricatorFileQuery())
118 ->setParentQuery($this)
119 ->setViewer($this->getViewer())
120 ->withPHIDs($file_phids)
121 ->execute();
122 $files = mpull($files, null, 'getPHID');
123 } else {
124 $files = array();
127 foreach ($blogs as $blog) {
128 $file = idx($files, $blog->getHeaderImagePHID());
129 if ($file) {
130 $blog->attachHeaderImageFile($file);
134 return $blogs;
137 public function getQueryApplicationClass() {
138 // TODO: Can we set this without breaking public blogs?
139 return null;
142 protected function getPrimaryTableAlias() {
143 return 'b';