[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/dashboard/layoutconfig/ -> PhabricatorDashboardLayoutConfig.php (source)

   1  <?php
   2  
   3  final class PhabricatorDashboardLayoutConfig {
   4  
   5    const MODE_FULL                = 'layout-mode-full';
   6    const MODE_HALF_AND_HALF       = 'layout-mode-half-and-half';
   7    const MODE_THIRD_AND_THIRDS    = 'layout-mode-third-and-thirds';
   8    const MODE_THIRDS_AND_THIRD    = 'layout-mode-thirds-and-third';
   9  
  10    private $layoutMode     = self::MODE_FULL;
  11    private $panelLocations = array();
  12  
  13    public function setLayoutMode($mode) {
  14      $this->layoutMode = $mode;
  15      return $this;
  16    }
  17    public function getLayoutMode() {
  18      return $this->layoutMode;
  19    }
  20  
  21    public function setPanelLocation($which_column, $panel_phid) {
  22      $this->panelLocations[$which_column][] = $panel_phid;
  23      return $this;
  24    }
  25  
  26    public function setPanelLocations(array $locations) {
  27      $this->panelLocations = $locations;
  28      return $this;
  29    }
  30  
  31    public function getPanelLocations() {
  32      return $this->panelLocations;
  33    }
  34  
  35    public function replacePanel($old_phid, $new_phid) {
  36      $locations = $this->getPanelLocations();
  37      foreach ($locations as $column => $panel_phids) {
  38        foreach ($panel_phids as $key => $panel_phid) {
  39          if ($panel_phid == $old_phid) {
  40            $locations[$column][$key] = $new_phid;
  41          }
  42        }
  43      }
  44      return $this->setPanelLocations($locations);
  45    }
  46  
  47    public function removePanel($panel_phid) {
  48      $panel_location_grid = $this->getPanelLocations();
  49      foreach ($panel_location_grid as $column => $panel_columns) {
  50        $found_old_column = array_search($panel_phid, $panel_columns);
  51        if ($found_old_column !== false) {
  52          $new_panel_columns = $panel_columns;
  53          array_splice(
  54            $new_panel_columns,
  55            $found_old_column,
  56            1,
  57            array());
  58          $panel_location_grid[$column] = $new_panel_columns;
  59          break;
  60        }
  61      }
  62      $this->setPanelLocations($panel_location_grid);
  63    }
  64  
  65    public function getDefaultPanelLocations() {
  66      switch ($this->getLayoutMode()) {
  67        case self::MODE_HALF_AND_HALF:
  68        case self::MODE_THIRD_AND_THIRDS:
  69        case self::MODE_THIRDS_AND_THIRD:
  70          $locations = array(array(), array());
  71          break;
  72        case self::MODE_FULL:
  73        default:
  74          $locations = array(array());
  75          break;
  76      }
  77      return $locations;
  78    }
  79  
  80    public function getColumnClass($column_index, $grippable = false) {
  81      switch ($this->getLayoutMode()) {
  82        case self::MODE_HALF_AND_HALF:
  83          $class = 'half';
  84          break;
  85        case self::MODE_THIRD_AND_THIRDS:
  86          if ($column_index) {
  87            $class = 'thirds';
  88          } else {
  89            $class = 'third';
  90          }
  91          break;
  92        case self::MODE_THIRDS_AND_THIRD:
  93          if ($column_index) {
  94            $class = 'third';
  95          } else {
  96            $class = 'thirds';
  97          }
  98          break;
  99        case self::MODE_FULL:
 100        default:
 101          $class = null;
 102          break;
 103      }
 104      if ($grippable) {
 105        $class .= ' grippable';
 106      }
 107      return $class;
 108    }
 109  
 110    public function isMultiColumnLayout() {
 111      return $this->getLayoutMode() != self::MODE_FULL;
 112    }
 113  
 114    public function getColumnSelectOptions() {
 115      $options = array();
 116  
 117      switch ($this->getLayoutMode()) {
 118        case self::MODE_HALF_AND_HALF:
 119        case self::MODE_THIRD_AND_THIRDS:
 120        case self::MODE_THIRDS_AND_THIRD:
 121          return array(
 122            0 => pht('Left'),
 123            1 => pht('Right'),
 124          );
 125          break;
 126        case self::MODE_FULL:
 127          throw new Exception('There is only one column in mode full.');
 128          break;
 129        default:
 130          throw new Exception('Unknown layout mode!');
 131          break;
 132      }
 133  
 134      return $options;
 135    }
 136  
 137    public static function getLayoutModeSelectOptions() {
 138      return array(
 139        self::MODE_FULL             => pht('One full-width column'),
 140        self::MODE_HALF_AND_HALF    => pht('Two columns, 1/2 and 1/2'),
 141        self::MODE_THIRD_AND_THIRDS => pht('Two columns, 1/3 and 2/3'),
 142        self::MODE_THIRDS_AND_THIRD => pht('Two columns, 2/3 and 1/3'),
 143      );
 144    }
 145  
 146    public static function newFromDictionary(array $dict) {
 147      $layout_config = id(new PhabricatorDashboardLayoutConfig())
 148        ->setLayoutMode(idx($dict, 'layoutMode', self::MODE_FULL));
 149      $layout_config->setPanelLocations(idx(
 150        $dict,
 151        'panelLocations',
 152        $layout_config->getDefaultPanelLocations()));
 153  
 154      return $layout_config;
 155    }
 156  
 157    public function toDictionary() {
 158      return array(
 159        'layoutMode' => $this->getLayoutMode(),
 160        'panelLocations' => $this->getPanelLocations(),
 161      );
 162    }
 163  
 164  }


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