1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-25 22:18:19 +01:00

Searching Calendar events by invitee should work now

Summary: Closes T8045, Searching Calendar events by invitee should work now

Test Plan: Open Advanced Search on Calendar, search by invitee, only events with invitee specified should be returned.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T8045

Differential Revision: https://secure.phabricator.com/D12738
This commit is contained in:
lkassianik 2015-05-06 11:12:24 -07:00
parent bcf60f1b05
commit a54011b84e

View file

@ -7,7 +7,7 @@ final class PhabricatorCalendarEventQuery
private $phids; private $phids;
private $rangeBegin; private $rangeBegin;
private $rangeEnd; private $rangeEnd;
private $invitedPHIDs; private $inviteePHIDs;
private $creatorPHIDs; private $creatorPHIDs;
private $isCancelled; private $isCancelled;
@ -28,7 +28,7 @@ final class PhabricatorCalendarEventQuery
} }
public function withInvitedPHIDs(array $phids) { public function withInvitedPHIDs(array $phids) {
$this->invitedPHIDs = $phids; $this->inviteePHIDs = $phids;
return $this; return $this;
} }
@ -48,67 +48,79 @@ final class PhabricatorCalendarEventQuery
$data = queryfx_all( $data = queryfx_all(
$conn_r, $conn_r,
'SELECT * FROM %T %Q %Q %Q', 'SELECT event.* FROM %T event %Q %Q %Q %Q %Q',
$table->getTableName(), $table->getTableName(),
$this->buildJoinClause($conn_r),
$this->buildWhereClause($conn_r), $this->buildWhereClause($conn_r),
$this->buildGroupClause($conn_r),
$this->buildOrderClause($conn_r), $this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r)); $this->buildLimitClause($conn_r));
return $table->loadAllFromArray($data); return $table->loadAllFromArray($data);
} }
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn_r) {
$parts = parent::buildJoinClauseParts($conn_r);
if ($this->inviteePHIDs !== null) {
$parts[] = qsprintf(
$conn_r,
'JOIN %T invitee ON invitee.eventPHID = event.phid'.
'AND invitee.status != %s',
id(new PhabricatorCalendarEventInvitee())->getTableName(),
PhabricatorCalendarEventInvitee::STATUS_UNINVITED);
}
return $parts;
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array(); $where = array();
if ($this->ids) { if ($this->ids) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'id IN (%Ld)', 'event.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'phid IN (%Ls)', 'event.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->rangeBegin) { if ($this->rangeBegin) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'dateTo >= %d', 'event.dateTo >= %d',
$this->rangeBegin); $this->rangeBegin);
} }
if ($this->rangeEnd) { if ($this->rangeEnd) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'dateFrom <= %d', 'event.dateFrom <= %d',
$this->rangeEnd); $this->rangeEnd);
} }
// TODO: Currently, the creator is always the only invitee, but you can if ($this->inviteePHIDs !== null) {
// query them separately since this won't always be true.
if ($this->invitedPHIDs) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'userPHID IN (%Ls)', 'invitee.inviteePHID IN (%Ls)',
$this->invitedPHIDs); $this->inviteePHIDs);
} }
if ($this->creatorPHIDs) { if ($this->creatorPHIDs) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'userPHID IN (%Ls)', 'event.userPHID IN (%Ls)',
$this->creatorPHIDs); $this->creatorPHIDs);
} }
if ($this->isCancelled !== null) { if ($this->isCancelled !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'isCancelled = %d', 'event.isCancelled = %d',
(int)$this->isCancelled); (int)$this->isCancelled);
} }
@ -117,6 +129,21 @@ final class PhabricatorCalendarEventQuery
return $this->formatWhereClause($where); return $this->formatWhereClause($where);
} }
protected function getPrimaryTableAlias() {
return 'event';
}
protected function shouldGroupQueryResultRows() {
if ($this->inviteePHIDs !== null) {
return true;
}
return parent::shouldGroupQueryResultRows();
}
protected function getApplicationSearchObjectPHIDColumn() {
return 'event.phid';
}
public function getQueryApplicationClass() { public function getQueryApplicationClass() {
return 'PhabricatorCalendarApplication'; return 'PhabricatorCalendarApplication';
} }