Changeset View
Changeset View
Standalone View
Standalone View
src/applications/calendar/storage/PhabricatorCalendarEvent.php
<?php | <?php | ||||
final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO | final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO | ||||
implements PhabricatorPolicyInterface, | implements PhabricatorPolicyInterface, | ||||
PhabricatorMarkupInterface, | PhabricatorMarkupInterface, | ||||
PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
PhabricatorSubscribableInterface, | PhabricatorSubscribableInterface, | ||||
PhabricatorTokenReceiverInterface, | PhabricatorTokenReceiverInterface, | ||||
PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
PhabricatorMentionableInterface, | PhabricatorMentionableInterface, | ||||
PhabricatorFlaggableInterface { | PhabricatorFlaggableInterface { | ||||
protected $name; | protected $name; | ||||
protected $userPHID; | protected $userPHID; | ||||
protected $dateFrom; | protected $dateFrom; | ||||
protected $dateTo; | protected $dateTo; | ||||
protected $status; | |||||
protected $description; | protected $description; | ||||
protected $isCancelled; | protected $isCancelled; | ||||
protected $isAllDay; | protected $isAllDay; | ||||
protected $mailKey; | protected $mailKey; | ||||
protected $viewPolicy; | protected $viewPolicy; | ||||
protected $editPolicy; | protected $editPolicy; | ||||
private $invitees = self::ATTACHABLE; | private $invitees = self::ATTACHABLE; | ||||
private $appliedViewer; | private $appliedViewer; | ||||
const STATUS_AWAY = 1; | |||||
const STATUS_SPORADIC = 2; | |||||
public static function initializeNewCalendarEvent(PhabricatorUser $actor) { | public static function initializeNewCalendarEvent(PhabricatorUser $actor) { | ||||
$app = id(new PhabricatorApplicationQuery()) | $app = id(new PhabricatorApplicationQuery()) | ||||
->setViewer($actor) | ->setViewer($actor) | ||||
->withClasses(array('PhabricatorCalendarApplication')) | ->withClasses(array('PhabricatorCalendarApplication')) | ||||
->executeOne(); | ->executeOne(); | ||||
return id(new PhabricatorCalendarEvent()) | return id(new PhabricatorCalendarEvent()) | ||||
->setUserPHID($actor->getPHID()) | ->setUserPHID($actor->getPHID()) | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO | ||||
* series of back-to-back meetings, even if they don't strictly overlap. | * series of back-to-back meetings, even if they don't strictly overlap. | ||||
* | * | ||||
* @return int Event start date for availability caches. | * @return int Event start date for availability caches. | ||||
*/ | */ | ||||
public function getDateFromForCache() { | public function getDateFromForCache() { | ||||
return ($this->getDateFrom() - phutil_units('15 minutes in seconds')); | return ($this->getDateFrom() - phutil_units('15 minutes in seconds')); | ||||
} | } | ||||
private static $statusTexts = array( | |||||
self::STATUS_AWAY => 'away', | |||||
self::STATUS_SPORADIC => 'sporadic', | |||||
); | |||||
public function setTextStatus($status) { | |||||
$statuses = array_flip(self::$statusTexts); | |||||
return $this->setStatus($statuses[$status]); | |||||
} | |||||
public function getTextStatus() { | |||||
return self::$statusTexts[$this->status]; | |||||
} | |||||
public function getStatusOptions() { | |||||
return array( | |||||
self::STATUS_AWAY => pht('Away'), | |||||
self::STATUS_SPORADIC => pht('Sporadic'), | |||||
); | |||||
} | |||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'name' => 'text', | 'name' => 'text', | ||||
'dateFrom' => 'epoch', | 'dateFrom' => 'epoch', | ||||
'dateTo' => 'epoch', | 'dateTo' => 'epoch', | ||||
'status' => 'uint32', | |||||
'description' => 'text', | 'description' => 'text', | ||||
'isCancelled' => 'bool', | 'isCancelled' => 'bool', | ||||
'isAllDay' => 'bool', | 'isAllDay' => 'bool', | ||||
'mailKey' => 'bytes20', | 'mailKey' => 'bytes20', | ||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'userPHID_dateFrom' => array( | 'userPHID_dateFrom' => array( | ||||
'columns' => array('userPHID', 'dateTo'), | 'columns' => array('userPHID', 'dateTo'), | ||||
), | ), | ||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function generatePHID() { | public function generatePHID() { | ||||
return PhabricatorPHID::generateNewPHID( | return PhabricatorPHID::generateNewPHID( | ||||
PhabricatorCalendarEventPHIDType::TYPECONST); | PhabricatorCalendarEventPHIDType::TYPECONST); | ||||
} | } | ||||
public function getMonogram() { | public function getMonogram() { | ||||
return 'E'.$this->getID(); | return 'E'.$this->getID(); | ||||
} | } | ||||
public function getTerseSummary(PhabricatorUser $viewer) { | |||||
$until = phabricator_date($this->dateTo, $viewer); | |||||
if ($this->status == self::STATUS_SPORADIC) { | |||||
return pht('Sporadic until %s', $until); | |||||
} else { | |||||
return pht('Away until %s', $until); | |||||
} | |||||
} | |||||
public static function getNameForStatus($value) { | |||||
switch ($value) { | |||||
case self::STATUS_AWAY: | |||||
return pht('Away'); | |||||
case self::STATUS_SPORADIC: | |||||
return pht('Sporadic'); | |||||
default: | |||||
return pht('Unknown'); | |||||
} | |||||
} | |||||
public function getInvitees() { | public function getInvitees() { | ||||
return $this->assertAttached($this->invitees); | return $this->assertAttached($this->invitees); | ||||
} | } | ||||
public function attachInvitees(array $invitees) { | public function attachInvitees(array $invitees) { | ||||
$this->invitees = $invitees; | $this->invitees = $invitees; | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 170 Lines • Show Last 20 Lines |