Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/dashboard/storage/PhabricatorDashboardPanel.php
12242 views
1
<?php
2
3
/**
4
* An individual dashboard panel.
5
*/
6
final class PhabricatorDashboardPanel
7
extends PhabricatorDashboardDAO
8
implements
9
PhabricatorApplicationTransactionInterface,
10
PhabricatorPolicyInterface,
11
PhabricatorFlaggableInterface,
12
PhabricatorDestructibleInterface,
13
PhabricatorFulltextInterface,
14
PhabricatorFerretInterface,
15
PhabricatorDashboardPanelContainerInterface {
16
17
protected $name;
18
protected $panelType;
19
protected $viewPolicy;
20
protected $editPolicy;
21
protected $authorPHID;
22
protected $isArchived = 0;
23
protected $properties = array();
24
25
public static function initializeNewPanel(PhabricatorUser $actor) {
26
return id(new PhabricatorDashboardPanel())
27
->setName('')
28
->setAuthorPHID($actor->getPHID())
29
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())
30
->setEditPolicy($actor->getPHID());
31
}
32
33
protected function getConfiguration() {
34
return array(
35
self::CONFIG_AUX_PHID => true,
36
self::CONFIG_SERIALIZATION => array(
37
'properties' => self::SERIALIZATION_JSON,
38
),
39
self::CONFIG_COLUMN_SCHEMA => array(
40
'name' => 'sort255',
41
'panelType' => 'text64',
42
'authorPHID' => 'phid',
43
'isArchived' => 'bool',
44
),
45
) + parent::getConfiguration();
46
}
47
48
public function getPHIDType() {
49
return PhabricatorDashboardPanelPHIDType::TYPECONST;
50
}
51
52
public function getProperty($key, $default = null) {
53
return idx($this->properties, $key, $default);
54
}
55
56
public function setProperty($key, $value) {
57
$this->properties[$key] = $value;
58
return $this;
59
}
60
61
public function getMonogram() {
62
return 'W'.$this->getID();
63
}
64
65
public function getURI() {
66
return '/'.$this->getMonogram();
67
}
68
69
public function getPanelTypes() {
70
$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes();
71
$panel_types = mpull($panel_types, 'getPanelTypeName', 'getPanelTypeKey');
72
asort($panel_types);
73
$panel_types = (array('' => pht('(All Types)')) + $panel_types);
74
return $panel_types;
75
}
76
77
public function getStatuses() {
78
$statuses =
79
array(
80
'' => pht('(All Panels)'),
81
'active' => pht('Active Panels'),
82
'archived' => pht('Archived Panels'),
83
);
84
return $statuses;
85
}
86
87
public function getImplementation() {
88
return idx(
89
PhabricatorDashboardPanelType::getAllPanelTypes(),
90
$this->getPanelType());
91
}
92
93
public function requireImplementation() {
94
$impl = $this->getImplementation();
95
if (!$impl) {
96
throw new Exception(
97
pht(
98
'Attempting to use a panel in a way that requires an '.
99
'implementation, but the panel implementation ("%s") is unknown.',
100
$this->getPanelType()));
101
}
102
return $impl;
103
}
104
105
public function getEditEngineFields() {
106
return $this->requireImplementation()->getEditEngineFields($this);
107
}
108
109
public function newHeaderEditActions(
110
PhabricatorUser $viewer,
111
$context_phid) {
112
return $this->requireImplementation()->newHeaderEditActions(
113
$this,
114
$viewer,
115
$context_phid);
116
}
117
118
119
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
120
121
122
public function getApplicationTransactionEditor() {
123
return new PhabricatorDashboardPanelTransactionEditor();
124
}
125
126
public function getApplicationTransactionTemplate() {
127
return new PhabricatorDashboardPanelTransaction();
128
}
129
130
131
/* -( PhabricatorPolicyInterface )----------------------------------------- */
132
133
134
public function getCapabilities() {
135
return array(
136
PhabricatorPolicyCapability::CAN_VIEW,
137
PhabricatorPolicyCapability::CAN_EDIT,
138
);
139
}
140
141
public function getPolicy($capability) {
142
switch ($capability) {
143
case PhabricatorPolicyCapability::CAN_VIEW:
144
return $this->getViewPolicy();
145
case PhabricatorPolicyCapability::CAN_EDIT:
146
return $this->getEditPolicy();
147
}
148
}
149
150
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
151
return false;
152
}
153
154
155
/* -( PhabricatorDestructibleInterface )----------------------------------- */
156
157
158
public function destroyObjectPermanently(
159
PhabricatorDestructionEngine $engine) {
160
161
$this->openTransaction();
162
$this->delete();
163
$this->saveTransaction();
164
}
165
166
/* -( PhabricatorDashboardPanelContainerInterface )------------------------ */
167
168
public function getDashboardPanelContainerPanelPHIDs() {
169
return $this->requireImplementation()->getSubpanelPHIDs($this);
170
}
171
172
/* -( PhabricatorFulltextInterface )--------------------------------------- */
173
174
public function newFulltextEngine() {
175
return new PhabricatorDashboardPanelFulltextEngine();
176
}
177
178
/* -( PhabricatorFerretInterface )----------------------------------------- */
179
180
public function newFerretEngine() {
181
return new PhabricatorDashboardPanelFerretEngine();
182
}
183
184
}
185
186