Path: blob/master/src/applications/macro/storage/PhabricatorFileImageMacro.php
12242 views
<?php12final class PhabricatorFileImageMacro extends PhabricatorFileDAO3implements4PhabricatorSubscribableInterface,5PhabricatorApplicationTransactionInterface,6PhabricatorFlaggableInterface,7PhabricatorTokenReceiverInterface,8PhabricatorPolicyInterface {910protected $authorPHID;11protected $filePHID;12protected $name;13protected $isDisabled = 0;14protected $audioPHID;15protected $audioBehavior = self::AUDIO_BEHAVIOR_NONE;16protected $mailKey;1718private $file = self::ATTACHABLE;19private $audio = self::ATTACHABLE;2021const AUDIO_BEHAVIOR_NONE = 'audio:none';22const AUDIO_BEHAVIOR_ONCE = 'audio:once';23const AUDIO_BEHAVIOR_LOOP = 'audio:loop';2425public function attachFile(PhabricatorFile $file) {26$this->file = $file;27return $this;28}2930public function getFile() {31return $this->assertAttached($this->file);32}3334public function attachAudio(PhabricatorFile $audio = null) {35$this->audio = $audio;36return $this;37}3839public function getAudio() {40return $this->assertAttached($this->audio);41}4243public static function initializeNewFileImageMacro(PhabricatorUser $actor) {44$macro = id(new self())45->setAuthorPHID($actor->getPHID());46return $macro;47}4849protected function getConfiguration() {50return array(51self::CONFIG_AUX_PHID => true,52self::CONFIG_COLUMN_SCHEMA => array(53'name' => 'text128',54'authorPHID' => 'phid?',55'isDisabled' => 'bool',56'audioPHID' => 'phid?',57'audioBehavior' => 'text64',58'mailKey' => 'bytes20',59),60self::CONFIG_KEY_SCHEMA => array(61'name' => array(62'columns' => array('name'),63'unique' => true,64),65'key_disabled' => array(66'columns' => array('isDisabled'),67),68'key_dateCreated' => array(69'columns' => array('dateCreated'),70),71),72) + parent::getConfiguration();73}7475public function generatePHID() {76return PhabricatorPHID::generateNewPHID(77PhabricatorMacroMacroPHIDType::TYPECONST);78}798081public function save() {82if (!$this->getMailKey()) {83$this->setMailKey(Filesystem::readRandomCharacters(20));84}85return parent::save();86}8788public function getViewURI() {89return '/macro/view/'.$this->getID().'/';90}919293/* -( PhabricatorApplicationTransactionInterface )------------------------- */949596public function getApplicationTransactionEditor() {97return new PhabricatorMacroEditor();98}99100public function getApplicationTransactionTemplate() {101return new PhabricatorMacroTransaction();102}103104105/* -( PhabricatorSubscribableInterface )----------------------------------- */106107108public function isAutomaticallySubscribed($phid) {109return false;110}111112113/* -( PhabricatorTokenRecevierInterface )---------------------------------- */114115116public function getUsersToNotifyOfTokenGiven() {117return array(118$this->getAuthorPHID(),119);120}121122123/* -( PhabricatorPolicyInterface )----------------------------------------- */124125126public function getCapabilities() {127return array(128PhabricatorPolicyCapability::CAN_VIEW,129PhabricatorPolicyCapability::CAN_EDIT,130);131}132133public function getPolicy($capability) {134switch ($capability) {135case PhabricatorPolicyCapability::CAN_VIEW:136return PhabricatorPolicies::getMostOpenPolicy();137case PhabricatorPolicyCapability::CAN_EDIT:138$app = PhabricatorApplication::getByClass(139'PhabricatorMacroApplication');140return $app->getPolicy(PhabricatorMacroManageCapability::CAPABILITY);141}142}143144public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {145return false;146}147148}149150151