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;
|
2016-03-08 17:51:45 +01:00
|
|
|
private $itemTypes;
|
|
|
|
private $itemKeys;
|
|
|
|
private $containerKeys;
|
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;
|
|
|
|
}
|
|
|
|
|
2016-03-08 17:51:45 +01:00
|
|
|
public function withItemTypes(array $item_types) {
|
|
|
|
$this->itemTypes = $item_types;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withItemKeys(array $item_keys) {
|
|
|
|
$this->itemKeys = $item_keys;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withItemContainerKeys(array $container_keys) {
|
|
|
|
$this->containerKeys = $container_keys;
|
|
|
|
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);
|
|
|
|
}
|
2016-03-08 22:07:22 +01:00
|
|
|
|
|
|
|
$type_map = NuanceItemType::getAllItemTypes();
|
|
|
|
foreach ($items as $key => $item) {
|
|
|
|
$type = idx($type_map, $item->getItemType());
|
|
|
|
if (!$type) {
|
|
|
|
$this->didRejectResult($items[$key]);
|
|
|
|
unset($items[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$item->attachImplementation($type);
|
|
|
|
}
|
2015-08-23 17:34:52 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-03-08 17:51:45 +01:00
|
|
|
if ($this->itemTypes !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'itemType IN (%Ls)',
|
|
|
|
$this->itemTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->itemKeys !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'itemKey IN (%Ls)',
|
|
|
|
$this->itemKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->containerKeys !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'itemContainerKey IN (%Ls)',
|
|
|
|
$this->containerKeys);
|
|
|
|
}
|
|
|
|
|
2015-06-05 20:01:06 +02:00
|
|
|
return $where;
|
2013-11-07 02:00:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|