2012-07-19 18:03:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group phame
|
|
|
|
*/
|
2012-10-15 23:49:52 +02:00
|
|
|
final class PhameBlogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
2012-07-19 18:03:10 +02:00
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
private $ids;
|
2012-07-19 18:03:10 +02:00
|
|
|
private $phids;
|
2012-10-01 02:10:27 +02:00
|
|
|
private $domain;
|
2012-07-19 18:03:10 +02:00
|
|
|
private $needBloggers;
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
2012-07-19 18:03:10 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
2012-10-01 02:10:27 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
public function withDomain($domain) {
|
|
|
|
$this->domain = $domain;
|
2012-07-19 18:03:10 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:28:02 +01:00
|
|
|
protected function loadPage() {
|
2012-07-19 18:03:10 +02:00
|
|
|
$table = new PhameBlog();
|
|
|
|
$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,
|
|
|
|
'SELECT * FROM %T b %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$where_clause,
|
|
|
|
$order_clause,
|
|
|
|
$limit_clause);
|
|
|
|
|
|
|
|
$blogs = $table->loadAllFromArray($data);
|
|
|
|
|
|
|
|
return $blogs;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildWhereClause($conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ls)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
if ($this->phids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'phid IN (%Ls)',
|
2012-10-15 23:49:52 +02:00
|
|
|
$this->phids);
|
2012-10-01 02:10:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->domain) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'domain = %s',
|
2012-10-15 23:49:52 +02:00
|
|
|
$this->domain);
|
2012-07-19 18:03:10 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 23:49:52 +02:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|