Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/engine/PhabricatorBoardResponseEngine.php
| <?php | <?php | ||||
| final class PhabricatorBoardResponseEngine extends Phobject { | final class PhabricatorBoardResponseEngine extends Phobject { | ||||
| private $viewer; | private $viewer; | ||||
| private $objects; | |||||
| private $boardPHID; | private $boardPHID; | ||||
| private $objectPHID; | private $visiblePHIDs = array(); | ||||
| private $visiblePHIDs; | |||||
| private $updatePHIDs = array(); | private $updatePHIDs = array(); | ||||
| private $ordering; | private $ordering; | ||||
| private $sounds; | private $sounds; | ||||
| public function setViewer(PhabricatorUser $viewer) { | public function setViewer(PhabricatorUser $viewer) { | ||||
| $this->viewer = $viewer; | $this->viewer = $viewer; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getViewer() { | public function getViewer() { | ||||
| return $this->viewer; | return $this->viewer; | ||||
| } | } | ||||
| public function setBoardPHID($board_phid) { | public function setBoardPHID($board_phid) { | ||||
| $this->boardPHID = $board_phid; | $this->boardPHID = $board_phid; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getBoardPHID() { | public function getBoardPHID() { | ||||
| return $this->boardPHID; | return $this->boardPHID; | ||||
| } | } | ||||
| public function setObjectPHID($object_phid) { | public function setObjects(array $objects) { | ||||
| $this->objectPHID = $object_phid; | $this->objects = $objects; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getObjectPHID() { | public function getObjects() { | ||||
| return $this->objectPHID; | return $this->objects; | ||||
| } | } | ||||
| public function setVisiblePHIDs(array $visible_phids) { | public function setVisiblePHIDs(array $visible_phids) { | ||||
| $this->visiblePHIDs = $visible_phids; | $this->visiblePHIDs = $visible_phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getVisiblePHIDs() { | public function getVisiblePHIDs() { | ||||
| Show All 24 Lines | final class PhabricatorBoardResponseEngine extends Phobject { | ||||
| } | } | ||||
| public function getSounds() { | public function getSounds() { | ||||
| return $this->sounds; | return $this->sounds; | ||||
| } | } | ||||
| public function buildResponse() { | public function buildResponse() { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $object_phid = $this->getObjectPHID(); | |||||
| $board_phid = $this->getBoardPHID(); | $board_phid = $this->getBoardPHID(); | ||||
| $ordering = $this->getOrdering(); | $ordering = $this->getOrdering(); | ||||
| $update_phids = $this->getUpdatePHIDs(); | |||||
| $update_phids = array_fuse($update_phids); | |||||
| $visible_phids = $this->getVisiblePHIDs(); | |||||
| $visible_phids = array_fuse($visible_phids); | |||||
| $all_phids = $update_phids + $visible_phids; | |||||
| // Load all the other tasks that are visible in the affected columns and | // Load all the other tasks that are visible in the affected columns and | ||||
| // perform layout for them. | // perform layout for them. | ||||
| $all_phids = $this->getAllVisiblePHIDs(); | |||||
| if ($this->objects !== null) { | |||||
| $all_objects = $this->getObjects(); | |||||
| $all_objects = mpull($all_objects, null, 'getPHID'); | |||||
| } else { | |||||
| $all_objects = id(new ManiphestTaskQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withPHIDs($all_phids) | |||||
| ->execute(); | |||||
| $all_objects = mpull($all_objects, null, 'getPHID'); | |||||
| } | |||||
| $layout_engine = id(new PhabricatorBoardLayoutEngine()) | $layout_engine = id(new PhabricatorBoardLayoutEngine()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->setBoardPHIDs(array($board_phid)) | ->setBoardPHIDs(array($board_phid)) | ||||
| ->setObjectPHIDs($all_phids) | ->setObjectPHIDs($all_phids) | ||||
| ->executeLayout(); | ->executeLayout(); | ||||
| $natural = array(); | $natural = array(); | ||||
| $update_phids = $this->getAllUpdatePHIDs(); | |||||
| $update_columns = array(); | $update_columns = array(); | ||||
| foreach ($update_phids as $update_phid) { | foreach ($update_phids as $update_phid) { | ||||
| $update_columns += $layout_engine->getObjectColumns( | $update_columns += $layout_engine->getObjectColumns( | ||||
| $board_phid, | $board_phid, | ||||
| $update_phid); | $update_phid); | ||||
| } | } | ||||
| foreach ($update_columns as $column_phid => $column) { | foreach ($update_columns as $column_phid => $column) { | ||||
| $column_object_phids = $layout_engine->getColumnObjectPHIDs( | $column_object_phids = $layout_engine->getColumnObjectPHIDs( | ||||
| $board_phid, | $board_phid, | ||||
| $column_phid); | $column_phid); | ||||
| $natural[$column_phid] = array_values($column_object_phids); | $natural[$column_phid] = array_values($column_object_phids); | ||||
| } | } | ||||
| $all_objects = id(new ManiphestTaskQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withPHIDs($all_phids) | |||||
| ->execute(); | |||||
| $all_objects = mpull($all_objects, null, 'getPHID'); | |||||
| if ($ordering) { | if ($ordering) { | ||||
| $vectors = $ordering->getSortVectorsForObjects($all_objects); | $vectors = $ordering->getSortVectorsForObjects($all_objects); | ||||
| $header_keys = $ordering->getHeaderKeysForObjects($all_objects); | $header_keys = $ordering->getHeaderKeysForObjects($all_objects); | ||||
| $headers = $ordering->getHeadersForObjects($all_objects); | $headers = $ordering->getHeadersForObjects($all_objects); | ||||
| $headers = mpull($headers, 'toDictionary'); | $headers = mpull($headers, 'toDictionary'); | ||||
| } else { | } else { | ||||
| $vectors = array(); | $vectors = array(); | ||||
| $header_keys = array(); | $header_keys = array(); | ||||
| Show All 36 Lines | foreach ($all_objects as $card_phid => $object) { | ||||
| $card['vectors'] = (object)$card['vectors']; | $card['vectors'] = (object)$card['vectors']; | ||||
| $card['headers'] = (object)$card['headers']; | $card['headers'] = (object)$card['headers']; | ||||
| $card['properties'] = (object)$card['properties']; | $card['properties'] = (object)$card['properties']; | ||||
| $cards[$card_phid] = $card; | $cards[$card_phid] = $card; | ||||
| } | } | ||||
| // Mark cards which are currently visible on the client but not visible | |||||
| // on the board on the server for removal from the client view of the | |||||
| // board state. | |||||
| foreach ($visible_phids as $card_phid) { | |||||
| if (!isset($cards[$card_phid])) { | |||||
| $cards[$card_phid] = array( | |||||
| 'remove' => true, | |||||
| ); | |||||
| } | |||||
| } | |||||
| $payload = array( | $payload = array( | ||||
| 'columnMaps' => $natural, | 'columnMaps' => $natural, | ||||
| 'cards' => $cards, | 'cards' => $cards, | ||||
| 'headers' => $headers, | 'headers' => $headers, | ||||
| 'sounds' => $this->getSounds(), | 'sounds' => $this->getSounds(), | ||||
| ); | ); | ||||
| return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
| Show All 22 Lines | private function loadExcludedProjectPHIDs() { | ||||
| foreach ($descendants as $descendant) { | foreach ($descendants as $descendant) { | ||||
| $exclude_phids[] = $descendant->getPHID(); | $exclude_phids[] = $descendant->getPHID(); | ||||
| } | } | ||||
| return array_fuse($exclude_phids); | return array_fuse($exclude_phids); | ||||
| } | } | ||||
| private function getAllVisiblePHIDs() { | |||||
| $phids = $this->getAllUpdatePHIDs(); | |||||
| foreach ($this->getVisiblePHIDs() as $phid) { | |||||
| $phids[] = $phid; | |||||
| } | |||||
| $phids = array_fuse($phids); | |||||
| return $phids; | |||||
| } | |||||
| private function getAllUpdatePHIDs() { | |||||
| $phids = $this->getUpdatePHIDs(); | |||||
| $object_phid = $this->getObjectPHID(); | |||||
| if ($object_phid) { | |||||
| $phids[] = $object_phid; | |||||
| } | |||||
| $phids = array_fuse($phids); | |||||
| return $phids; | |||||
| } | |||||
| private function newCardTemplates() { | private function newCardTemplates() { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $update_phids = $this->getAllUpdatePHIDs(); | $update_phids = $this->getUpdatePHIDs(); | ||||
| if (!$update_phids) { | if (!$update_phids) { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| $update_phids = array_fuse($update_phids); | |||||
| if ($this->objects === null) { | |||||
| $objects = id(new ManiphestTaskQuery()) | $objects = id(new ManiphestTaskQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withPHIDs($update_phids) | ->withPHIDs($update_phids) | ||||
| ->needProjectPHIDs(true) | ->needProjectPHIDs(true) | ||||
| ->execute(); | ->execute(); | ||||
| } else { | |||||
| $objects = $this->getObjects(); | |||||
| $objects = mpull($objects, null, 'getPHID'); | |||||
| $objects = array_select_keys($objects, $update_phids); | |||||
| } | |||||
| if (!$objects) { | if (!$objects) { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| $excluded_phids = $this->loadExcludedProjectPHIDs(); | $excluded_phids = $this->loadExcludedProjectPHIDs(); | ||||
| $rendering_engine = id(new PhabricatorBoardRenderingEngine()) | $rendering_engine = id(new PhabricatorBoardRenderingEngine()) | ||||
| Show All 19 Lines | |||||