Path: blob/master/src/applications/dashboard/storage/PhabricatorDashboardPanel.php
12242 views
<?php12/**3* An individual dashboard panel.4*/5final class PhabricatorDashboardPanel6extends PhabricatorDashboardDAO7implements8PhabricatorApplicationTransactionInterface,9PhabricatorPolicyInterface,10PhabricatorFlaggableInterface,11PhabricatorDestructibleInterface,12PhabricatorFulltextInterface,13PhabricatorFerretInterface,14PhabricatorDashboardPanelContainerInterface {1516protected $name;17protected $panelType;18protected $viewPolicy;19protected $editPolicy;20protected $authorPHID;21protected $isArchived = 0;22protected $properties = array();2324public static function initializeNewPanel(PhabricatorUser $actor) {25return id(new PhabricatorDashboardPanel())26->setName('')27->setAuthorPHID($actor->getPHID())28->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())29->setEditPolicy($actor->getPHID());30}3132protected function getConfiguration() {33return array(34self::CONFIG_AUX_PHID => true,35self::CONFIG_SERIALIZATION => array(36'properties' => self::SERIALIZATION_JSON,37),38self::CONFIG_COLUMN_SCHEMA => array(39'name' => 'sort255',40'panelType' => 'text64',41'authorPHID' => 'phid',42'isArchived' => 'bool',43),44) + parent::getConfiguration();45}4647public function getPHIDType() {48return PhabricatorDashboardPanelPHIDType::TYPECONST;49}5051public function getProperty($key, $default = null) {52return idx($this->properties, $key, $default);53}5455public function setProperty($key, $value) {56$this->properties[$key] = $value;57return $this;58}5960public function getMonogram() {61return 'W'.$this->getID();62}6364public function getURI() {65return '/'.$this->getMonogram();66}6768public function getPanelTypes() {69$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes();70$panel_types = mpull($panel_types, 'getPanelTypeName', 'getPanelTypeKey');71asort($panel_types);72$panel_types = (array('' => pht('(All Types)')) + $panel_types);73return $panel_types;74}7576public function getStatuses() {77$statuses =78array(79'' => pht('(All Panels)'),80'active' => pht('Active Panels'),81'archived' => pht('Archived Panels'),82);83return $statuses;84}8586public function getImplementation() {87return idx(88PhabricatorDashboardPanelType::getAllPanelTypes(),89$this->getPanelType());90}9192public function requireImplementation() {93$impl = $this->getImplementation();94if (!$impl) {95throw new Exception(96pht(97'Attempting to use a panel in a way that requires an '.98'implementation, but the panel implementation ("%s") is unknown.',99$this->getPanelType()));100}101return $impl;102}103104public function getEditEngineFields() {105return $this->requireImplementation()->getEditEngineFields($this);106}107108public function newHeaderEditActions(109PhabricatorUser $viewer,110$context_phid) {111return $this->requireImplementation()->newHeaderEditActions(112$this,113$viewer,114$context_phid);115}116117118/* -( PhabricatorApplicationTransactionInterface )------------------------- */119120121public function getApplicationTransactionEditor() {122return new PhabricatorDashboardPanelTransactionEditor();123}124125public function getApplicationTransactionTemplate() {126return new PhabricatorDashboardPanelTransaction();127}128129130/* -( PhabricatorPolicyInterface )----------------------------------------- */131132133public function getCapabilities() {134return array(135PhabricatorPolicyCapability::CAN_VIEW,136PhabricatorPolicyCapability::CAN_EDIT,137);138}139140public function getPolicy($capability) {141switch ($capability) {142case PhabricatorPolicyCapability::CAN_VIEW:143return $this->getViewPolicy();144case PhabricatorPolicyCapability::CAN_EDIT:145return $this->getEditPolicy();146}147}148149public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {150return false;151}152153154/* -( PhabricatorDestructibleInterface )----------------------------------- */155156157public function destroyObjectPermanently(158PhabricatorDestructionEngine $engine) {159160$this->openTransaction();161$this->delete();162$this->saveTransaction();163}164165/* -( PhabricatorDashboardPanelContainerInterface )------------------------ */166167public function getDashboardPanelContainerPanelPHIDs() {168return $this->requireImplementation()->getSubpanelPHIDs($this);169}170171/* -( PhabricatorFulltextInterface )--------------------------------------- */172173public function newFulltextEngine() {174return new PhabricatorDashboardPanelFulltextEngine();175}176177/* -( PhabricatorFerretInterface )----------------------------------------- */178179public function newFerretEngine() {180return new PhabricatorDashboardPanelFerretEngine();181}182183}184185186