[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorPeopleQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $usernames; 7 private $realnames; 8 private $emails; 9 private $phids; 10 private $ids; 11 private $dateCreatedAfter; 12 private $dateCreatedBefore; 13 private $isAdmin; 14 private $isSystemAgent; 15 private $isDisabled; 16 private $isApproved; 17 private $nameLike; 18 19 private $needPrimaryEmail; 20 private $needProfile; 21 private $needProfileImage; 22 private $needStatus; 23 24 public function withIDs(array $ids) { 25 $this->ids = $ids; 26 return $this; 27 } 28 29 public function withPHIDs(array $phids) { 30 $this->phids = $phids; 31 return $this; 32 } 33 34 public function withEmails(array $emails) { 35 $this->emails = $emails; 36 return $this; 37 } 38 39 public function withRealnames(array $realnames) { 40 $this->realnames = $realnames; 41 return $this; 42 } 43 44 public function withUsernames(array $usernames) { 45 $this->usernames = $usernames; 46 return $this; 47 } 48 49 public function withDateCreatedBefore($date_created_before) { 50 $this->dateCreatedBefore = $date_created_before; 51 return $this; 52 } 53 54 public function withDateCreatedAfter($date_created_after) { 55 $this->dateCreatedAfter = $date_created_after; 56 return $this; 57 } 58 59 public function withIsAdmin($admin) { 60 $this->isAdmin = $admin; 61 return $this; 62 } 63 64 public function withIsSystemAgent($system_agent) { 65 $this->isSystemAgent = $system_agent; 66 return $this; 67 } 68 69 public function withIsDisabled($disabled) { 70 $this->isDisabled = $disabled; 71 return $this; 72 } 73 74 public function withIsApproved($approved) { 75 $this->isApproved = $approved; 76 return $this; 77 } 78 79 public function withNameLike($like) { 80 $this->nameLike = $like; 81 return $this; 82 } 83 84 public function needPrimaryEmail($need) { 85 $this->needPrimaryEmail = $need; 86 return $this; 87 } 88 89 public function needProfile($need) { 90 $this->needProfile = $need; 91 return $this; 92 } 93 94 public function needProfileImage($need) { 95 $this->needProfileImage = $need; 96 return $this; 97 } 98 99 public function needStatus($need) { 100 $this->needStatus = $need; 101 return $this; 102 } 103 104 public function loadPage() { 105 $table = new PhabricatorUser(); 106 $conn_r = $table->establishConnection('r'); 107 108 $data = queryfx_all( 109 $conn_r, 110 'SELECT * FROM %T user %Q %Q %Q %Q %Q', 111 $table->getTableName(), 112 $this->buildJoinsClause($conn_r), 113 $this->buildWhereClause($conn_r), 114 $this->buildApplicationSearchGroupClause($conn_r), 115 $this->buildOrderClause($conn_r), 116 $this->buildLimitClause($conn_r)); 117 118 if ($this->needPrimaryEmail) { 119 $table->putInSet(new LiskDAOSet()); 120 } 121 122 return $table->loadAllFromArray($data); 123 } 124 125 protected function didFilterPage(array $users) { 126 if ($this->needProfile) { 127 $user_list = mpull($users, null, 'getPHID'); 128 $profiles = new PhabricatorUserProfile(); 129 $profiles = $profiles->loadAllWhere('userPHID IN (%Ls)', 130 array_keys($user_list)); 131 132 $profiles = mpull($profiles, null, 'getUserPHID'); 133 foreach ($user_list as $user_phid => $user) { 134 $profile = idx($profiles, $user_phid); 135 if (!$profile) { 136 $profile = new PhabricatorUserProfile(); 137 $profile->setUserPHID($user_phid); 138 } 139 140 $user->attachUserProfile($profile); 141 } 142 } 143 144 if ($this->needProfileImage) { 145 $user_profile_file_phids = mpull($users, 'getProfileImagePHID'); 146 $user_profile_file_phids = array_filter($user_profile_file_phids); 147 if ($user_profile_file_phids) { 148 $files = id(new PhabricatorFileQuery()) 149 ->setParentQuery($this) 150 ->setViewer($this->getViewer()) 151 ->withPHIDs($user_profile_file_phids) 152 ->execute(); 153 $files = mpull($files, null, 'getPHID'); 154 } else { 155 $files = array(); 156 } 157 foreach ($users as $user) { 158 $image_phid = $user->getProfileImagePHID(); 159 if (isset($files[$image_phid])) { 160 $profile_image_uri = $files[$image_phid]->getBestURI(); 161 } else { 162 $profile_image_uri = PhabricatorUser::getDefaultProfileImageURI(); 163 } 164 $user->attachProfileImageURI($profile_image_uri); 165 } 166 } 167 168 if ($this->needStatus) { 169 $user_list = mpull($users, null, 'getPHID'); 170 $statuses = id(new PhabricatorCalendarEvent())->loadCurrentStatuses( 171 array_keys($user_list)); 172 foreach ($user_list as $phid => $user) { 173 $status = idx($statuses, $phid); 174 if ($status) { 175 $user->attachStatus($status); 176 } 177 } 178 } 179 180 return $users; 181 } 182 183 private function buildJoinsClause($conn_r) { 184 $joins = array(); 185 186 if ($this->emails) { 187 $email_table = new PhabricatorUserEmail(); 188 $joins[] = qsprintf( 189 $conn_r, 190 'JOIN %T email ON email.userPHID = user.PHID', 191 $email_table->getTableName()); 192 } 193 194 $joins[] = $this->buildApplicationSearchJoinClause($conn_r); 195 196 $joins = implode(' ', $joins); 197 return $joins; 198 } 199 200 private function buildWhereClause($conn_r) { 201 $where = array(); 202 203 if ($this->usernames !== null) { 204 $where[] = qsprintf( 205 $conn_r, 206 'user.userName IN (%Ls)', 207 $this->usernames); 208 } 209 210 if ($this->emails !== null) { 211 $where[] = qsprintf( 212 $conn_r, 213 'email.address IN (%Ls)', 214 $this->emails); 215 } 216 217 if ($this->realnames !== null) { 218 $where[] = qsprintf( 219 $conn_r, 220 'user.realName IN (%Ls)', 221 $this->realnames); 222 } 223 224 if ($this->phids !== null) { 225 $where[] = qsprintf( 226 $conn_r, 227 'user.phid IN (%Ls)', 228 $this->phids); 229 } 230 231 if ($this->ids !== null) { 232 $where[] = qsprintf( 233 $conn_r, 234 'user.id IN (%Ld)', 235 $this->ids); 236 } 237 238 if ($this->dateCreatedAfter) { 239 $where[] = qsprintf( 240 $conn_r, 241 'user.dateCreated >= %d', 242 $this->dateCreatedAfter); 243 } 244 245 if ($this->dateCreatedBefore) { 246 $where[] = qsprintf( 247 $conn_r, 248 'user.dateCreated <= %d', 249 $this->dateCreatedBefore); 250 } 251 252 if ($this->isAdmin) { 253 $where[] = qsprintf( 254 $conn_r, 255 'user.isAdmin = 1'); 256 } 257 258 if ($this->isDisabled !== null) { 259 $where[] = qsprintf( 260 $conn_r, 261 'user.isDisabled = %d', 262 (int)$this->isDisabled); 263 } 264 265 if ($this->isApproved !== null) { 266 $where[] = qsprintf( 267 $conn_r, 268 'user.isApproved = %d', 269 (int)$this->isApproved); 270 } 271 272 if ($this->isSystemAgent) { 273 $where[] = qsprintf( 274 $conn_r, 275 'user.isSystemAgent = 1'); 276 } 277 278 if (strlen($this->nameLike)) { 279 $where[] = qsprintf( 280 $conn_r, 281 'user.username LIKE %~ OR user.realname LIKE %~', 282 $this->nameLike, 283 $this->nameLike); 284 } 285 286 $where[] = $this->buildPagingClause($conn_r); 287 288 return $this->formatWhereClause($where); 289 } 290 291 protected function getPagingColumn() { 292 return 'user.id'; 293 } 294 295 protected function getApplicationSearchObjectPHIDColumn() { 296 return 'user.phid'; 297 } 298 299 public function getQueryApplicationClass() { 300 return 'PhabricatorPeopleApplication'; 301 } 302 303 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |