Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/query/PhrictionDocumentQuery.php
<?php | <?php | ||||
/** | |||||
* @group phriction | |||||
*/ | |||||
final class PhrictionDocumentQuery | final class PhrictionDocumentQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
private $slugs; | private $slugs; | ||||
private $needContent; | |||||
private $status = 'status-any'; | private $status = 'status-any'; | ||||
const STATUS_ANY = 'status-any'; | const STATUS_ANY = 'status-any'; | ||||
const STATUS_OPEN = 'status-open'; | const STATUS_OPEN = 'status-open'; | ||||
const STATUS_NONSTUB = 'status-nonstub'; | const STATUS_NONSTUB = 'status-nonstub'; | ||||
private $order = 'order-created'; | private $order = 'order-created'; | ||||
const ORDER_CREATED = 'order-created'; | const ORDER_CREATED = 'order-created'; | ||||
const ORDER_UPDATED = 'order-updated'; | const ORDER_UPDATED = 'order-updated'; | ||||
Show All 13 Lines | public function withSlugs(array $slugs) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withStatus($status) { | public function withStatus($status) { | ||||
$this->status = $status; | $this->status = $status; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needContent($need_content) { | |||||
$this->needContent = $need_content; | |||||
return $this; | |||||
} | |||||
public function setOrder($order) { | public function setOrder($order) { | ||||
$this->order = $order; | $this->order = $order; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
$document = new PhrictionDocument(); | $document = new PhrictionDocument(); | ||||
$conn_r = $document->establishConnection('r'); | $conn_r = $document->establishConnection('r'); | ||||
$rows = queryfx_all( | $rows = queryfx_all( | ||||
$conn_r, | $conn_r, | ||||
'SELECT * FROM %T %Q %Q %Q', | 'SELECT * FROM %T %Q %Q %Q', | ||||
$document->getTableName(), | $document->getTableName(), | ||||
$this->buildWhereClause($conn_r), | $this->buildWhereClause($conn_r), | ||||
$this->buildOrderClause($conn_r), | $this->buildOrderClause($conn_r), | ||||
$this->buildLimitClause($conn_r)); | $this->buildLimitClause($conn_r)); | ||||
return $document->loadAllFromArray($rows); | return $document->loadAllFromArray($rows); | ||||
} | } | ||||
protected function willFilterPage(array $documents) { | protected function willFilterPage(array $documents) { | ||||
if ($this->needContent) { | |||||
$contents = id(new PhrictionContent())->loadAllWhere( | $contents = id(new PhrictionContent())->loadAllWhere( | ||||
'id IN (%Ld)', | 'id IN (%Ld)', | ||||
mpull($documents, 'getContentID')); | mpull($documents, 'getContentID')); | ||||
foreach ($documents as $key => $document) { | foreach ($documents as $key => $document) { | ||||
$content_id = $document->getContentID(); | $content_id = $document->getContentID(); | ||||
if (empty($contents[$content_id])) { | if (empty($contents[$content_id])) { | ||||
unset($documents[$key]); | unset($documents[$key]); | ||||
continue; | continue; | ||||
} | } | ||||
$document->attachContent($contents[$content_id]); | $document->attachContent($contents[$content_id]); | ||||
} | } | ||||
} | |||||
foreach ($documents as $document) { | foreach ($documents as $document) { | ||||
$document->attachProject(null); | $document->attachProject(null); | ||||
} | } | ||||
$project_slugs = array(); | $project_slugs = array(); | ||||
foreach ($documents as $key => $document) { | foreach ($documents as $key => $document) { | ||||
$slug = $document->getSlug(); | $slug = $document->getSlug(); | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |