Path: blob/master/src/applications/dashboard/layoutconfig/PhabricatorDashboardPanelRefList.php
13444 views
<?php12final class PhabricatorDashboardPanelRefList3extends Phobject {45private $refs;6private $columns;78public static function newFromDictionary($config) {9if (!is_array($config)) {10$config = array();11}1213$mode_map = PhabricatorDashboardLayoutMode::getAllLayoutModes();14$mode_key = idx($config, 'layoutMode');15if (!isset($mode_map[$mode_key])) {16$mode_key = head_key($mode_map);17}18$mode = $mode_map[$mode_key];1920$columns = $mode->getLayoutModeColumns();21$columns = mpull($columns, null, 'getColumnKey');22$default_column = head($columns);2324$panels = idx($config, 'panels');25if (!is_array($panels)) {26$panels = array();27}2829$seen_panels = array();30$refs = array();31foreach ($panels as $panel) {32$panel_phid = idx($panel, 'panelPHID');33if (!strlen($panel_phid)) {34continue;35}3637$panel_key = idx($panel, 'panelKey');38if (!strlen($panel_key)) {39continue;40}4142if (isset($seen_panels[$panel_key])) {43continue;44}45$seen_panels[$panel_key] = true;4647$column_key = idx($panel, 'columnKey');48$column = idx($columns, $column_key, $default_column);4950$ref = id(new PhabricatorDashboardPanelRef())51->setPanelPHID($panel_phid)52->setPanelKey($panel_key)53->setColumnKey($column->getColumnKey());5455$column->addPanelRef($ref);56$refs[] = $ref;57}5859$list = new self();6061$list->columns = $columns;62$list->refs = $refs;6364return $list;65}6667public function getColumns() {68return $this->columns;69}7071public function getPanelRefs() {72return $this->refs;73}7475public function getPanelRef($panel_key) {76foreach ($this->getPanelRefs() as $ref) {77if ($ref->getPanelKey() === $panel_key) {78return $ref;79}80}8182return null;83}8485public function toDictionary() {86return array_values(mpull($this->getPanelRefs(), 'toDictionary'));87}8889public function newPanelRef(90PhabricatorDashboardPanel $panel,91$column_key = null) {9293if ($column_key === null) {94$column_key = head_key($this->columns);95}9697$ref = id(new PhabricatorDashboardPanelRef())98->setPanelKey($this->newPanelKey())99->setPanelPHID($panel->getPHID())100->setColumnKey($column_key);101102$this->refs[] = $ref;103104return $ref;105}106107public function removePanelRef(PhabricatorDashboardPanelRef $target) {108foreach ($this->refs as $key => $ref) {109if ($ref->getPanelKey() !== $target->getPanelKey()) {110continue;111}112113unset($this->refs[$key]);114return $ref;115}116117return null;118}119120public function movePanelRef(121PhabricatorDashboardPanelRef $target,122$column_key,123PhabricatorDashboardPanelRef $after = null) {124125$target->setColumnKey($column_key);126127$results = array();128129if (!$after) {130$results[] = $target;131}132133foreach ($this->refs as $ref) {134if ($ref->getPanelKey() === $target->getPanelKey()) {135continue;136}137138$results[] = $ref;139140if ($after) {141if ($ref->getPanelKey() === $after->getPanelKey()) {142$results[] = $target;143}144}145}146147$this->refs = $results;148149$column_map = mgroup($results, 'getColumnKey');150foreach ($this->columns as $column_key => $column) {151$column->setPanelRefs(idx($column_map, $column_key, array()));152}153154return $ref;155}156157private function newPanelKey() {158return Filesystem::readRandomCharacters(8);159}160161162}163164165