2012-10-05 22:18:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSubscribersQuery extends PhabricatorQuery {
|
|
|
|
|
|
|
|
private $objectPHIDs;
|
|
|
|
private $subscriberPHIDs;
|
|
|
|
|
|
|
|
public static function loadSubscribersForPHID($phid) {
|
2012-11-22 02:38:57 +01:00
|
|
|
if (!$phid) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2012-10-05 22:18:05 +02:00
|
|
|
$subscribers = id(new PhabricatorSubscribersQuery())
|
|
|
|
->withObjectPHIDs(array($phid))
|
|
|
|
->execute();
|
|
|
|
return $subscribers[$phid];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withObjectPHIDs(array $object_phids) {
|
|
|
|
$this->objectPHIDs = $object_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withSubscriberPHIDs(array $subscriber_phids) {
|
|
|
|
$this->subscriberPHIDs = $subscriber_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
$query = new PhabricatorEdgeQuery();
|
|
|
|
|
2015-01-03 00:33:25 +01:00
|
|
|
$edge_type = PhabricatorObjectHasSubscriberEdgeType::EDGECONST;
|
2012-10-05 22:18:05 +02:00
|
|
|
|
|
|
|
$query->withSourcePHIDs($this->objectPHIDs);
|
|
|
|
$query->withEdgeTypes(array($edge_type));
|
|
|
|
|
|
|
|
if ($this->subscriberPHIDs) {
|
|
|
|
$query->withDestinationPHIDs($this->subscriberPHIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
$edges = $query->execute();
|
|
|
|
|
|
|
|
$results = array_fill_keys($this->objectPHIDs, array());
|
|
|
|
foreach ($edges as $src => $edge_types) {
|
|
|
|
foreach ($edge_types[$edge_type] as $dst => $data) {
|
|
|
|
$results[$src][] = $dst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
}
|