2014-02-26 23:46:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialJIRAIssuesField
|
2014-02-27 01:53:42 +01:00
|
|
|
extends DifferentialStoredCustomField {
|
2014-02-26 23:46:18 +01:00
|
|
|
|
2014-02-27 01:53:42 +01:00
|
|
|
public function getFieldKey() {
|
|
|
|
return 'phabricator:jira-issues';
|
|
|
|
}
|
2014-02-26 23:46:18 +01:00
|
|
|
|
2014-02-27 01:53:42 +01:00
|
|
|
public function getValueForStorage() {
|
|
|
|
return json_encode($this->getValue());
|
|
|
|
}
|
2014-02-26 23:46:18 +01:00
|
|
|
|
2014-02-27 01:53:42 +01:00
|
|
|
public function setValueFromStorage($value) {
|
|
|
|
$this->setValue(json_decode($value, true));
|
|
|
|
return $this;
|
2014-02-26 23:46:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldName() {
|
|
|
|
return pht('JIRA Issues');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldDescription() {
|
|
|
|
return pht('Lists associated JIRA issues.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAppearInPropertyView() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderPropertyViewLabel() {
|
|
|
|
return $this->getFieldName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderPropertyViewValue(array $handles) {
|
|
|
|
$xobjs = $this->loadDoorkeeperExternalObjects();
|
|
|
|
if (!$xobjs) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$links = array();
|
|
|
|
foreach ($xobjs as $xobj) {
|
|
|
|
$links[] = id(new DoorkeeperTagView())
|
|
|
|
->setExternalObject($xobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return phutil_implode_html(phutil_tag('br'), $links);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildDoorkeeperRefs() {
|
|
|
|
$provider = PhabricatorAuthProviderOAuth1JIRA::getJIRAProvider();
|
|
|
|
|
|
|
|
$refs = array();
|
2014-02-27 01:53:42 +01:00
|
|
|
if ($this->getValue()) {
|
|
|
|
foreach ($this->getValue() as $jira_key) {
|
2014-02-26 23:46:18 +01:00
|
|
|
$refs[] = id(new DoorkeeperObjectRef())
|
|
|
|
->setApplicationType(DoorkeeperBridgeJIRA::APPTYPE_JIRA)
|
|
|
|
->setApplicationDomain($provider->getProviderDomain())
|
|
|
|
->setObjectType(DoorkeeperBridgeJIRA::OBJTYPE_ISSUE)
|
|
|
|
->setObjectID($jira_key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $refs;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadDoorkeeperExternalObjects() {
|
|
|
|
$refs = $this->buildDoorkeeperRefs();
|
|
|
|
if (!$refs) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$xobjs = id(new DoorkeeperExternalObjectQuery())
|
2014-02-27 01:53:42 +01:00
|
|
|
->setViewer($this->getViewer())
|
2014-02-26 23:46:18 +01:00
|
|
|
->withObjectKeys(mpull($refs, 'getObjectKey'))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
return $xobjs;
|
|
|
|
}
|
|
|
|
|
2014-02-27 01:53:42 +01:00
|
|
|
// TODO: Implement edit; this field is readonly for now.
|
|
|
|
|
2014-02-26 23:46:18 +01:00
|
|
|
}
|