2012-04-12 22:09:04 +02:00
|
|
|
<?php
|
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
/**
|
|
|
|
* @group phame
|
|
|
|
*/
|
2012-10-15 23:50:04 +02:00
|
|
|
final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
2012-04-12 22:09:04 +02:00
|
|
|
|
2012-10-15 23:50:45 +02:00
|
|
|
private $ids;
|
2012-10-15 23:50:04 +02:00
|
|
|
private $blogPHIDs;
|
|
|
|
private $bloggerPHIDs;
|
|
|
|
private $phameTitles;
|
2012-04-12 22:09:04 +02:00
|
|
|
private $visibility;
|
2012-07-19 18:03:10 +02:00
|
|
|
private $phids;
|
2012-04-12 22:09:04 +02:00
|
|
|
|
2012-10-15 23:50:45 +02:00
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
2012-04-12 22:09:04 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2012-10-15 23:50:04 +02:00
|
|
|
|
|
|
|
public function withBloggerPHIDs(array $blogger_phids) {
|
|
|
|
$this->bloggerPHIDs = $blogger_phids;
|
2012-07-06 00:43:14 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
public function withBlogPHIDs(array $blog_phids) {
|
|
|
|
$this->blogPHIDs = $blog_phids;
|
2012-07-19 18:03:10 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
public function withPhameTitles(array $phame_titles) {
|
|
|
|
$this->phameTitles = $phame_titles;
|
2012-04-12 22:09:04 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
public function withVisibility($visibility) {
|
|
|
|
$this->visibility = $visibility;
|
2012-07-19 18:03:10 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
protected function loadPage() {
|
2012-04-12 22:09:04 +02:00
|
|
|
$table = new PhamePost();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$where_clause = $this->buildWhereClause($conn_r);
|
|
|
|
$order_clause = $this->buildOrderClause($conn_r);
|
|
|
|
$limit_clause = $this->buildLimitClause($conn_r);
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
2012-07-19 18:03:10 +02:00
|
|
|
'SELECT * FROM %T p %Q %Q %Q',
|
2012-04-12 22:09:04 +02:00
|
|
|
$table->getTableName(),
|
|
|
|
$where_clause,
|
|
|
|
$order_clause,
|
|
|
|
$limit_clause);
|
|
|
|
|
|
|
|
$posts = $table->loadAllFromArray($data);
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
if ($posts) {
|
|
|
|
// We require these to do visibility checks, so load them unconditionally.
|
|
|
|
$blog_phids = mpull($posts, 'getBlogPHID');
|
|
|
|
$blogs = id(new PhameBlogQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($blog_phids)
|
|
|
|
->execute();
|
2012-10-15 23:50:37 +02:00
|
|
|
$blogs = mpull($blogs, null, 'getPHID');
|
2012-10-15 23:50:04 +02:00
|
|
|
foreach ($posts as $post) {
|
|
|
|
if (isset($blogs[$post->getBlogPHID()])) {
|
|
|
|
$post->setBlog($blogs[$post->getBlogPHID()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 22:09:04 +02:00
|
|
|
return $posts;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
2012-04-12 22:09:04 +02:00
|
|
|
$where = array();
|
|
|
|
|
2012-10-15 23:50:45 +02:00
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'p.id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
if ($this->phids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2012-10-15 23:50:04 +02:00
|
|
|
'p.phid IN (%Ls)',
|
|
|
|
$this->phids);
|
2012-07-19 18:03:10 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
if ($this->bloggerPHIDs) {
|
2012-04-12 22:09:04 +02:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2012-10-15 23:50:04 +02:00
|
|
|
'p.bloggerPHID IN (%Ls)',
|
|
|
|
$this->bloggerPHIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->phameTitles) {
|
2012-07-06 00:43:14 +02:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2012-10-15 23:50:04 +02:00
|
|
|
'p.phameTitle IN (%Ls)',
|
|
|
|
$this->phameTitles);
|
2012-04-12 22:09:04 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
if ($this->visibility !== null) {
|
2012-07-19 18:03:10 +02:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2012-10-15 23:50:04 +02:00
|
|
|
'p.visibility = %d',
|
|
|
|
$this->visibility);
|
2012-07-19 18:03:10 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
if ($this->blogPHIDs) {
|
2012-04-12 22:09:04 +02:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2012-10-15 23:50:04 +02:00
|
|
|
'p.blogPHID in (%Ls)',
|
|
|
|
$this->blogPHIDs);
|
2012-04-12 22:09:04 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
2012-04-12 22:09:04 +02:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|