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 $boardPHID; | private $boardPHID; | ||||
private $objectPHID; | private $objectPHID; | ||||
private $visiblePHIDs; | private $visiblePHIDs; | ||||
private $ordering; | |||||
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; | ||||
Show All 21 Lines | public function setVisiblePHIDs(array $visible_phids) { | ||||
$this->visiblePHIDs = $visible_phids; | $this->visiblePHIDs = $visible_phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getVisiblePHIDs() { | public function getVisiblePHIDs() { | ||||
return $this->visiblePHIDs; | return $this->visiblePHIDs; | ||||
} | } | ||||
public function setOrdering(PhabricatorProjectColumnOrder $ordering) { | |||||
$this->ordering = $ordering; | |||||
return $this; | |||||
} | |||||
public function getOrdering() { | |||||
return $this->ordering; | |||||
} | |||||
public function buildResponse() { | public function buildResponse() { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$object_phid = $this->getObjectPHID(); | $object_phid = $this->getObjectPHID(); | ||||
$board_phid = $this->getBoardPHID(); | $board_phid = $this->getBoardPHID(); | ||||
$ordering = $this->getOrdering(); | |||||
// 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. | ||||
$visible_phids = $this->getAllVisiblePHIDs(); | $visible_phids = $this->getAllVisiblePHIDs(); | ||||
$layout_engine = id(new PhabricatorBoardLayoutEngine()) | $layout_engine = id(new PhabricatorBoardLayoutEngine()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setBoardPHIDs(array($board_phid)) | ->setBoardPHIDs(array($board_phid)) | ||||
Show All 11 Lines | foreach ($object_columns as $column_phid => $column) { | ||||
$column_phid); | $column_phid); | ||||
$natural[$column_phid] = array_values($column_object_phids); | $natural[$column_phid] = array_values($column_object_phids); | ||||
} | } | ||||
$all_visible = id(new ManiphestTaskQuery()) | $all_visible = id(new ManiphestTaskQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs($visible_phids) | ->withPHIDs($visible_phids) | ||||
->execute(); | ->execute(); | ||||
$all_visible = mpull($all_visible, null, 'getPHID'); | |||||
$order_maps = array(); | if ($ordering) { | ||||
foreach ($all_visible as $visible) { | $vectors = $ordering->getSortVectorsForObjects($all_visible); | ||||
$order_maps[$visible->getPHID()] = $visible->getWorkboardOrderVectors(); | $header_keys = $ordering->getHeaderKeysForObjects($all_visible); | ||||
$headers = $ordering->getHeadersForObjects($all_visible); | |||||
$headers = mpull($headers, 'toDictionary'); | |||||
} else { | |||||
$vectors = array(); | |||||
$header_keys = array(); | |||||
$headers = array(); | |||||
} | } | ||||
$object = id(new ManiphestTaskQuery()) | $object = id(new ManiphestTaskQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($object_phid)) | ->withPHIDs(array($object_phid)) | ||||
->needProjectPHIDs(true) | ->needProjectPHIDs(true) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$object) { | if (!$object) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$template = $this->buildTemplate($object); | $template = $this->buildTemplate($object); | ||||
$cards = array(); | |||||
foreach ($all_visible as $card_phid => $object) { | |||||
$card = array( | |||||
'vectors' => array(), | |||||
'headers' => array(), | |||||
'properties' => array(), | |||||
'nodeHTMLTemplate' => null, | |||||
); | |||||
if ($ordering) { | |||||
$order_key = $ordering->getColumnOrderKey(); | |||||
$vector = idx($vectors, $card_phid); | |||||
if ($vector !== null) { | |||||
$card['vectors'][$order_key] = $vector; | |||||
} | |||||
$header = idx($header_keys, $card_phid); | |||||
if ($header !== null) { | |||||
$card['headers'][$order_key] = $header; | |||||
} | |||||
$card['properties'] = array( | |||||
'points' => (double)$object->getPoints(), | |||||
'status' => $object->getStatus(), | |||||
); | |||||
} | |||||
if ($card_phid === $object_phid) { | |||||
$card['nodeHTMLTemplate'] = hsprintf('%s', $template); | |||||
} | |||||
$card['vectors'] = (object)$card['vectors']; | |||||
$card['headers'] = (object)$card['headers']; | |||||
$card['properties'] = (object)$card['properties']; | |||||
$cards[$card_phid] = $card; | |||||
} | |||||
$payload = array( | $payload = array( | ||||
'objectPHID' => $object_phid, | 'objectPHID' => $object_phid, | ||||
'cardHTML' => $template, | |||||
'columnMaps' => $natural, | 'columnMaps' => $natural, | ||||
'orderMaps' => $order_maps, | 'cards' => $cards, | ||||
'propertyMaps' => array( | 'headers' => $headers, | ||||
$object_phid => $object->getWorkboardProperties(), | |||||
), | |||||
); | ); | ||||
return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
->setContent($payload); | ->setContent($payload); | ||||
} | } | ||||
private function buildTemplate($object) { | private function buildTemplate($object) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
Show All 40 Lines |