[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Query class that answers the question: 5 * 6 * - Q: How many unread conpherences am I participating in? 7 * - A: 8 * id(new ConpherenceParticipantCountQuery()) 9 * ->withParticipantPHIDs(array($my_phid)) 10 * ->withParticipationStatus(ConpherenceParticipationStatus::BEHIND) 11 * ->execute(); 12 */ 13 final class ConpherenceParticipantCountQuery 14 extends PhabricatorOffsetPagedQuery { 15 16 private $participantPHIDs; 17 private $participationStatus; 18 19 public function withParticipantPHIDs(array $phids) { 20 $this->participantPHIDs = $phids; 21 return $this; 22 } 23 24 public function withParticipationStatus($participation_status) { 25 $this->participationStatus = $participation_status; 26 return $this; 27 } 28 29 public function execute() { 30 $table = new ConpherenceParticipant(); 31 $conn_r = $table->establishConnection('r'); 32 33 $rows = queryfx_all( 34 $conn_r, 35 'SELECT COUNT(*) as count, participantPHID '. 36 'FROM %T participant %Q %Q %Q', 37 $table->getTableName(), 38 $this->buildWhereClause($conn_r), 39 $this->buildGroupByClause($conn_r), 40 $this->buildLimitClause($conn_r)); 41 42 return ipull($rows, 'count', 'participantPHID'); 43 } 44 45 private function buildWhereClause($conn_r) { 46 $where = array(); 47 48 if ($this->participantPHIDs) { 49 $where[] = qsprintf( 50 $conn_r, 51 'participantPHID IN (%Ls)', 52 $this->participantPHIDs); 53 } 54 55 if ($this->participationStatus !== null) { 56 $where[] = qsprintf( 57 $conn_r, 58 'participationStatus = %d', 59 $this->participationStatus); 60 } 61 62 return $this->formatWhereClause($where); 63 } 64 65 private function buildGroupByClause(AphrontDatabaseConnection $conn_r) { 66 $group_by = qsprintf( 67 $conn_r, 68 'GROUP BY participantPHID'); 69 70 return $group_by; 71 } 72 73 }
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 |