1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Enhanced PholioMockQuery

Summary:
Images and cover files can now be attached calling need functions for PholioMockQuery.
Mock list will show cover files for mocks.
MockView uses new feature to show the first image

Test Plan: Verified that images are shown.

Reviewers: epriestley

CC: aran, Korvin

Maniphest Tasks: T2364

Differential Revision: https://secure.phabricator.com/D4644
This commit is contained in:
Lauri-Henrik Jalonen 2013-01-25 13:27:49 -08:00 committed by epriestley
parent 9d23a49c91
commit 3838e14ad8
6 changed files with 107 additions and 10 deletions

View file

@ -16,7 +16,8 @@ final class PholioMockListController extends PholioController {
$user = $request->getUser();
$query = id(new PholioMockQuery())
->setViewer($user);
->setViewer($user)
->needCoverFiles(true);
$nav = $this->buildSideNav();
$filter = $nav->selectFilter('view/'.$this->view, 'view/all');
@ -38,7 +39,8 @@ final class PholioMockListController extends PholioController {
$board->addItem(
id(new PhabricatorPinboardItemView())
->setHeader($mock->getName())
->setURI('/M'.$mock->getID()));
->setURI('/M'.$mock->getID())
->setImageURI($mock->getCoverFile()->getThumb160x120URI()));
}
$header = id(new PhabricatorHeaderView())

View file

@ -18,6 +18,8 @@ final class PholioMockViewController extends PholioController {
$mock = id(new PholioMockQuery())
->setViewer($user)
->withIDs(array($this->id))
->needImages(true)
->needCoverFiles(true)
->executeOne();
if (!$mock) {

View file

@ -10,6 +10,9 @@ final class PholioMockQuery
private $phids;
private $authorPHIDs;
private $needCoverFiles;
private $needImages;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
@ -37,7 +40,17 @@ final class PholioMockQuery
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($data);
$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) {
@ -69,4 +82,49 @@ final class PholioMockQuery
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 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');
foreach ($all_images as $image) {
$image->attachFile($all_files[$image->getFilePHID()]);
}
$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()]);
}
}
}

View file

@ -14,6 +14,7 @@ final class PholioImage extends PholioDAO
protected $description = '';
protected $sequence;
private $file;
/* -( PhabricatorMarkupInterface )----------------------------------------- */
@ -39,4 +40,16 @@ final class PholioImage extends PholioDAO
return (bool)$this->getID();
}
public function attachFile(PhabricatorFile $file) {
$this->file = $file;
return $this;
}
public function getFile() {
if ($this->file === null) {
throw new Exception("Call attachFile() before getFile()!");
}
return $this->file;
}
}

View file

@ -20,6 +20,9 @@ final class PholioMock extends PholioDAO
protected $coverPHID;
protected $mailKey;
private $images;
private $coverFile;
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
@ -37,6 +40,31 @@ final class PholioMock extends PholioDAO
return parent::save();
}
public function attachImages(array $images) {
assert_instances_of($images, 'PholioImage');
$this->images = $images;
return $this;
}
public function getImages() {
if ($this->images === null) {
throw new Exception("Call attachImages() before getImages()!");
}
return $this->images;
}
public function attachCoverFile(PhabricatorFile $file) {
$this->coverFile = $file;
return $this;
}
public function getCoverFile() {
if ($this->coverFile === null) {
throw new Exception("Call attachCoverFile() before getCoverFile()!");
}
return $this->coverFile;
}
/* -( PhabricatorSubscribableInterface Implementation )-------------------- */

View file

@ -13,13 +13,7 @@ final class PholioMockImagesView extends AphrontView {
throw new Exception("Call setMock() before render()!");
}
$image = id(new PholioImage())->loadOneWhere(
"mockid=%d",
$this->mock->getID());
$file = id(new PhabricatorFile())->loadOneWhere(
"phid=%s",
$image->getFilePHID());
$file = head($this->mock->getImages())->getFile();
$image_tag = phutil_render_tag(
'img',