Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/macro/storage/PhabricatorFileImageMacro.php
12242 views
1
<?php
2
3
final class PhabricatorFileImageMacro extends PhabricatorFileDAO
4
implements
5
PhabricatorSubscribableInterface,
6
PhabricatorApplicationTransactionInterface,
7
PhabricatorFlaggableInterface,
8
PhabricatorTokenReceiverInterface,
9
PhabricatorPolicyInterface {
10
11
protected $authorPHID;
12
protected $filePHID;
13
protected $name;
14
protected $isDisabled = 0;
15
protected $audioPHID;
16
protected $audioBehavior = self::AUDIO_BEHAVIOR_NONE;
17
protected $mailKey;
18
19
private $file = self::ATTACHABLE;
20
private $audio = self::ATTACHABLE;
21
22
const AUDIO_BEHAVIOR_NONE = 'audio:none';
23
const AUDIO_BEHAVIOR_ONCE = 'audio:once';
24
const AUDIO_BEHAVIOR_LOOP = 'audio:loop';
25
26
public function attachFile(PhabricatorFile $file) {
27
$this->file = $file;
28
return $this;
29
}
30
31
public function getFile() {
32
return $this->assertAttached($this->file);
33
}
34
35
public function attachAudio(PhabricatorFile $audio = null) {
36
$this->audio = $audio;
37
return $this;
38
}
39
40
public function getAudio() {
41
return $this->assertAttached($this->audio);
42
}
43
44
public static function initializeNewFileImageMacro(PhabricatorUser $actor) {
45
$macro = id(new self())
46
->setAuthorPHID($actor->getPHID());
47
return $macro;
48
}
49
50
protected function getConfiguration() {
51
return array(
52
self::CONFIG_AUX_PHID => true,
53
self::CONFIG_COLUMN_SCHEMA => array(
54
'name' => 'text128',
55
'authorPHID' => 'phid?',
56
'isDisabled' => 'bool',
57
'audioPHID' => 'phid?',
58
'audioBehavior' => 'text64',
59
'mailKey' => 'bytes20',
60
),
61
self::CONFIG_KEY_SCHEMA => array(
62
'name' => array(
63
'columns' => array('name'),
64
'unique' => true,
65
),
66
'key_disabled' => array(
67
'columns' => array('isDisabled'),
68
),
69
'key_dateCreated' => array(
70
'columns' => array('dateCreated'),
71
),
72
),
73
) + parent::getConfiguration();
74
}
75
76
public function generatePHID() {
77
return PhabricatorPHID::generateNewPHID(
78
PhabricatorMacroMacroPHIDType::TYPECONST);
79
}
80
81
82
public function save() {
83
if (!$this->getMailKey()) {
84
$this->setMailKey(Filesystem::readRandomCharacters(20));
85
}
86
return parent::save();
87
}
88
89
public function getViewURI() {
90
return '/macro/view/'.$this->getID().'/';
91
}
92
93
94
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
95
96
97
public function getApplicationTransactionEditor() {
98
return new PhabricatorMacroEditor();
99
}
100
101
public function getApplicationTransactionTemplate() {
102
return new PhabricatorMacroTransaction();
103
}
104
105
106
/* -( PhabricatorSubscribableInterface )----------------------------------- */
107
108
109
public function isAutomaticallySubscribed($phid) {
110
return false;
111
}
112
113
114
/* -( PhabricatorTokenRecevierInterface )---------------------------------- */
115
116
117
public function getUsersToNotifyOfTokenGiven() {
118
return array(
119
$this->getAuthorPHID(),
120
);
121
}
122
123
124
/* -( PhabricatorPolicyInterface )----------------------------------------- */
125
126
127
public function getCapabilities() {
128
return array(
129
PhabricatorPolicyCapability::CAN_VIEW,
130
PhabricatorPolicyCapability::CAN_EDIT,
131
);
132
}
133
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);
142
}
143
}
144
145
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
146
return false;
147
}
148
149
}
150
151