2014-02-06 10:07:42 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCalendarEventQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $ids;
|
2014-02-06 10:10:43 -08:00
|
|
|
private $phids;
|
2014-02-06 10:07:42 -08:00
|
|
|
private $rangeBegin;
|
|
|
|
private $rangeEnd;
|
2015-05-06 11:12:24 -07:00
|
|
|
private $inviteePHIDs;
|
2014-02-06 10:10:18 -08:00
|
|
|
private $creatorPHIDs;
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 08:39:39 -07:00
|
|
|
private $isCancelled;
|
2014-02-06 10:07:42 -08:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:10:43 -08:00
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
public function withDateRange($begin, $end) {
|
|
|
|
$this->rangeBegin = $begin;
|
|
|
|
$this->rangeEnd = $end;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withInvitedPHIDs(array $phids) {
|
2015-05-06 11:12:24 -07:00
|
|
|
$this->inviteePHIDs = $phids;
|
2014-02-06 10:07:42 -08:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:10:18 -08:00
|
|
|
public function withCreatorPHIDs(array $phids) {
|
|
|
|
$this->creatorPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 08:39:39 -07:00
|
|
|
public function withIsCancelled($is_cancelled) {
|
|
|
|
$this->isCancelled = $is_cancelled;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
protected function loadPage() {
|
|
|
|
$table = new PhabricatorCalendarEvent();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
2015-05-06 11:12:24 -07:00
|
|
|
'SELECT event.* FROM %T event %Q %Q %Q %Q %Q',
|
2014-02-06 10:07:42 -08:00
|
|
|
$table->getTableName(),
|
2015-05-06 11:12:24 -07:00
|
|
|
$this->buildJoinClause($conn_r),
|
2014-02-06 10:07:42 -08:00
|
|
|
$this->buildWhereClause($conn_r),
|
2015-05-06 11:12:24 -07:00
|
|
|
$this->buildGroupClause($conn_r),
|
2014-02-06 10:07:42 -08:00
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
return $table->loadAllFromArray($data);
|
|
|
|
}
|
|
|
|
|
2015-05-06 11:12:24 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
Make buildWhereClause() a method of AphrontCursorPagedPolicyAwareQuery
Summary:
Ref T4100. Ref T5595.
To support a unified "Projects:" query across all applications, a future diff is going to add a set of "Edge Logic" capabilities to `PolicyAwareQuery` which write the required SELECT, JOIN, WHERE, HAVING and GROUP clauses for you.
With the addition of "Edge Logic", we'll have three systems which may need to build components of query claues: ordering/paging, customfields/applicationsearch, and edge logic.
For most clauses, queries don't currently call into the parent explicitly to get default components. I want to move more query construction logic up the class tree so it can be shared.
For most methods, this isn't a problem, but many subclasses define a `buildWhereClause()`. Make all such definitions protected and consistent.
This causes no behavioral changes.
Test Plan: Ran `arc unit --everything`, which does a pretty through job of verifying this statically.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: yelirekim, hach-que, epriestley
Maniphest Tasks: T4100, T5595
Differential Revision: https://secure.phabricator.com/D12453
2015-04-18 07:08:30 -07:00
|
|
|
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
2014-02-06 10:07:42 -08:00
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-05-06 11:12:24 -07:00
|
|
|
'event.id IN (%Ld)',
|
2014-02-06 10:07:42 -08:00
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:10:43 -08:00
|
|
|
if ($this->phids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-05-06 11:12:24 -07:00
|
|
|
'event.phid IN (%Ls)',
|
2014-02-06 10:10:43 -08:00
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:10:18 -08:00
|
|
|
if ($this->rangeBegin) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-05-06 11:12:24 -07:00
|
|
|
'event.dateTo >= %d',
|
2014-02-06 10:10:18 -08:00
|
|
|
$this->rangeBegin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->rangeEnd) {
|
2014-02-06 10:07:42 -08:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-05-06 11:12:24 -07:00
|
|
|
'event.dateFrom <= %d',
|
2014-02-06 10:07:42 -08:00
|
|
|
$this->rangeEnd);
|
|
|
|
}
|
|
|
|
|
2015-05-06 11:12:24 -07:00
|
|
|
if ($this->inviteePHIDs !== null) {
|
2014-02-06 10:07:42 -08:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-05-06 11:12:24 -07:00
|
|
|
'invitee.inviteePHID IN (%Ls)',
|
|
|
|
$this->inviteePHIDs);
|
2014-02-06 10:07:42 -08:00
|
|
|
}
|
|
|
|
|
2014-02-06 10:10:18 -08:00
|
|
|
if ($this->creatorPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-05-06 11:12:24 -07:00
|
|
|
'event.userPHID IN (%Ls)',
|
2014-02-06 10:10:18 -08:00
|
|
|
$this->creatorPHIDs);
|
|
|
|
}
|
|
|
|
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 08:39:39 -07:00
|
|
|
if ($this->isCancelled !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-05-06 11:12:24 -07:00
|
|
|
'event.isCancelled = %d',
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 08:39:39 -07:00
|
|
|
(int)$this->isCancelled);
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
2015-05-06 11:12:24 -07:00
|
|
|
protected function getPrimaryTableAlias() {
|
|
|
|
return 'event';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function shouldGroupQueryResultRows() {
|
|
|
|
if ($this->inviteePHIDs !== null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return parent::shouldGroupQueryResultRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getApplicationSearchObjectPHIDColumn() {
|
|
|
|
return 'event.phid';
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return 'PhabricatorCalendarApplication';
|
2014-02-06 10:07:42 -08:00
|
|
|
}
|
|
|
|
|
2015-04-29 13:51:09 -07:00
|
|
|
|
|
|
|
protected function willFilterPage(array $events) {
|
|
|
|
$phids = array();
|
|
|
|
|
|
|
|
foreach ($events as $event) {
|
|
|
|
$phids[] = $event->getPHID();
|
|
|
|
}
|
|
|
|
|
|
|
|
$invitees = id(new PhabricatorCalendarEventInviteeQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withEventPHIDs($phids)
|
|
|
|
->execute();
|
|
|
|
$invitees = mgroup($invitees, 'getEventPHID');
|
|
|
|
|
|
|
|
foreach ($events as $event) {
|
|
|
|
$event_invitees = idx($invitees, $event->getPHID(), array());
|
|
|
|
$event->attachInvitees($event_invitees);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $events;
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
}
|