2013-04-26 10:30:41 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ConpherenceParticipantCountQuery
|
|
|
|
extends PhabricatorOffsetPagedQuery {
|
|
|
|
|
|
|
|
private $participantPHIDs;
|
2017-04-19 12:17:37 -07:00
|
|
|
private $unread;
|
2013-04-26 10:30:41 -07:00
|
|
|
|
|
|
|
public function withParticipantPHIDs(array $phids) {
|
|
|
|
$this->participantPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:17:37 -07:00
|
|
|
public function withUnread($unread) {
|
|
|
|
$this->unread = $unread;
|
2013-04-26 10:30:41 -07:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
2017-04-19 12:17:37 -07:00
|
|
|
$thread = new ConpherenceThread();
|
2013-04-26 10:30:41 -07:00
|
|
|
$table = new ConpherenceParticipant();
|
2017-04-19 12:17:37 -07:00
|
|
|
$conn = $table->establishConnection('r');
|
2013-04-26 10:30:41 -07:00
|
|
|
|
|
|
|
$rows = queryfx_all(
|
2017-04-19 12:17:37 -07:00
|
|
|
$conn,
|
|
|
|
'SELECT COUNT(*) as count, participantPHID
|
|
|
|
FROM %T participant JOIN %T thread
|
|
|
|
ON participant.conpherencePHID = thread.phid %Q %Q %Q',
|
2013-04-26 10:30:41 -07:00
|
|
|
$table->getTableName(),
|
2017-04-19 12:17:37 -07:00
|
|
|
$thread->getTableName(),
|
|
|
|
$this->buildWhereClause($conn),
|
|
|
|
$this->buildGroupByClause($conn),
|
|
|
|
$this->buildLimitClause($conn));
|
2013-04-26 10:30:41 -07:00
|
|
|
|
|
|
|
return ipull($rows, 'count', 'participantPHID');
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:17:37 -07:00
|
|
|
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
|
2013-04-26 10:30:41 -07:00
|
|
|
$where = array();
|
|
|
|
|
2017-04-19 12:17:37 -07:00
|
|
|
if ($this->participantPHIDs !== null) {
|
2013-04-26 10:30:41 -07:00
|
|
|
$where[] = qsprintf(
|
2017-04-19 12:17:37 -07:00
|
|
|
$conn,
|
|
|
|
'participant.participantPHID IN (%Ls)',
|
2013-04-26 10:30:41 -07:00
|
|
|
$this->participantPHIDs);
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:17:37 -07:00
|
|
|
if ($this->unread !== null) {
|
|
|
|
if ($this->unread) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'participant.seenMessageCount < thread.messageCount');
|
|
|
|
} else {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'participant.seenMessageCount >= thread.messageCount');
|
|
|
|
}
|
2013-04-26 10:30:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:17:37 -07:00
|
|
|
private function buildGroupByClause(AphrontDatabaseConnection $conn) {
|
|
|
|
return qsprintf(
|
|
|
|
$conn,
|
2013-04-26 10:30:41 -07:00
|
|
|
'GROUP BY participantPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|