Differential D25078 Diff 361 src/applications/project/trigger/PhabricatorProjectTriggerManiphestOwnerRule.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/trigger/PhabricatorProjectTriggerManiphestOwnerRule.php
<?php | <?php | ||||
final class PhabricatorProjectTriggerManiphestOwnerRule | final class PhabricatorProjectTriggerManiphestOwnerRule | ||||
extends PhabricatorProjectTriggerRule { | extends PhabricatorProjectTriggerRule { | ||||
const TRIGGERTYPE = 'task.owner'; | const TRIGGERTYPE = 'task.owner'; | ||||
public function getSelectControlName() { | public function getSelectControlName() { | ||||
return pht('Assign task to'); | return pht('Assign Task to'); | ||||
} | } | ||||
protected function getValueForEditorField() { | protected function getValueForEditorField() { | ||||
return $this->getDatasource()->getWireTokens($this->getValue()); | return $this->getDatasource()->getWireTokens($this->getValue()); | ||||
} | } | ||||
private function convertTokenizerValueToOwner($value) { | private function convertTokenizerValueToOwner($value) { | ||||
$value = head($value); | $value = head($value); | ||||
if ($value === PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN) { | if ($value === PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN) { | ||||
$value = null; | $value = null; | ||||
} | } | ||||
return $value; | return $value; | ||||
} | } | ||||
protected function assertValidRuleRecordFormat($value) { | protected function assertValidRuleRecordFormat($value) { | ||||
if (!is_array($value)) { | if (!is_array($value)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Owner rule value should be a list, but is not (value is "%s").', | 'Owner Rule Value should be a list, but is not (value is "%s").', | ||||
phutil_describe_type($value))); | phutil_describe_type($value))); | ||||
} | } | ||||
} | } | ||||
protected function assertValidRuleRecordValue($value) { | protected function assertValidRuleRecordValue($value) { | ||||
if (!$value) { | if (!$value) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Owner rule value is required. Specify a user to assign tasks '. | 'Owner Rule Value is required. Specify a User to assign Tasks '. | ||||
'to, or the token "none()" to unassign tasks.')); | 'to, or the token "none()" to unassign Tasks.')); | ||||
} | } | ||||
if (count($value) > 1) { | if (count($value) > 1) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Owner rule value must have only one elmement (value is "%s").', | 'Owner Rule value must have only one element (value is "%s").', | ||||
implode(', ', $value))); | implode(', ', $value))); | ||||
} | } | ||||
$owner_phid = $this->convertTokenizerValueToOwner($value); | $owner_phid = $this->convertTokenizerValueToOwner($value); | ||||
if ($owner_phid !== null) { | if ($owner_phid !== null) { | ||||
$user = id(new PhabricatorPeopleQuery()) | $user = id(new PhabricatorPeopleQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->withPHIDs(array($owner_phid)) | ->withPHIDs(array($owner_phid)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$user) { | if (!$user) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'User PHID ("%s") is not a valid user.', | 'User PHID ("%s") is not a valid User.', | ||||
$owner_phid)); | $owner_phid)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
protected function newDropTransactions($object, $value) { | protected function newDropTransactions($object, $value) { | ||||
$value = $this->convertTokenizerValueToOwner($value); | $value = $this->convertTokenizerValueToOwner($value); | ||||
return array( | return array( | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | final class PhabricatorProjectTriggerManiphestOwnerRule | ||||
public function getRuleViewLabel() { | public function getRuleViewLabel() { | ||||
return pht('Change Owner'); | return pht('Change Owner'); | ||||
} | } | ||||
public function getRuleViewDescription($value) { | public function getRuleViewDescription($value) { | ||||
$value = $this->convertTokenizerValueToOwner($value); | $value = $this->convertTokenizerValueToOwner($value); | ||||
if (!$value) { | if (!$value) { | ||||
return pht('Unassign task.'); | return pht('Unassign Task.'); | ||||
} else { | } else { | ||||
return pht( | return pht( | ||||
'Assign task to %s.', | 'Assign Task to %s.', | ||||
phutil_tag( | phutil_tag( | ||||
'strong', | 'strong', | ||||
array(), | array(), | ||||
$this->getViewer() | $this->getViewer() | ||||
->renderHandle($value) | ->renderHandle($value) | ||||
->render())); | ->render())); | ||||
} | } | ||||
} | } | ||||
public function getRuleViewIcon($value) { | public function getRuleViewIcon($value) { | ||||
return id(new PHUIIconView()) | return id(new PHUIIconView()) | ||||
->setIcon('fa-user', 'green'); | ->setIcon('fa-user', 'green'); | ||||
} | } | ||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0