4 * A collection of dashboard panels with a specific layout.
6 final class PhabricatorDashboard
extends PhabricatorDashboardDAO
8 PhabricatorApplicationTransactionInterface
,
9 PhabricatorPolicyInterface
,
10 PhabricatorFlaggableInterface
,
11 PhabricatorDestructibleInterface
,
12 PhabricatorProjectInterface
,
13 PhabricatorFulltextInterface
,
14 PhabricatorFerretInterface
,
15 PhabricatorDashboardPanelContainerInterface
{
18 protected $authorPHID;
19 protected $viewPolicy;
20 protected $editPolicy;
23 protected $layoutConfig = array();
25 const STATUS_ACTIVE
= 'active';
26 const STATUS_ARCHIVED
= 'archived';
28 private $panelRefList;
30 public static function initializeNewDashboard(PhabricatorUser
$actor) {
31 return id(new PhabricatorDashboard())
33 ->setIcon('fa-dashboard')
34 ->setViewPolicy(PhabricatorPolicies
::getMostOpenPolicy())
35 ->setEditPolicy($actor->getPHID())
36 ->setStatus(self
::STATUS_ACTIVE
)
37 ->setAuthorPHID($actor->getPHID());
40 public static function getStatusNameMap() {
42 self
::STATUS_ACTIVE
=> pht('Active'),
43 self
::STATUS_ARCHIVED
=> pht('Archived'),
47 protected function getConfiguration() {
49 self
::CONFIG_AUX_PHID
=> true,
50 self
::CONFIG_SERIALIZATION
=> array(
51 'layoutConfig' => self
::SERIALIZATION_JSON
,
53 self
::CONFIG_COLUMN_SCHEMA
=> array(
57 'authorPHID' => 'phid',
59 ) + parent
::getConfiguration();
62 public function getPHIDType() {
63 return PhabricatorDashboardDashboardPHIDType
::TYPECONST
;
66 public function getRawLayoutMode() {
67 $config = $this->getRawLayoutConfig();
68 return idx($config, 'layoutMode');
71 public function setRawLayoutMode($mode) {
72 $config = $this->getRawLayoutConfig();
73 $config['layoutMode'] = $mode;
74 return $this->setRawLayoutConfig($config);
77 public function getRawPanels() {
78 $config = $this->getRawLayoutConfig();
79 return idx($config, 'panels');
82 public function setRawPanels(array $panels) {
83 $config = $this->getRawLayoutConfig();
84 $config['panels'] = $panels;
85 return $this->setRawLayoutConfig($config);
88 private function getRawLayoutConfig() {
89 $config = $this->getLayoutConfig();
91 if (!is_array($config)) {
98 private function setRawLayoutConfig(array $config) {
99 // If a cached panel ref list exists, clear it.
100 $this->panelRefList
= null;
102 return $this->setLayoutConfig($config);
105 public function isArchived() {
106 return ($this->getStatus() == self
::STATUS_ARCHIVED
);
109 public function getURI() {
110 return urisprintf('/dashboard/view/%d/', $this->getID());
113 public function getObjectName() {
114 return pht('Dashboard %d', $this->getID());
117 public function getPanelRefList() {
118 if (!$this->panelRefList
) {
119 $this->panelRefList
= $this->newPanelRefList();
121 return $this->panelRefList
;
124 private function newPanelRefList() {
125 $raw_config = $this->getLayoutConfig();
126 return PhabricatorDashboardPanelRefList
::newFromDictionary($raw_config);
129 public function getPanelPHIDs() {
130 $ref_list = $this->getPanelRefList();
131 $phids = mpull($ref_list->getPanelRefs(), 'getPanelPHID');
132 return array_unique($phids);
135 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
138 public function getApplicationTransactionEditor() {
139 return new PhabricatorDashboardTransactionEditor();
142 public function getApplicationTransactionTemplate() {
143 return new PhabricatorDashboardTransaction();
147 /* -( PhabricatorPolicyInterface )----------------------------------------- */
150 public function getCapabilities() {
152 PhabricatorPolicyCapability
::CAN_VIEW
,
153 PhabricatorPolicyCapability
::CAN_EDIT
,
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();
166 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
171 /* -( PhabricatorDestructibleInterface )----------------------------------- */
174 public function destroyObjectPermanently(
175 PhabricatorDestructionEngine
$engine) {
179 /* -( PhabricatorDashboardPanelContainerInterface )------------------------ */
181 public function getDashboardPanelContainerPanelPHIDs() {
182 return $this->getPanelPHIDs();
185 /* -( PhabricatorFulltextInterface )--------------------------------------- */
187 public function newFulltextEngine() {
188 return new PhabricatorDashboardFulltextEngine();
191 /* -( PhabricatorFerretInterface )----------------------------------------- */
193 public function newFerretEngine() {
194 return new PhabricatorDashboardFerretEngine();