Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/query/PhamePostQuery.php
<?php | <?php | ||||
final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery { | final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $blogPHIDs; | private $blogPHIDs; | ||||
private $bloggerPHIDs; | private $bloggerPHIDs; | ||||
private $visibility; | private $visibility; | ||||
private $publishedAfter; | private $publishedAfter; | ||||
private $phids; | private $phids; | ||||
private $needHeaderImage; | |||||
public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
$this->ids = $ids; | $this->ids = $ids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
$this->phids = $phids; | $this->phids = $phids; | ||||
return $this; | return $this; | ||||
Show All 14 Lines | public function withVisibility(array $visibility) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withPublishedAfter($time) { | public function withPublishedAfter($time) { | ||||
$this->publishedAfter = $time; | $this->publishedAfter = $time; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needHeaderImage($need) { | |||||
$this->needHeaderImage = $need; | |||||
return $this; | |||||
} | |||||
public function newResultObject() { | public function newResultObject() { | ||||
return new PhamePost(); | return new PhamePost(); | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
} | } | ||||
Show All 16 Lines | foreach ($posts as $key => $post) { | ||||
$this->didRejectResult($post); | $this->didRejectResult($post); | ||||
unset($posts[$key]); | unset($posts[$key]); | ||||
continue; | continue; | ||||
} | } | ||||
$post->attachBlog($blog); | $post->attachBlog($blog); | ||||
} | } | ||||
if ($this->needHeaderImage) { | |||||
$file_phids = mpull($posts, 'getHeaderImagePHID'); | |||||
$file_phids = array_filter($file_phids); | |||||
if ($file_phids) { | |||||
$files = id(new PhabricatorFileQuery()) | |||||
->setParentQuery($this) | |||||
->setViewer($this->getViewer()) | |||||
->withPHIDs($file_phids) | |||||
->execute(); | |||||
$files = mpull($files, null, 'getPHID'); | |||||
} else { | |||||
$files = array(); | |||||
} | |||||
foreach ($posts as $post) { | |||||
$file = idx($files, $post->getHeaderImagePHID()); | |||||
if ($file) { | |||||
$post->attachHeaderImageFile($file); | |||||
} | |||||
} | |||||
} | |||||
return $posts; | return $posts; | ||||
} | } | ||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
if ($this->ids) { | if ($this->ids) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |