3 final class PhabricatorCountdown
extends PhabricatorCountdownDAO
5 PhabricatorPolicyInterface
,
6 PhabricatorFlaggableInterface
,
7 PhabricatorSubscribableInterface
,
8 PhabricatorApplicationTransactionInterface
,
9 PhabricatorTokenReceiverInterface
,
10 PhabricatorSpacesInterface
,
11 PhabricatorProjectInterface
,
12 PhabricatorDestructibleInterface
,
13 PhabricatorConduitResultInterface
{
16 protected $authorPHID;
18 protected $description;
19 protected $viewPolicy;
20 protected $editPolicy;
24 public static function initializeNewCountdown(PhabricatorUser
$actor) {
25 $app = id(new PhabricatorApplicationQuery())
27 ->withClasses(array('PhabricatorCountdownApplication'))
30 $view_policy = $app->getPolicy(
31 PhabricatorCountdownDefaultViewCapability
::CAPABILITY
);
33 $edit_policy = $app->getPolicy(
34 PhabricatorCountdownDefaultEditCapability
::CAPABILITY
);
36 return id(new PhabricatorCountdown())
37 ->setAuthorPHID($actor->getPHID())
38 ->setViewPolicy($view_policy)
39 ->setEditPolicy($edit_policy)
40 ->setSpacePHID($actor->getDefaultSpacePHID());
43 protected function getConfiguration() {
45 self
::CONFIG_AUX_PHID
=> true,
46 self
::CONFIG_COLUMN_SCHEMA
=> array(
48 'description' => 'text',
49 'mailKey' => 'bytes20',
51 self
::CONFIG_KEY_SCHEMA
=> array(
53 'columns' => array('epoch'),
55 'key_author' => array(
56 'columns' => array('authorPHID', 'epoch'),
59 ) + parent
::getConfiguration();
62 public function generatePHID() {
63 return PhabricatorPHID
::generateNewPHID(
64 PhabricatorCountdownCountdownPHIDType
::TYPECONST
);
67 public function getMonogram() {
68 return 'C'.$this->getID();
71 public function getURI() {
72 return '/'.$this->getMonogram();
75 public function save() {
76 if (!$this->getMailKey()) {
77 $this->setMailKey(Filesystem
::readRandomCharacters(20));
79 return parent
::save();
83 /* -( PhabricatorSubscribableInterface )----------------------------------- */
86 public function isAutomaticallySubscribed($phid) {
87 return ($phid == $this->getAuthorPHID());
91 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
94 public function getApplicationTransactionEditor() {
95 return new PhabricatorCountdownEditor();
98 public function getApplicationTransactionTemplate() {
99 return new PhabricatorCountdownTransaction();
103 /* -( PhabricatorTokenReceiverInterface )---------------------------------- */
106 public function getUsersToNotifyOfTokenGiven() {
107 return array($this->getAuthorPHID());
111 /* -( PhabricatorPolicyInterface )----------------------------------------- */
114 public function getCapabilities() {
116 PhabricatorPolicyCapability
::CAN_VIEW
,
117 PhabricatorPolicyCapability
::CAN_EDIT
,
121 public function getPolicy($capability) {
122 switch ($capability) {
123 case PhabricatorPolicyCapability
::CAN_VIEW
:
124 return $this->getViewPolicy();
125 case PhabricatorPolicyCapability
::CAN_EDIT
:
126 return $this->getEditPolicy();
130 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
134 /* -( PhabricatorSpacesInterface )------------------------------------------- */
137 public function getSpacePHID() {
138 return $this->spacePHID
;
141 /* -( PhabricatorDestructibleInterface )----------------------------------- */
144 public function destroyObjectPermanently(
145 PhabricatorDestructionEngine
$engine) {
147 $this->openTransaction();
149 $this->saveTransaction();
152 /* -( PhabricatorConduitResultInterface )---------------------------------- */
155 public function getFieldSpecificationsForConduit() {
157 id(new PhabricatorConduitSearchFieldSpecification())
160 ->setDescription(pht('The title of the countdown.')),
161 id(new PhabricatorConduitSearchFieldSpecification())
162 ->setKey('description')
163 ->setType('remarkup')
164 ->setDescription(pht('The description of the countdown.')),
165 id(new PhabricatorConduitSearchFieldSpecification())
168 ->setDescription(pht('The end date of the countdown.')),
172 public function getFieldValuesForConduit() {
174 'title' => $this->getTitle(),
175 'description' => array(
176 'raw' => $this->getDescription(),
178 'epoch' => (int)$this->getEpoch(),
182 public function getConduitSearchAttachments() {