2013-11-07 02:00:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class NuanceItemQuery
|
|
|
|
extends NuanceQuery {
|
|
|
|
|
|
|
|
private $ids;
|
|
|
|
private $phids;
|
2015-06-05 20:01:06 +02:00
|
|
|
private $sourcePHIDs;
|
2013-11-07 02:00:09 +01:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-08-23 17:34:52 +02:00
|
|
|
public function withSourcePHIDs(array $source_phids) {
|
2015-06-05 20:01:06 +02:00
|
|
|
$this->sourcePHIDs = $source_phids;
|
2013-11-07 02:00:09 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-08-23 17:34:52 +02:00
|
|
|
public function newResultObject() {
|
|
|
|
return new NuanceItem();
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:56:07 +01:00
|
|
|
protected function loadPage() {
|
2015-08-23 17:34:52 +02:00
|
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function willFilterPage(array $items) {
|
|
|
|
$source_phids = mpull($items, 'getSourcePHID');
|
|
|
|
|
|
|
|
// NOTE: We always load sources, even if the viewer can't formally see
|
|
|
|
// them. If they can see the item, they're allowed to be aware of the
|
|
|
|
// source in some sense.
|
|
|
|
$sources = id(new NuanceSourceQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withPHIDs($source_phids)
|
|
|
|
->execute();
|
|
|
|
$sources = mpull($sources, null, 'getPHID');
|
|
|
|
|
|
|
|
foreach ($items as $key => $item) {
|
|
|
|
$source = idx($sources, $item->getSourcePHID());
|
|
|
|
if (!$source) {
|
|
|
|
$this->didRejectResult($items[$key]);
|
|
|
|
unset($items[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$item->attachSource($source);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $items;
|
2013-11-07 02:00:09 +01:00
|
|
|
}
|
|
|
|
|
2015-06-05 20:01:06 +02:00
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
2013-11-07 02:00:09 +01:00
|
|
|
|
2015-06-05 20:01:06 +02:00
|
|
|
if ($this->sourcePHIDs !== null) {
|
2013-11-07 02:00:09 +01:00
|
|
|
$where[] = qsprintf(
|
2015-06-05 20:01:06 +02:00
|
|
|
$conn,
|
|
|
|
'sourcePHID IN (%Ls)',
|
|
|
|
$this->sourcePHIDs);
|
2013-11-07 02:00:09 +01:00
|
|
|
}
|
|
|
|
|
2015-06-05 20:01:06 +02:00
|
|
|
if ($this->ids !== null) {
|
2013-11-07 02:00:09 +01:00
|
|
|
$where[] = qsprintf(
|
2015-06-05 20:01:06 +02:00
|
|
|
$conn,
|
2013-11-07 02:00:09 +01:00
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2015-06-05 20:01:06 +02:00
|
|
|
if ($this->phids !== null) {
|
2013-11-07 02:00:09 +01:00
|
|
|
$where[] = qsprintf(
|
2015-06-05 20:01:06 +02:00
|
|
|
$conn,
|
2013-11-07 02:00:09 +01:00
|
|
|
'phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2015-06-05 20:01:06 +02:00
|
|
|
return $where;
|
2013-11-07 02:00:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|