Changeset View
Changeset View
Standalone View
Standalone View
src/applications/calendar/storage/PhabricatorCalendarEvent.php
Show First 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO | ||||
public function generateNthGhost( | public function generateNthGhost( | ||||
$sequence_index, | $sequence_index, | ||||
PhabricatorUser $actor) { | PhabricatorUser $actor) { | ||||
$frequency = $this->getFrequencyUnit(); | $frequency = $this->getFrequencyUnit(); | ||||
$modify_key = '+'.$sequence_index.' '.$frequency; | $modify_key = '+'.$sequence_index.' '.$frequency; | ||||
$instance_of = ($this->getPHID()) ? | if ($this->instanceOfEventPHID) { | ||||
$this->getPHID() : $this->instanceOfEventPHID; | $event = id(new PhabricatorCalendarEventQuery()) | ||||
->setViewer($actor) | |||||
->withPHIDs(array($this->instanceOfEventPHID)) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
return $event->generateNthGhost($sequence_index, $actor); | |||||
} | |||||
$instance_of = ($this->instanceOfEventPHID) ? | |||||
$this->instanceOfEventPHID : $this->getPHID(); | |||||
$date = $this->dateFrom; | $date = $this->dateFrom; | ||||
$date_time = PhabricatorTime::getDateTimeFromEpoch($date, $actor); | $date_time = PhabricatorTime::getDateTimeFromEpoch($date, $actor); | ||||
$date_time->modify($modify_key); | $date_time->modify($modify_key); | ||||
$date = $date_time->format('U'); | $date = $date_time->format('U'); | ||||
$duration = $this->dateTo - $this->dateFrom; | $duration = $this->dateTo - $this->dateFrom; | ||||
$edit_policy = PhabricatorPolicies::POLICY_NOONE; | $edit_policy = PhabricatorPolicies::POLICY_NOONE; | ||||
$ghost_event = id(clone $this) | $ghost_event = id(clone $this) | ||||
->setIsGhostEvent(true) | ->setIsGhostEvent(true) | ||||
->setDateFrom($date) | ->setDateFrom($date) | ||||
->setDateTo($date + $duration) | ->setDateTo($date + $duration) | ||||
->setIsRecurring(true) | ->setIsRecurring(true) | ||||
->setRecurrenceFrequency($this->recurrenceFrequency) | ->setRecurrenceFrequency($this->recurrenceFrequency) | ||||
->setInstanceOfEventPHID($instance_of) | ->setInstanceOfEventPHID($instance_of) | ||||
->setSequenceIndex($sequence_index) | ->setSequenceIndex($sequence_index) | ||||
->setEditPolicy($edit_policy); | ->setEditPolicy($edit_policy); | ||||
return $ghost_event; | return $ghost_event; | ||||
} | } | ||||
protected function getEventAtIndexForGhostEvent($viewer, $event, $index) { | |||||
$phid = $event->getInstanceOfEventPHID(); | |||||
if (!$phid) { | |||||
$phid = $event->getPHID(); | |||||
} | |||||
return $this->getEventAtIndexForGhostPHID($viewer, $phid, $index); | |||||
} | |||||
protected function getEventAtIndexForGhostPHID($viewer, $phid, $index) { | |||||
$result = id(new PhabricatorCalendarEventQuery()) | |||||
->setViewer($viewer) | |||||
->withInstanceSequencePairs( | |||||
array( | |||||
array( | |||||
$phid, | |||||
$index, | |||||
), | |||||
)) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
return $result; | |||||
} | |||||
public function getFrequencyUnit() { | public function getFrequencyUnit() { | ||||
$frequency = idx($this->recurrenceFrequency, 'rule'); | $frequency = idx($this->recurrenceFrequency, 'rule'); | ||||
switch ($frequency) { | switch ($frequency) { | ||||
case 'daily': | case 'daily': | ||||
return 'day'; | return 'day'; | ||||
case 'weekly': | case 'weekly': | ||||
return 'week'; | return 'week'; | ||||
▲ Show 20 Lines • Show All 240 Lines • Show Last 20 Lines |