2016-06-22 14:35:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class PhabricatorObjectRelationship extends Phobject {
|
|
|
|
|
|
|
|
private $viewer;
|
|
|
|
|
|
|
|
public function setViewer(PhabricatorUser $viewer) {
|
|
|
|
$this->viewer = $viewer;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getViewer() {
|
|
|
|
return $this->viewer;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function getRelationshipConstant() {
|
|
|
|
return $this->getPhobjectClassConstant('RELATIONSHIPKEY');
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract public function isEnabledForObject($object);
|
|
|
|
|
|
|
|
abstract public function getEdgeConstant();
|
|
|
|
|
|
|
|
abstract protected function getActionName();
|
|
|
|
abstract protected function getActionIcon();
|
|
|
|
|
2016-06-22 17:04:14 +02:00
|
|
|
abstract public function canRelateObjects($src, $dst);
|
|
|
|
|
|
|
|
abstract public function getDialogTitleText();
|
|
|
|
abstract public function getDialogHeaderText();
|
|
|
|
abstract public function getDialogButtonText();
|
|
|
|
|
|
|
|
public function getDialogInstructionsText() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-06-22 14:35:40 +02:00
|
|
|
public function shouldAppearInActionMenu() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function isActionEnabled($object) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
return PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$object,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
}
|
|
|
|
|
2016-06-29 01:05:05 +02:00
|
|
|
public function getRequiredRelationshipCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function newSource() {
|
2016-06-29 03:38:45 +02:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
return $this->newRelationshipSource()
|
|
|
|
->setViewer($viewer);
|
2016-06-29 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected function newRelationshipSource();
|
|
|
|
|
|
|
|
final public function getSourceURI($object) {
|
|
|
|
$relationship_key = $this->getRelationshipConstant();
|
|
|
|
$object_phid = $object->getPHID();
|
|
|
|
|
|
|
|
return "/search/source/{$relationship_key}/{$object_phid}/";
|
|
|
|
}
|
|
|
|
|
2016-06-22 14:35:40 +02:00
|
|
|
final public function newAction($object) {
|
|
|
|
$is_enabled = $this->isActionEnabled($object);
|
|
|
|
$action_uri = $this->getActionURI($object);
|
|
|
|
|
|
|
|
return id(new PhabricatorActionView())
|
|
|
|
->setName($this->getActionName())
|
|
|
|
->setHref($action_uri)
|
|
|
|
->setIcon($this->getActionIcon())
|
|
|
|
->setDisabled(!$is_enabled)
|
|
|
|
->setWorkflow(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
final public static function getAllRelationships() {
|
|
|
|
return id(new PhutilClassMapQuery())
|
|
|
|
->setAncestorClass(__CLASS__)
|
|
|
|
->setUniqueMethod('getRelationshipConstant')
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getActionURI($object) {
|
|
|
|
$phid = $object->getPHID();
|
2016-06-22 17:04:14 +02:00
|
|
|
$type = $this->getRelationshipConstant();
|
|
|
|
return "/search/rel/{$type}/{$phid}/";
|
2016-06-22 14:35:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|