Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/dashboard/storage/PhabricatorDashboard.php
12242 views
1
<?php
2
3
/**
4
* A collection of dashboard panels with a specific layout.
5
*/
6
final class PhabricatorDashboard extends PhabricatorDashboardDAO
7
implements
8
PhabricatorApplicationTransactionInterface,
9
PhabricatorPolicyInterface,
10
PhabricatorFlaggableInterface,
11
PhabricatorDestructibleInterface,
12
PhabricatorProjectInterface,
13
PhabricatorFulltextInterface,
14
PhabricatorFerretInterface,
15
PhabricatorDashboardPanelContainerInterface {
16
17
protected $name;
18
protected $authorPHID;
19
protected $viewPolicy;
20
protected $editPolicy;
21
protected $status;
22
protected $icon;
23
protected $layoutConfig = array();
24
25
const STATUS_ACTIVE = 'active';
26
const STATUS_ARCHIVED = 'archived';
27
28
private $panelRefList;
29
30
public static function initializeNewDashboard(PhabricatorUser $actor) {
31
return id(new PhabricatorDashboard())
32
->setName('')
33
->setIcon('fa-dashboard')
34
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())
35
->setEditPolicy($actor->getPHID())
36
->setStatus(self::STATUS_ACTIVE)
37
->setAuthorPHID($actor->getPHID());
38
}
39
40
public static function getStatusNameMap() {
41
return array(
42
self::STATUS_ACTIVE => pht('Active'),
43
self::STATUS_ARCHIVED => pht('Archived'),
44
);
45
}
46
47
protected function getConfiguration() {
48
return array(
49
self::CONFIG_AUX_PHID => true,
50
self::CONFIG_SERIALIZATION => array(
51
'layoutConfig' => self::SERIALIZATION_JSON,
52
),
53
self::CONFIG_COLUMN_SCHEMA => array(
54
'name' => 'sort255',
55
'status' => 'text32',
56
'icon' => 'text32',
57
'authorPHID' => 'phid',
58
),
59
) + parent::getConfiguration();
60
}
61
62
public function getPHIDType() {
63
return PhabricatorDashboardDashboardPHIDType::TYPECONST;
64
}
65
66
public function getRawLayoutMode() {
67
$config = $this->getRawLayoutConfig();
68
return idx($config, 'layoutMode');
69
}
70
71
public function setRawLayoutMode($mode) {
72
$config = $this->getRawLayoutConfig();
73
$config['layoutMode'] = $mode;
74
return $this->setRawLayoutConfig($config);
75
}
76
77
public function getRawPanels() {
78
$config = $this->getRawLayoutConfig();
79
return idx($config, 'panels');
80
}
81
82
public function setRawPanels(array $panels) {
83
$config = $this->getRawLayoutConfig();
84
$config['panels'] = $panels;
85
return $this->setRawLayoutConfig($config);
86
}
87
88
private function getRawLayoutConfig() {
89
$config = $this->getLayoutConfig();
90
91
if (!is_array($config)) {
92
$config = array();
93
}
94
95
return $config;
96
}
97
98
private function setRawLayoutConfig(array $config) {
99
// If a cached panel ref list exists, clear it.
100
$this->panelRefList = null;
101
102
return $this->setLayoutConfig($config);
103
}
104
105
public function isArchived() {
106
return ($this->getStatus() == self::STATUS_ARCHIVED);
107
}
108
109
public function getURI() {
110
return urisprintf('/dashboard/view/%d/', $this->getID());
111
}
112
113
public function getObjectName() {
114
return pht('Dashboard %d', $this->getID());
115
}
116
117
public function getPanelRefList() {
118
if (!$this->panelRefList) {
119
$this->panelRefList = $this->newPanelRefList();
120
}
121
return $this->panelRefList;
122
}
123
124
private function newPanelRefList() {
125
$raw_config = $this->getLayoutConfig();
126
return PhabricatorDashboardPanelRefList::newFromDictionary($raw_config);
127
}
128
129
public function getPanelPHIDs() {
130
$ref_list = $this->getPanelRefList();
131
$phids = mpull($ref_list->getPanelRefs(), 'getPanelPHID');
132
return array_unique($phids);
133
}
134
135
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
136
137
138
public function getApplicationTransactionEditor() {
139
return new PhabricatorDashboardTransactionEditor();
140
}
141
142
public function getApplicationTransactionTemplate() {
143
return new PhabricatorDashboardTransaction();
144
}
145
146
147
/* -( PhabricatorPolicyInterface )----------------------------------------- */
148
149
150
public function getCapabilities() {
151
return array(
152
PhabricatorPolicyCapability::CAN_VIEW,
153
PhabricatorPolicyCapability::CAN_EDIT,
154
);
155
}
156
157
public function getPolicy($capability) {
158
switch ($capability) {
159
case PhabricatorPolicyCapability::CAN_VIEW:
160
return $this->getViewPolicy();
161
case PhabricatorPolicyCapability::CAN_EDIT:
162
return $this->getEditPolicy();
163
}
164
}
165
166
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
167
return false;
168
}
169
170
171
/* -( PhabricatorDestructibleInterface )----------------------------------- */
172
173
174
public function destroyObjectPermanently(
175
PhabricatorDestructionEngine $engine) {
176
$this->delete();
177
}
178
179
/* -( PhabricatorDashboardPanelContainerInterface )------------------------ */
180
181
public function getDashboardPanelContainerPanelPHIDs() {
182
return $this->getPanelPHIDs();
183
}
184
185
/* -( PhabricatorFulltextInterface )--------------------------------------- */
186
187
public function newFulltextEngine() {
188
return new PhabricatorDashboardFulltextEngine();
189
}
190
191
/* -( PhabricatorFerretInterface )----------------------------------------- */
192
193
public function newFerretEngine() {
194
return new PhabricatorDashboardFerretEngine();
195
}
196
197
}
198
199