Changeset View
Changeset View
Standalone View
Standalone View
src/applications/pholio/query/PholioMockQuery.php
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | public function needTokenCounts($need) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function newResultObject() { | public function newResultObject() { | ||||
return new PholioMock(); | return new PholioMock(); | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
$mocks = $this->loadStandardPage($this->newResultObject()); | if ($this->needInlineComments && !$this->needImages) { | ||||
throw new Exception( | |||||
if ($mocks && $this->needImages) { | pht( | ||||
self::loadImages($this->getViewer(), $mocks, $this->needInlineComments); | 'You can not query for inline comments without also querying for '. | ||||
} | 'images.')); | ||||
if ($mocks && $this->needCoverFiles) { | |||||
$this->loadCoverFiles($mocks); | |||||
} | } | ||||
if ($mocks && $this->needTokenCounts) { | return $this->loadStandardPage(new PholioMock()); | ||||
$this->loadTokenCounts($mocks); | |||||
} | |||||
return $mocks; | |||||
} | } | ||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
Show All 20 Lines | if ($this->statuses !== null) { | ||||
$conn, | $conn, | ||||
'mock.status IN (%Ls)', | 'mock.status IN (%Ls)', | ||||
$this->statuses); | $this->statuses); | ||||
} | } | ||||
return $where; | return $where; | ||||
} | } | ||||
public static function loadImages( | protected function didFilterPage(array $mocks) { | ||||
PhabricatorUser $viewer, | $viewer = $this->getViewer(); | ||||
array $mocks, | |||||
$need_inline_comments) { | |||||
assert_instances_of($mocks, 'PholioMock'); | |||||
$mock_map = mpull($mocks, null, 'getPHID'); | if ($this->needImages) { | ||||
$all_images = id(new PholioImageQuery()) | $images = id(new PholioImageQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setMockCache($mock_map) | ->withMocks($mocks) | ||||
->withMockPHIDs(array_keys($mock_map)) | ->needInlineComments($this->needInlineComments) | ||||
->needInlineComments($need_inline_comments) | |||||
->execute(); | ->execute(); | ||||
$image_groups = mgroup($all_images, 'getMockPHID'); | $image_groups = mgroup($images, 'getMockPHID'); | ||||
foreach ($mocks as $mock) { | foreach ($mocks as $mock) { | ||||
$mock_images = idx($image_groups, $mock->getPHID(), array()); | $images = idx($image_groups, $mock->getPHID(), array()); | ||||
$mock->attachImages($mock_images); | $mock->attachImages($images); | ||||
} | } | ||||
} | } | ||||
private function loadCoverFiles(array $mocks) { | if ($this->needCoverFiles) { | ||||
assert_instances_of($mocks, 'PholioMock'); | |||||
$cover_file_phids = mpull($mocks, 'getCoverPHID'); | |||||
$cover_files = id(new PhabricatorFileQuery()) | $cover_files = id(new PhabricatorFileQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($viewer) | ||||
->withPHIDs($cover_file_phids) | ->withPHIDs(mpull($mocks, 'getCoverPHID')) | ||||
->execute(); | ->execute(); | ||||
$cover_files = mpull($cover_files, null, 'getPHID'); | $cover_files = mpull($cover_files, null, 'getPHID'); | ||||
foreach ($mocks as $mock) { | foreach ($mocks as $mock) { | ||||
$file = idx($cover_files, $mock->getCoverPHID()); | $file = idx($cover_files, $mock->getCoverPHID()); | ||||
if (!$file) { | if (!$file) { | ||||
$file = PhabricatorFile::loadBuiltin($this->getViewer(), 'missing.png'); | $file = PhabricatorFile::loadBuiltin( | ||||
$viewer, | |||||
'missing.png'); | |||||
} | } | ||||
$mock->attachCoverFile($file); | $mock->attachCoverFile($file); | ||||
} | } | ||||
} | } | ||||
private function loadTokenCounts(array $mocks) { | if ($this->needTokenCounts) { | ||||
assert_instances_of($mocks, 'PholioMock'); | |||||
$phids = mpull($mocks, 'getPHID'); | |||||
$counts = id(new PhabricatorTokenCountQuery()) | $counts = id(new PhabricatorTokenCountQuery()) | ||||
->withObjectPHIDs($phids) | ->withObjectPHIDs(mpull($mocks, 'getPHID')) | ||||
->execute(); | ->execute(); | ||||
foreach ($mocks as $mock) { | foreach ($mocks as $mock) { | ||||
$mock->attachTokenCount(idx($counts, $mock->getPHID(), 0)); | $token_count = idx($counts, $mock->getPHID(), 0); | ||||
$mock->attachTokenCount($token_count); | |||||
} | } | ||||
} | } | ||||
return $mocks; | |||||
} | |||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorPholioApplication'; | return 'PhabricatorPholioApplication'; | ||||
} | } | ||||
protected function getPrimaryTableAlias() { | protected function getPrimaryTableAlias() { | ||||
return 'mock'; | return 'mock'; | ||||
} | } | ||||
} | } |