[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorCalendarEvent 4 extends PhabricatorCalendarDAO 5 implements PhabricatorPolicyInterface { 6 7 protected $userPHID; 8 protected $dateFrom; 9 protected $dateTo; 10 protected $status; 11 protected $description; 12 13 const STATUS_AWAY = 1; 14 const STATUS_SPORADIC = 2; 15 16 private static $statusTexts = array( 17 self::STATUS_AWAY => 'away', 18 self::STATUS_SPORADIC => 'sporadic', 19 ); 20 21 public function getTextStatus() { 22 return self::$statusTexts[$this->status]; 23 } 24 25 public function getStatusOptions() { 26 return array( 27 self::STATUS_AWAY => pht('Away'), 28 self::STATUS_SPORADIC => pht('Sporadic'), 29 ); 30 } 31 32 public function getHumanStatus() { 33 $options = $this->getStatusOptions(); 34 return $options[$this->status]; 35 } 36 37 public function getConfiguration() { 38 return array( 39 self::CONFIG_AUX_PHID => true, 40 self::CONFIG_COLUMN_SCHEMA => array( 41 'dateFrom' => 'epoch', 42 'dateTo' => 'epoch', 43 'status' => 'uint32', 44 'description' => 'text', 45 ), 46 self::CONFIG_KEY_SCHEMA => array( 47 'userPHID_dateFrom' => array( 48 'columns' => array('userPHID', 'dateTo'), 49 ), 50 ), 51 ) + parent::getConfiguration(); 52 } 53 54 public function generatePHID() { 55 return PhabricatorPHID::generateNewPHID( 56 PhabricatorCalendarEventPHIDType::TYPECONST); 57 } 58 59 public function getTerseSummary(PhabricatorUser $viewer) { 60 $until = phabricator_date($this->dateTo, $viewer); 61 if ($this->status == PhabricatorCalendarEvent::STATUS_SPORADIC) { 62 return pht('Sporadic until %s', $until); 63 } else { 64 return pht('Away until %s', $until); 65 } 66 } 67 68 public function setTextStatus($status) { 69 $statuses = array_flip(self::$statusTexts); 70 return $this->setStatus($statuses[$status]); 71 } 72 73 public function loadCurrentStatuses($user_phids) { 74 if (!$user_phids) { 75 return array(); 76 } 77 78 $statuses = $this->loadAllWhere( 79 'userPHID IN (%Ls) AND UNIX_TIMESTAMP() BETWEEN dateFrom AND dateTo', 80 $user_phids); 81 82 return mpull($statuses, null, 'getUserPHID'); 83 } 84 85 /** 86 * Validates data and throws exceptions for non-sensical status 87 * windows 88 */ 89 public function save() { 90 91 if ($this->getDateTo() <= $this->getDateFrom()) { 92 throw new PhabricatorCalendarEventInvalidEpochException(); 93 } 94 95 return parent::save(); 96 } 97 98 99 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 100 101 102 public function getCapabilities() { 103 return array( 104 PhabricatorPolicyCapability::CAN_VIEW, 105 PhabricatorPolicyCapability::CAN_EDIT, 106 ); 107 } 108 109 public function getPolicy($capability) { 110 switch ($capability) { 111 case PhabricatorPolicyCapability::CAN_VIEW: 112 return PhabricatorPolicies::getMostOpenPolicy(); 113 case PhabricatorPolicyCapability::CAN_EDIT: 114 return $this->getUserPHID(); 115 } 116 } 117 118 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 119 return false; 120 } 121 122 public function describeAutomaticCapability($capability) { 123 return null; 124 } 125 126 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |