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;
|
2015-06-03 09:27:39 -07:00
|
|
|
private $eventsWithNoParent;
|
2015-05-31 15:04:48 -07:00
|
|
|
private $instanceSequencePairs;
|
|
|
|
|
2015-05-28 17:27:25 -07:00
|
|
|
private $generateGhosts = false;
|
|
|
|
|
2015-06-22 13:27:37 -07:00
|
|
|
public function newResultObject() {
|
|
|
|
return new PhabricatorCalendarEvent();
|
|
|
|
}
|
|
|
|
|
2015-05-28 17:27:25 -07:00
|
|
|
public function setGenerateGhosts($generate_ghosts) {
|
|
|
|
$this->generateGhosts = $generate_ghosts;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-06-03 09:27:39 -07:00
|
|
|
public function withEventsWithNoParent($events_with_no_parent) {
|
|
|
|
$this->eventsWithNoParent = $events_with_no_parent;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-05-31 15:04:48 -07:00
|
|
|
public function withInstanceSequencePairs(array $pairs) {
|
|
|
|
$this->instanceSequencePairs = $pairs;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-05-21 17:10:27 -07:00
|
|
|
protected function getDefaultOrderVector() {
|
|
|
|
return array('start', 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOrderableColumns() {
|
|
|
|
return array(
|
|
|
|
'start' => array(
|
|
|
|
'table' => $this->getPrimaryTableAlias(),
|
|
|
|
'column' => 'dateFrom',
|
|
|
|
'reverse' => true,
|
|
|
|
'type' => 'int',
|
|
|
|
'unique' => false,
|
|
|
|
),
|
|
|
|
) + parent::getOrderableColumns();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getPagingValueMap($cursor, array $keys) {
|
|
|
|
$event = $this->loadCursorObject($cursor);
|
|
|
|
return array(
|
|
|
|
'start' => $event->getDateFrom(),
|
|
|
|
'id' => $event->getID(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
protected function loadPage() {
|
2016-04-07 05:10:55 -07:00
|
|
|
$events = $this->loadStandardPage($this->newResultObject());
|
2015-05-07 18:57:28 -07:00
|
|
|
|
2016-04-07 05:10:55 -07:00
|
|
|
$viewer = $this->getViewer();
|
2015-05-07 18:57:28 -07:00
|
|
|
foreach ($events as $event) {
|
2016-04-07 05:10:55 -07:00
|
|
|
$event->applyViewerTimezone($viewer);
|
2015-05-07 18:57:28 -07:00
|
|
|
}
|
|
|
|
|
2015-05-28 17:27:25 -07:00
|
|
|
if (!$this->generateGhosts) {
|
|
|
|
return $events;
|
|
|
|
}
|
|
|
|
|
2015-06-03 13:01:26 -07:00
|
|
|
$enforced_end = null;
|
2016-04-07 05:10:55 -07:00
|
|
|
$raw_limit = $this->getRawResultLimit();
|
|
|
|
|
|
|
|
if (!$raw_limit && !$this->rangeEnd) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'Event queries which generate ghost events must include either a '.
|
|
|
|
'result limit or an end date, because they may otherwise generate '.
|
|
|
|
'an infinite number of results. This query has neither.'));
|
|
|
|
}
|
2015-05-31 15:04:48 -07:00
|
|
|
|
2015-06-02 19:44:31 -07:00
|
|
|
foreach ($events as $key => $event) {
|
2015-05-28 17:27:25 -07:00
|
|
|
$sequence_start = 0;
|
2015-06-01 18:56:11 -07:00
|
|
|
$sequence_end = null;
|
2015-05-29 15:46:18 -07:00
|
|
|
$duration = $event->getDateTo() - $event->getDateFrom();
|
2015-06-01 18:56:11 -07:00
|
|
|
$end = null;
|
2015-05-28 17:27:25 -07:00
|
|
|
|
2015-06-02 19:44:31 -07:00
|
|
|
$instance_of = $event->getInstanceOfEventPHID();
|
|
|
|
|
|
|
|
if ($instance_of == null && $this->isCancelled !== null) {
|
|
|
|
if ($event->getIsCancelled() != $this->isCancelled) {
|
|
|
|
unset($events[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($event->getIsRecurring() && $instance_of == null) {
|
2015-05-28 17:27:25 -07:00
|
|
|
$frequency = $event->getFrequencyUnit();
|
|
|
|
$modify_key = '+1 '.$frequency;
|
|
|
|
|
|
|
|
if ($this->rangeBegin && $this->rangeBegin > $event->getDateFrom()) {
|
2015-05-29 15:46:18 -07:00
|
|
|
$max_date = $this->rangeBegin - $duration;
|
2015-05-28 17:27:25 -07:00
|
|
|
$date = $event->getDateFrom();
|
|
|
|
$datetime = PhabricatorTime::getDateTimeFromEpoch($date, $viewer);
|
|
|
|
|
|
|
|
while ($date < $max_date) {
|
|
|
|
// TODO: optimize this to not loop through all off-screen events
|
|
|
|
$sequence_start++;
|
|
|
|
$datetime = PhabricatorTime::getDateTimeFromEpoch($date, $viewer);
|
|
|
|
$date = $datetime->modify($modify_key)->format('U');
|
|
|
|
}
|
|
|
|
|
|
|
|
$start = $this->rangeBegin;
|
|
|
|
} else {
|
2015-05-29 15:46:18 -07:00
|
|
|
$start = $event->getDateFrom() - $duration;
|
2015-05-28 17:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$date = $start;
|
2015-06-01 18:56:11 -07:00
|
|
|
$datetime = PhabricatorTime::getDateTimeFromEpoch($date, $viewer);
|
2015-05-28 17:27:25 -07:00
|
|
|
|
2015-06-01 18:56:11 -07:00
|
|
|
if (($this->rangeEnd && $event->getRecurrenceEndDate()) &&
|
|
|
|
$this->rangeEnd < $event->getRecurrenceEndDate()) {
|
2015-05-28 17:27:25 -07:00
|
|
|
$end = $this->rangeEnd;
|
2015-06-01 18:56:11 -07:00
|
|
|
} else if ($event->getRecurrenceEndDate()) {
|
|
|
|
$end = $event->getRecurrenceEndDate();
|
|
|
|
} else if ($this->rangeEnd) {
|
|
|
|
$end = $this->rangeEnd;
|
2015-06-03 13:01:26 -07:00
|
|
|
} else if ($enforced_end) {
|
|
|
|
if ($end) {
|
|
|
|
$end = min($end, $enforced_end);
|
|
|
|
} else {
|
|
|
|
$end = $enforced_end;
|
|
|
|
}
|
2015-06-01 18:56:11 -07:00
|
|
|
}
|
2015-05-28 17:27:25 -07:00
|
|
|
|
2015-06-01 18:56:11 -07:00
|
|
|
if ($end) {
|
|
|
|
$sequence_end = $sequence_start;
|
2015-05-28 17:27:25 -07:00
|
|
|
while ($date < $end) {
|
2015-06-01 18:56:11 -07:00
|
|
|
$sequence_end++;
|
2015-05-28 17:27:25 -07:00
|
|
|
$datetime->modify($modify_key);
|
|
|
|
$date = $datetime->format('U');
|
2016-04-07 05:10:55 -07:00
|
|
|
if ($sequence_end > $raw_limit + $sequence_start) {
|
2015-06-03 13:01:26 -07:00
|
|
|
break;
|
|
|
|
}
|
2015-05-28 17:27:25 -07:00
|
|
|
}
|
|
|
|
} else {
|
2016-04-07 05:10:55 -07:00
|
|
|
$sequence_end = $raw_limit + $sequence_start;
|
2015-05-28 17:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$sequence_start = max(1, $sequence_start);
|
|
|
|
|
2015-06-01 18:56:11 -07:00
|
|
|
for ($index = $sequence_start; $index < $sequence_end; $index++) {
|
2015-05-28 17:27:25 -07:00
|
|
|
$events[] = $event->generateNthGhost($index, $viewer);
|
2015-06-03 13:01:26 -07:00
|
|
|
}
|
2015-05-31 15:04:48 -07:00
|
|
|
|
2016-04-07 05:10:55 -07:00
|
|
|
// NOTE: We're slicing results every time because this makes it cheaper
|
|
|
|
// to generate future ghosts. If we already have 100 events that occur
|
|
|
|
// before July 1, we know we never need to generate ghosts after that
|
|
|
|
// because they couldn't possibly ever appear in the result set.
|
|
|
|
|
|
|
|
if ($raw_limit) {
|
|
|
|
if (count($events) >= $raw_limit) {
|
|
|
|
$events = msort($events, 'getDateFrom');
|
|
|
|
$events = array_slice($events, 0, $raw_limit, true);
|
|
|
|
$enforced_end = last($events)->getDateFrom();
|
|
|
|
}
|
2015-05-31 15:04:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-03 13:01:26 -07:00
|
|
|
$map = array();
|
|
|
|
$instance_sequence_pairs = array();
|
|
|
|
|
|
|
|
foreach ($events as $key => $event) {
|
|
|
|
if ($event->getIsGhostEvent()) {
|
|
|
|
$index = $event->getSequenceIndex();
|
|
|
|
$instance_sequence_pairs[] = array($event->getPHID(), $index);
|
|
|
|
$map[$event->getPHID()][$index] = $key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-31 15:04:48 -07:00
|
|
|
if (count($instance_sequence_pairs) > 0) {
|
|
|
|
$sub_query = id(new PhabricatorCalendarEventQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->setParentQuery($this)
|
|
|
|
->withInstanceSequencePairs($instance_sequence_pairs)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
foreach ($sub_query as $edited_ghost) {
|
|
|
|
$indexes = idx($map, $edited_ghost->getInstanceOfEventPHID());
|
|
|
|
$key = idx($indexes, $edited_ghost->getSequenceIndex());
|
|
|
|
$events[$key] = $edited_ghost;
|
|
|
|
}
|
|
|
|
|
|
|
|
$id_map = array();
|
|
|
|
foreach ($events as $key => $event) {
|
|
|
|
if ($event->getIsGhostEvent()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isset($id_map[$event->getID()])) {
|
|
|
|
unset($events[$key]);
|
|
|
|
} else {
|
|
|
|
$id_map[$event->getID()] = true;
|
2015-05-28 17:27:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 18:57:28 -07:00
|
|
|
return $events;
|
2014-02-06 10:07:42 -08:00
|
|
|
}
|
|
|
|
|
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,
|
2015-05-06 12:41:02 -07:00
|
|
|
'JOIN %T invitee ON invitee.eventPHID = event.phid
|
|
|
|
AND invitee.status != %s',
|
2015-05-06 11:12:24 -07:00
|
|
|
id(new PhabricatorCalendarEventInvitee())->getTableName(),
|
|
|
|
PhabricatorCalendarEventInvitee::STATUS_UNINVITED);
|
|
|
|
}
|
|
|
|
return $parts;
|
|
|
|
}
|
|
|
|
|
2016-04-07 05:10:55 -07:00
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
2014-02-06 10:07:42 -08:00
|
|
|
|
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
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(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
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(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
2015-05-28 17:27:25 -07:00
|
|
|
'event.dateTo >= %d OR event.isRecurring = 1',
|
2014-02-06 10:10:18 -08:00
|
|
|
$this->rangeBegin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->rangeEnd) {
|
2014-02-06 10:07:42 -08:00
|
|
|
$where[] = qsprintf(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
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(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
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(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
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(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
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);
|
|
|
|
}
|
|
|
|
|
2015-06-03 09:27:39 -07:00
|
|
|
if ($this->eventsWithNoParent == true) {
|
|
|
|
$where[] = qsprintf(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
2015-06-03 09:27:39 -07:00
|
|
|
'event.instanceOfEventPHID IS NULL');
|
|
|
|
}
|
|
|
|
|
2015-05-31 15:04:48 -07:00
|
|
|
if ($this->instanceSequencePairs !== null) {
|
|
|
|
$sql = array();
|
|
|
|
|
|
|
|
foreach ($this->instanceSequencePairs as $pair) {
|
|
|
|
$sql[] = qsprintf(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
2015-05-31 15:04:48 -07:00
|
|
|
'(event.instanceOfEventPHID = %s AND event.sequenceIndex = %d)',
|
|
|
|
$pair[0],
|
|
|
|
$pair[1]);
|
|
|
|
}
|
2016-04-07 05:10:55 -07:00
|
|
|
|
2015-05-31 15:04:48 -07:00
|
|
|
$where[] = qsprintf(
|
2016-04-07 05:10:55 -07:00
|
|
|
$conn,
|
2015-05-31 15:04:48 -07:00
|
|
|
'%Q',
|
|
|
|
implode(' OR ', $sql));
|
|
|
|
}
|
|
|
|
|
2016-04-07 05:10:55 -07:00
|
|
|
return $where;
|
2014-02-06 10:07:42 -08:00
|
|
|
}
|
|
|
|
|
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) {
|
2015-05-26 14:28:07 -07:00
|
|
|
$range_start = $this->rangeBegin;
|
|
|
|
$range_end = $this->rangeEnd;
|
2015-06-02 19:44:31 -07:00
|
|
|
$instance_of_event_phids = array();
|
|
|
|
$recurring_events = array();
|
|
|
|
$viewer = $this->getViewer();
|
2015-05-26 14:28:07 -07:00
|
|
|
|
|
|
|
foreach ($events as $key => $event) {
|
|
|
|
$event_start = $event->getDateFrom();
|
|
|
|
$event_end = $event->getDateTo();
|
|
|
|
|
|
|
|
if ($range_start && $event_end < $range_start) {
|
|
|
|
unset($events[$key]);
|
|
|
|
}
|
|
|
|
if ($range_end && $event_start > $range_end) {
|
|
|
|
unset($events[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-29 13:51:09 -07:00
|
|
|
$phids = array();
|
|
|
|
|
|
|
|
foreach ($events as $event) {
|
|
|
|
$phids[] = $event->getPHID();
|
2015-06-02 19:44:31 -07:00
|
|
|
$instance_of = $event->getInstanceOfEventPHID();
|
|
|
|
|
|
|
|
if ($instance_of) {
|
2015-06-03 09:27:39 -07:00
|
|
|
$instance_of_event_phids[] = $instance_of;
|
2015-06-02 19:44:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($instance_of_event_phids) > 0) {
|
|
|
|
$recurring_events = id(new PhabricatorCalendarEventQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs($instance_of_event_phids)
|
2015-06-03 09:27:39 -07:00
|
|
|
->withEventsWithNoParent(true)
|
2015-06-02 19:44:31 -07:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
$recurring_events = mpull($recurring_events, null, 'getPHID');
|
2015-04-29 13:51:09 -07:00
|
|
|
}
|
|
|
|
|
2015-05-29 07:17:09 -07:00
|
|
|
if ($events) {
|
|
|
|
$invitees = id(new PhabricatorCalendarEventInviteeQuery())
|
2015-06-02 19:44:31 -07:00
|
|
|
->setViewer($viewer)
|
2015-05-29 07:17:09 -07:00
|
|
|
->withEventPHIDs($phids)
|
|
|
|
->execute();
|
|
|
|
$invitees = mgroup($invitees, 'getEventPHID');
|
|
|
|
} else {
|
|
|
|
$invitees = array();
|
|
|
|
}
|
2015-04-29 13:51:09 -07:00
|
|
|
|
2015-06-02 19:44:31 -07:00
|
|
|
foreach ($events as $key => $event) {
|
2015-04-29 13:51:09 -07:00
|
|
|
$event_invitees = idx($invitees, $event->getPHID(), array());
|
|
|
|
$event->attachInvitees($event_invitees);
|
2015-06-02 19:44:31 -07:00
|
|
|
|
|
|
|
$instance_of = $event->getInstanceOfEventPHID();
|
|
|
|
if (!$instance_of) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$parent = idx($recurring_events, $instance_of);
|
|
|
|
|
|
|
|
// should never get here
|
|
|
|
if (!$parent) {
|
|
|
|
unset($events[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$event->attachParentEvent($parent);
|
|
|
|
|
|
|
|
if ($this->isCancelled !== null) {
|
|
|
|
if ($event->getIsCancelled() != $this->isCancelled) {
|
|
|
|
unset($events[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-04-29 13:51:09 -07:00
|
|
|
}
|
|
|
|
|
2015-05-26 14:28:07 -07:00
|
|
|
$events = msort($events, 'getDateFrom');
|
|
|
|
|
2015-04-29 13:51:09 -07:00
|
|
|
return $events;
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
}
|