Differential D12438 Diff 29881 src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php
<?php | <?php | ||||
abstract class PhabricatorTypeaheadCompositeDatasource | abstract class PhabricatorTypeaheadCompositeDatasource | ||||
extends PhabricatorTypeaheadDatasource { | extends PhabricatorTypeaheadDatasource { | ||||
private $usable; | |||||
abstract public function getComponentDatasources(); | abstract public function getComponentDatasources(); | ||||
public function isBrowsable() { | |||||
foreach ($this->getUsableDatasources() as $datasource) { | |||||
if (!$datasource->isBrowsable()) { | |||||
return false; | |||||
} | |||||
} | |||||
return parent::isBrowsable(); | |||||
} | |||||
public function getDatasourceApplicationClass() { | public function getDatasourceApplicationClass() { | ||||
return null; | return null; | ||||
} | } | ||||
public function loadResults() { | public function loadResults() { | ||||
$offset = $this->getOffset(); | $offset = $this->getOffset(); | ||||
$limit = $this->getLimit(); | $limit = $this->getLimit(); | ||||
Show All 22 Lines | if ($offset || $limit) { | ||||
$results = array_slice($results, $offset, $limit, $preserve_keys = true); | $results = array_slice($results, $offset, $limit, $preserve_keys = true); | ||||
} | } | ||||
return $results; | return $results; | ||||
} | } | ||||
private function getUsableDatasources() { | private function getUsableDatasources() { | ||||
if ($this->usable === null) { | |||||
$sources = $this->getComponentDatasources(); | $sources = $this->getComponentDatasources(); | ||||
$usable = array(); | $usable = array(); | ||||
foreach ($sources as $source) { | foreach ($sources as $source) { | ||||
$application_class = $source->getDatasourceApplicationClass(); | $application_class = $source->getDatasourceApplicationClass(); | ||||
if ($application_class) { | if ($application_class) { | ||||
$result = id(new PhabricatorApplicationQuery()) | $result = id(new PhabricatorApplicationQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->withClasses(array($application_class)) | ->withClasses(array($application_class)) | ||||
->execute(); | ->execute(); | ||||
if (!$result) { | if (!$result) { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
$usable[] = $source; | $usable[] = $source; | ||||
} | } | ||||
$this->usable = $usable; | |||||
} | |||||
return $usable; | return $this->usable; | ||||
} | } | ||||
} | } |