Path: blob/master/src/applications/countdown/storage/PhabricatorCountdown.php
12256 views
<?php12final class PhabricatorCountdown extends PhabricatorCountdownDAO3implements4PhabricatorPolicyInterface,5PhabricatorFlaggableInterface,6PhabricatorSubscribableInterface,7PhabricatorApplicationTransactionInterface,8PhabricatorTokenReceiverInterface,9PhabricatorSpacesInterface,10PhabricatorProjectInterface,11PhabricatorDestructibleInterface,12PhabricatorConduitResultInterface {1314protected $title;15protected $authorPHID;16protected $epoch;17protected $description;18protected $viewPolicy;19protected $editPolicy;20protected $mailKey;21protected $spacePHID;2223public static function initializeNewCountdown(PhabricatorUser $actor) {24$app = id(new PhabricatorApplicationQuery())25->setViewer($actor)26->withClasses(array('PhabricatorCountdownApplication'))27->executeOne();2829$view_policy = $app->getPolicy(30PhabricatorCountdownDefaultViewCapability::CAPABILITY);3132$edit_policy = $app->getPolicy(33PhabricatorCountdownDefaultEditCapability::CAPABILITY);3435return id(new PhabricatorCountdown())36->setAuthorPHID($actor->getPHID())37->setViewPolicy($view_policy)38->setEditPolicy($edit_policy)39->setSpacePHID($actor->getDefaultSpacePHID());40}4142protected function getConfiguration() {43return array(44self::CONFIG_AUX_PHID => true,45self::CONFIG_COLUMN_SCHEMA => array(46'title' => 'text255',47'description' => 'text',48'mailKey' => 'bytes20',49),50self::CONFIG_KEY_SCHEMA => array(51'key_epoch' => array(52'columns' => array('epoch'),53),54'key_author' => array(55'columns' => array('authorPHID', 'epoch'),56),57),58) + parent::getConfiguration();59}6061public function generatePHID() {62return PhabricatorPHID::generateNewPHID(63PhabricatorCountdownCountdownPHIDType::TYPECONST);64}6566public function getMonogram() {67return 'C'.$this->getID();68}6970public function getURI() {71return '/'.$this->getMonogram();72}7374public function save() {75if (!$this->getMailKey()) {76$this->setMailKey(Filesystem::readRandomCharacters(20));77}78return parent::save();79}808182/* -( PhabricatorSubscribableInterface )----------------------------------- */838485public function isAutomaticallySubscribed($phid) {86return ($phid == $this->getAuthorPHID());87}888990/* -( PhabricatorApplicationTransactionInterface )------------------------- */919293public function getApplicationTransactionEditor() {94return new PhabricatorCountdownEditor();95}9697public function getApplicationTransactionTemplate() {98return new PhabricatorCountdownTransaction();99}100101102/* -( PhabricatorTokenReceiverInterface )---------------------------------- */103104105public function getUsersToNotifyOfTokenGiven() {106return array($this->getAuthorPHID());107}108109110/* -( PhabricatorPolicyInterface )----------------------------------------- */111112113public function getCapabilities() {114return array(115PhabricatorPolicyCapability::CAN_VIEW,116PhabricatorPolicyCapability::CAN_EDIT,117);118}119120public function getPolicy($capability) {121switch ($capability) {122case PhabricatorPolicyCapability::CAN_VIEW:123return $this->getViewPolicy();124case PhabricatorPolicyCapability::CAN_EDIT:125return $this->getEditPolicy();126}127}128129public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {130return false;131}132133/* -( PhabricatorSpacesInterface )------------------------------------------- */134135136public function getSpacePHID() {137return $this->spacePHID;138}139140/* -( PhabricatorDestructibleInterface )----------------------------------- */141142143public function destroyObjectPermanently(144PhabricatorDestructionEngine $engine) {145146$this->openTransaction();147$this->delete();148$this->saveTransaction();149}150151/* -( PhabricatorConduitResultInterface )---------------------------------- */152153154public function getFieldSpecificationsForConduit() {155return array(156id(new PhabricatorConduitSearchFieldSpecification())157->setKey('title')158->setType('string')159->setDescription(pht('The title of the countdown.')),160id(new PhabricatorConduitSearchFieldSpecification())161->setKey('description')162->setType('remarkup')163->setDescription(pht('The description of the countdown.')),164id(new PhabricatorConduitSearchFieldSpecification())165->setKey('epoch')166->setType('epoch')167->setDescription(pht('The end date of the countdown.')),168);169}170171public function getFieldValuesForConduit() {172return array(173'title' => $this->getTitle(),174'description' => array(175'raw' => $this->getDescription(),176),177'epoch' => (int)$this->getEpoch(),178);179}180181public function getConduitSearchAttachments() {182return array();183}184185}186187188