3 final class PhabricatorFileImageMacro
extends PhabricatorFileDAO
5 PhabricatorSubscribableInterface
,
6 PhabricatorApplicationTransactionInterface
,
7 PhabricatorFlaggableInterface
,
8 PhabricatorTokenReceiverInterface
,
9 PhabricatorPolicyInterface
{
11 protected $authorPHID;
14 protected $isDisabled = 0;
16 protected $audioBehavior = self
::AUDIO_BEHAVIOR_NONE
;
19 private $file = self
::ATTACHABLE
;
20 private $audio = self
::ATTACHABLE
;
22 const AUDIO_BEHAVIOR_NONE
= 'audio:none';
23 const AUDIO_BEHAVIOR_ONCE
= 'audio:once';
24 const AUDIO_BEHAVIOR_LOOP
= 'audio:loop';
26 public function attachFile(PhabricatorFile
$file) {
31 public function getFile() {
32 return $this->assertAttached($this->file
);
35 public function attachAudio(PhabricatorFile
$audio = null) {
36 $this->audio
= $audio;
40 public function getAudio() {
41 return $this->assertAttached($this->audio
);
44 public static function initializeNewFileImageMacro(PhabricatorUser
$actor) {
45 $macro = id(new self())
46 ->setAuthorPHID($actor->getPHID());
50 protected function getConfiguration() {
52 self
::CONFIG_AUX_PHID
=> true,
53 self
::CONFIG_COLUMN_SCHEMA
=> array(
55 'authorPHID' => 'phid?',
56 'isDisabled' => 'bool',
57 'audioPHID' => 'phid?',
58 'audioBehavior' => 'text64',
59 'mailKey' => 'bytes20',
61 self
::CONFIG_KEY_SCHEMA
=> array(
63 'columns' => array('name'),
66 'key_disabled' => array(
67 'columns' => array('isDisabled'),
69 'key_dateCreated' => array(
70 'columns' => array('dateCreated'),
73 ) + parent
::getConfiguration();
76 public function generatePHID() {
77 return PhabricatorPHID
::generateNewPHID(
78 PhabricatorMacroMacroPHIDType
::TYPECONST
);
82 public function save() {
83 if (!$this->getMailKey()) {
84 $this->setMailKey(Filesystem
::readRandomCharacters(20));
86 return parent
::save();
89 public function getViewURI() {
90 return '/macro/view/'.$this->getID().'/';
94 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
97 public function getApplicationTransactionEditor() {
98 return new PhabricatorMacroEditor();
101 public function getApplicationTransactionTemplate() {
102 return new PhabricatorMacroTransaction();
106 /* -( PhabricatorSubscribableInterface )----------------------------------- */
109 public function isAutomaticallySubscribed($phid) {
114 /* -( PhabricatorTokenRecevierInterface )---------------------------------- */
117 public function getUsersToNotifyOfTokenGiven() {
119 $this->getAuthorPHID(),
124 /* -( PhabricatorPolicyInterface )----------------------------------------- */
127 public function getCapabilities() {
129 PhabricatorPolicyCapability
::CAN_VIEW
,
130 PhabricatorPolicyCapability
::CAN_EDIT
,
134 public function getPolicy($capability) {
135 switch ($capability) {
136 case PhabricatorPolicyCapability
::CAN_VIEW
:
137 return PhabricatorPolicies
::getMostOpenPolicy();
138 case PhabricatorPolicyCapability
::CAN_EDIT
:
139 $app = PhabricatorApplication
::getByClass(
140 'PhabricatorMacroApplication');
141 return $app->getPolicy(PhabricatorMacroManageCapability
::CAPABILITY
);
145 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {