@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhameBlog>
5 */
6final class PhameBlogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
7
8 private $ids;
9 private $phids;
10 private $domain;
11 private $statuses;
12
13 private $needBloggers;
14 private $needProfileImage;
15 private $needHeaderImage;
16
17 public function withIDs(array $ids) {
18 $this->ids = $ids;
19 return $this;
20 }
21
22 public function withPHIDs(array $phids) {
23 $this->phids = $phids;
24 return $this;
25 }
26
27 public function withDomain($domain) {
28 $this->domain = $domain;
29 return $this;
30 }
31
32 public function withStatuses(array $status) {
33 $this->statuses = $status;
34 return $this;
35 }
36
37 public function needProfileImage($need) {
38 $this->needProfileImage = $need;
39 return $this;
40 }
41
42 public function needHeaderImage($need) {
43 $this->needHeaderImage = $need;
44 return $this;
45 }
46
47 public function newResultObject() {
48 return new PhameBlog();
49 }
50
51 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
52 $where = parent::buildWhereClauseParts($conn);
53
54 if ($this->statuses !== null) {
55 $where[] = qsprintf(
56 $conn,
57 'b.status IN (%Ls)',
58 $this->statuses);
59 }
60
61 if ($this->ids !== null) {
62 $where[] = qsprintf(
63 $conn,
64 'b.id IN (%Ls)',
65 $this->ids);
66 }
67
68 if ($this->phids !== null) {
69 $where[] = qsprintf(
70 $conn,
71 'b.phid IN (%Ls)',
72 $this->phids);
73 }
74
75 if ($this->domain !== null) {
76 $where[] = qsprintf(
77 $conn,
78 'b.domain = %s',
79 $this->domain);
80 }
81
82 return $where;
83 }
84
85 protected function didFilterPage(array $blogs) {
86 if ($this->needProfileImage) {
87 $default = null;
88
89 $file_phids = mpull($blogs, 'getProfileImagePHID');
90 $file_phids = array_filter($file_phids);
91 if ($file_phids) {
92 $files = id(new PhabricatorFileQuery())
93 ->setParentQuery($this)
94 ->setViewer($this->getViewer())
95 ->withPHIDs($file_phids)
96 ->execute();
97 $files = mpull($files, null, 'getPHID');
98 } else {
99 $files = array();
100 }
101
102 foreach ($blogs as $blog) {
103 $file = idx($files, $blog->getProfileImagePHID());
104 if (!$file) {
105 if (!$default) {
106 $default = PhabricatorFile::loadBuiltin(
107 $this->getViewer(),
108 'blog.png');
109 }
110 $file = $default;
111 }
112 $blog->attachProfileImageFile($file);
113 }
114 }
115
116 if ($this->needHeaderImage) {
117 $file_phids = mpull($blogs, 'getHeaderImagePHID');
118 $file_phids = array_filter($file_phids);
119 if ($file_phids) {
120 $files = id(new PhabricatorFileQuery())
121 ->setParentQuery($this)
122 ->setViewer($this->getViewer())
123 ->withPHIDs($file_phids)
124 ->execute();
125 $files = mpull($files, null, 'getPHID');
126 } else {
127 $files = array();
128 }
129
130 foreach ($blogs as $blog) {
131 $file = idx($files, $blog->getHeaderImagePHID());
132 if ($file) {
133 $blog->attachHeaderImageFile($file);
134 }
135 }
136 }
137 return $blogs;
138 }
139
140 public function getQueryApplicationClass() {
141 // TODO: Can we set this without breaking public blogs?
142 return null;
143 }
144
145 protected function getPrimaryTableAlias() {
146 return 'b';
147 }
148
149}