[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/dashboard/storage/ -> PhabricatorDashboard.php (source)

   1  <?php
   2  
   3  /**
   4   * A collection of dashboard panels with a specific layout.
   5   */
   6  final class PhabricatorDashboard extends PhabricatorDashboardDAO
   7    implements
   8      PhabricatorPolicyInterface,
   9      PhabricatorDestructibleInterface {
  10  
  11    protected $name;
  12    protected $viewPolicy;
  13    protected $editPolicy;
  14    protected $layoutConfig = array();
  15  
  16    private $panelPHIDs = self::ATTACHABLE;
  17    private $panels = self::ATTACHABLE;
  18  
  19    public static function initializeNewDashboard(PhabricatorUser $actor) {
  20      return id(new PhabricatorDashboard())
  21        ->setName('')
  22        ->setViewPolicy(PhabricatorPolicies::POLICY_USER)
  23        ->setEditPolicy($actor->getPHID())
  24        ->attachPanels(array())
  25        ->attachPanelPHIDs(array());
  26    }
  27  
  28    public static function copyDashboard(
  29      PhabricatorDashboard $dst,
  30      PhabricatorDashboard $src) {
  31  
  32      $dst->name = $src->name;
  33      $dst->layoutConfig = $src->layoutConfig;
  34  
  35      return $dst;
  36    }
  37  
  38    public function getConfiguration() {
  39      return array(
  40        self::CONFIG_AUX_PHID => true,
  41        self::CONFIG_SERIALIZATION => array(
  42          'layoutConfig' => self::SERIALIZATION_JSON,
  43        ),
  44        self::CONFIG_COLUMN_SCHEMA => array(
  45          'name' => 'text255',
  46        ),
  47      ) + parent::getConfiguration();
  48    }
  49  
  50    public function generatePHID() {
  51      return PhabricatorPHID::generateNewPHID(
  52        PhabricatorDashboardDashboardPHIDType::TYPECONST);
  53    }
  54  
  55    public function getLayoutConfigObject() {
  56      return PhabricatorDashboardLayoutConfig::newFromDictionary(
  57        $this->getLayoutConfig());
  58    }
  59  
  60    public function setLayoutConfigFromObject(
  61      PhabricatorDashboardLayoutConfig $object) {
  62      $this->setLayoutConfig($object->toDictionary());
  63      return $this;
  64    }
  65  
  66    public function attachPanelPHIDs(array $phids) {
  67      $this->panelPHIDs = $phids;
  68      return $this;
  69    }
  70  
  71    public function getPanelPHIDs() {
  72      return $this->assertAttached($this->panelPHIDs);
  73    }
  74  
  75    public function attachPanels(array $panels) {
  76      assert_instances_of($panels, 'PhabricatorDashboardPanel');
  77      $this->panels = $panels;
  78      return $this;
  79    }
  80  
  81    public function getPanels() {
  82      return $this->assertAttached($this->panels);
  83    }
  84  
  85  
  86  /* -(  PhabricatorPolicyInterface  )----------------------------------------- */
  87  
  88  
  89    public function getCapabilities() {
  90      return array(
  91        PhabricatorPolicyCapability::CAN_VIEW,
  92        PhabricatorPolicyCapability::CAN_EDIT,
  93      );
  94    }
  95  
  96    public function getPolicy($capability) {
  97      switch ($capability) {
  98        case PhabricatorPolicyCapability::CAN_VIEW:
  99          return $this->getViewPolicy();
 100        case PhabricatorPolicyCapability::CAN_EDIT:
 101          return $this->getEditPolicy();
 102      }
 103    }
 104  
 105    public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
 106      return false;
 107    }
 108  
 109    public function describeAutomaticCapability($capability) {
 110      return null;
 111    }
 112  
 113  
 114  /* -(  PhabricatorDestructibleInterface  )----------------------------------- */
 115  
 116  
 117    public function destroyObjectPermanently(
 118      PhabricatorDestructionEngine $engine) {
 119  
 120      $this->openTransaction();
 121        $installs = id(new PhabricatorDashboardInstall())->loadAllWhere(
 122          'dashboardPHID = %s',
 123          $this->getPHID());
 124        foreach ($installs as $install) {
 125          $install->delete();
 126        }
 127  
 128        $this->delete();
 129      $this->saveTransaction();
 130    }
 131  
 132  
 133  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1