Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/herald/ManiphestTaskPriorityHeraldAction.php
12256 views
1
<?php
2
3
final class ManiphestTaskPriorityHeraldAction
4
extends HeraldAction {
5
6
const ACTIONCONST = 'maniphest.priority';
7
const DO_PRIORITY = 'do.priority';
8
9
public function supportsObject($object) {
10
return ($object instanceof ManiphestTask);
11
}
12
13
public function getActionGroupKey() {
14
return HeraldApplicationActionGroup::ACTIONGROUPKEY;
15
}
16
17
public function getHeraldActionName() {
18
return pht('Change priority to');
19
}
20
21
public function supportsRuleType($rule_type) {
22
return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
23
}
24
25
public function applyEffect($object, HeraldEffect $effect) {
26
$priority = head($effect->getTarget());
27
28
if (!$priority) {
29
$this->logEffect(self::DO_STANDARD_EMPTY);
30
return;
31
}
32
33
$adapter = $this->getAdapter();
34
$object = $adapter->getObject();
35
$current = $object->getPriority();
36
37
if ($current == $priority) {
38
$this->logEffect(self::DO_STANDARD_NO_EFFECT, $priority);
39
return;
40
}
41
42
$keyword_map = ManiphestTaskPriority::getTaskPriorityKeywordsMap();
43
$keyword = head(idx($keyword_map, $priority));
44
45
$xaction = $adapter->newTransaction()
46
->setTransactionType(ManiphestTaskPriorityTransaction::TRANSACTIONTYPE)
47
->setNewValue($keyword);
48
49
$adapter->queueTransaction($xaction);
50
$this->logEffect(self::DO_PRIORITY, $keyword);
51
}
52
53
public function getHeraldActionStandardType() {
54
return self::STANDARD_PHID_LIST;
55
}
56
57
public function renderActionDescription($value) {
58
$priority = head($value);
59
$name = ManiphestTaskPriority::getTaskPriorityName($priority);
60
return pht('Change priority to: %s.', $name);
61
}
62
63
protected function getDatasource() {
64
return id(new ManiphestTaskPriorityDatasource())
65
->setLimit(1);
66
}
67
68
protected function getDatasourceValueMap() {
69
return ManiphestTaskPriority::getTaskPriorityMap();
70
}
71
72
protected function getActionEffectMap() {
73
return array(
74
self::DO_PRIORITY => array(
75
'icon' => 'fa-pencil',
76
'color' => 'green',
77
'name' => pht('Changed Task Priority'),
78
),
79
);
80
}
81
82
protected function renderActionEffectDescription($type, $data) {
83
switch ($type) {
84
case self::DO_PRIORITY:
85
return pht(
86
'Changed task priority to "%s".',
87
ManiphestTaskPriority::getTaskPriorityName($data));
88
}
89
}
90
91
}
92
93