mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-03 20:22:46 +01:00
f1bd1da062
Summary: Rendering of inline comments has now been moved to PholioInlineCommentView controller. Delete almost deletes and edit... well not so much, but replaced google.fi with amazing popup. Test Plan: Verified that inline comments still show up. Verified that delete almost deletes. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2446 Differential Revision: https://secure.phabricator.com/D4994 Conflicts: src/applications/pholio/controller/PholioInlineController.php
147 lines
3.5 KiB
PHP
147 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group pholio
|
|
*/
|
|
final class PholioMockQuery
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
private $ids;
|
|
private $phids;
|
|
private $authorPHIDs;
|
|
|
|
private $needCoverFiles;
|
|
private $needImages;
|
|
private $needInlineComments;
|
|
|
|
public function withIDs(array $ids) {
|
|
$this->ids = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function withPHIDs(array $phids) {
|
|
$this->phids = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withAuthorPHIDs(array $author_phids) {
|
|
$this->authorPHIDs = $author_phids;
|
|
return $this;
|
|
}
|
|
|
|
public function loadPage() {
|
|
$table = new PholioMock();
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
$data = queryfx_all(
|
|
$conn_r,
|
|
'SELECT * FROM %T %Q %Q %Q',
|
|
$table->getTableName(),
|
|
$this->buildWhereClause($conn_r),
|
|
$this->buildOrderClause($conn_r),
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
$mocks = $table->loadAllFromArray($data);
|
|
|
|
if ($mocks && $this->needImages) {
|
|
$this->loadImages($mocks);
|
|
}
|
|
if ($mocks && $this->needCoverFiles) {
|
|
$this->loadCoverFiles($mocks);
|
|
}
|
|
|
|
|
|
return $mocks;
|
|
}
|
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
$where = array();
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
if ($this->ids) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'id IN (%Ld)',
|
|
$this->ids);
|
|
}
|
|
|
|
if ($this->phids) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'phid IN (%Ls)',
|
|
$this->phids);
|
|
}
|
|
|
|
if ($this->authorPHIDs) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'authorPHID in (%Ls)',
|
|
$this->authorPHIDs);
|
|
}
|
|
|
|
return $this->formatWhereClause($where);
|
|
}
|
|
|
|
public function needCoverFiles($need_cover_files) {
|
|
$this->needCoverFiles = $need_cover_files;
|
|
return $this;
|
|
}
|
|
|
|
public function needImages($need_images) {
|
|
$this->needImages = $need_images;
|
|
return $this;
|
|
}
|
|
|
|
public function needInlineComments($need_inline_comments) {
|
|
$this->needInlineComments = $need_inline_comments;
|
|
return $this;
|
|
}
|
|
|
|
public function loadImages(array $mocks) {
|
|
assert_instances_of($mocks, 'PholioMock');
|
|
|
|
$mock_ids = mpull($mocks, 'getID');
|
|
$all_images = id(new PholioImage())->loadAllWhere(
|
|
'mockID IN (%Ld)',
|
|
$mock_ids);
|
|
|
|
$file_phids = mpull($all_images, 'getFilePHID');
|
|
$all_files = mpull(id(new PhabricatorFile())->loadAllWhere(
|
|
'phid IN (%Ls)',
|
|
$file_phids), null, 'getPHID');
|
|
|
|
if ($this->needInlineComments) {
|
|
$all_inline_comments = id(new PholioTransactionComment())
|
|
->loadAllWhere('imageid IN (%Ld)',
|
|
mpull($all_images, 'getID'));
|
|
$all_inline_comments = mgroup($all_inline_comments, 'getImageID');
|
|
}
|
|
|
|
foreach ($all_images as $image) {
|
|
$image->attachFile($all_files[$image->getFilePHID()]);
|
|
if ($this->needInlineComments) {
|
|
$inlines = idx($all_images, $image->getID(), array());
|
|
$image->attachInlineComments($inlines);
|
|
}
|
|
}
|
|
|
|
$image_groups = mgroup($all_images, 'getMockID');
|
|
|
|
foreach ($mocks as $mock) {
|
|
$mock->attachImages($image_groups[$mock->getID()]);
|
|
}
|
|
}
|
|
|
|
public function loadCoverFiles(array $mocks) {
|
|
assert_instances_of($mocks, 'PholioMock');
|
|
$cover_file_phids = mpull($mocks, 'getCoverPHID');
|
|
$cover_files = mpull(id(new PhabricatorFile())->loadAllWhere(
|
|
'phid IN (%Ls)',
|
|
$cover_file_phids), null, 'getPHID');
|
|
|
|
foreach ($mocks as $mock) {
|
|
$mock->attachCoverFile($cover_files[$mock->getCoverPHID()]);
|
|
}
|
|
}
|
|
}
|