Path: blob/master/src/applications/dashboard/storage/PhabricatorDashboard.php
12242 views
<?php12/**3* A collection of dashboard panels with a specific layout.4*/5final class PhabricatorDashboard extends PhabricatorDashboardDAO6implements7PhabricatorApplicationTransactionInterface,8PhabricatorPolicyInterface,9PhabricatorFlaggableInterface,10PhabricatorDestructibleInterface,11PhabricatorProjectInterface,12PhabricatorFulltextInterface,13PhabricatorFerretInterface,14PhabricatorDashboardPanelContainerInterface {1516protected $name;17protected $authorPHID;18protected $viewPolicy;19protected $editPolicy;20protected $status;21protected $icon;22protected $layoutConfig = array();2324const STATUS_ACTIVE = 'active';25const STATUS_ARCHIVED = 'archived';2627private $panelRefList;2829public static function initializeNewDashboard(PhabricatorUser $actor) {30return id(new PhabricatorDashboard())31->setName('')32->setIcon('fa-dashboard')33->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())34->setEditPolicy($actor->getPHID())35->setStatus(self::STATUS_ACTIVE)36->setAuthorPHID($actor->getPHID());37}3839public static function getStatusNameMap() {40return array(41self::STATUS_ACTIVE => pht('Active'),42self::STATUS_ARCHIVED => pht('Archived'),43);44}4546protected function getConfiguration() {47return array(48self::CONFIG_AUX_PHID => true,49self::CONFIG_SERIALIZATION => array(50'layoutConfig' => self::SERIALIZATION_JSON,51),52self::CONFIG_COLUMN_SCHEMA => array(53'name' => 'sort255',54'status' => 'text32',55'icon' => 'text32',56'authorPHID' => 'phid',57),58) + parent::getConfiguration();59}6061public function getPHIDType() {62return PhabricatorDashboardDashboardPHIDType::TYPECONST;63}6465public function getRawLayoutMode() {66$config = $this->getRawLayoutConfig();67return idx($config, 'layoutMode');68}6970public function setRawLayoutMode($mode) {71$config = $this->getRawLayoutConfig();72$config['layoutMode'] = $mode;73return $this->setRawLayoutConfig($config);74}7576public function getRawPanels() {77$config = $this->getRawLayoutConfig();78return idx($config, 'panels');79}8081public function setRawPanels(array $panels) {82$config = $this->getRawLayoutConfig();83$config['panels'] = $panels;84return $this->setRawLayoutConfig($config);85}8687private function getRawLayoutConfig() {88$config = $this->getLayoutConfig();8990if (!is_array($config)) {91$config = array();92}9394return $config;95}9697private function setRawLayoutConfig(array $config) {98// If a cached panel ref list exists, clear it.99$this->panelRefList = null;100101return $this->setLayoutConfig($config);102}103104public function isArchived() {105return ($this->getStatus() == self::STATUS_ARCHIVED);106}107108public function getURI() {109return urisprintf('/dashboard/view/%d/', $this->getID());110}111112public function getObjectName() {113return pht('Dashboard %d', $this->getID());114}115116public function getPanelRefList() {117if (!$this->panelRefList) {118$this->panelRefList = $this->newPanelRefList();119}120return $this->panelRefList;121}122123private function newPanelRefList() {124$raw_config = $this->getLayoutConfig();125return PhabricatorDashboardPanelRefList::newFromDictionary($raw_config);126}127128public function getPanelPHIDs() {129$ref_list = $this->getPanelRefList();130$phids = mpull($ref_list->getPanelRefs(), 'getPanelPHID');131return array_unique($phids);132}133134/* -( PhabricatorApplicationTransactionInterface )------------------------- */135136137public function getApplicationTransactionEditor() {138return new PhabricatorDashboardTransactionEditor();139}140141public function getApplicationTransactionTemplate() {142return new PhabricatorDashboardTransaction();143}144145146/* -( PhabricatorPolicyInterface )----------------------------------------- */147148149public function getCapabilities() {150return array(151PhabricatorPolicyCapability::CAN_VIEW,152PhabricatorPolicyCapability::CAN_EDIT,153);154}155156public function getPolicy($capability) {157switch ($capability) {158case PhabricatorPolicyCapability::CAN_VIEW:159return $this->getViewPolicy();160case PhabricatorPolicyCapability::CAN_EDIT:161return $this->getEditPolicy();162}163}164165public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {166return false;167}168169170/* -( PhabricatorDestructibleInterface )----------------------------------- */171172173public function destroyObjectPermanently(174PhabricatorDestructionEngine $engine) {175$this->delete();176}177178/* -( PhabricatorDashboardPanelContainerInterface )------------------------ */179180public function getDashboardPanelContainerPanelPHIDs() {181return $this->getPanelPHIDs();182}183184/* -( PhabricatorFulltextInterface )--------------------------------------- */185186public function newFulltextEngine() {187return new PhabricatorDashboardFulltextEngine();188}189190/* -( PhabricatorFerretInterface )----------------------------------------- */191192public function newFerretEngine() {193return new PhabricatorDashboardFerretEngine();194}195196}197198199