Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/xaction/ManiphestTaskPointsTransaction.php
12256 views
1
<?php
2
3
final class ManiphestTaskPointsTransaction
4
extends ManiphestTaskTransactionType {
5
6
const TRANSACTIONTYPE = 'points';
7
8
public function generateOldValue($object) {
9
return $this->getValueForPoints($object->getPoints());
10
}
11
12
public function generateNewValue($object, $value) {
13
return $this->getValueForPoints($value);
14
}
15
16
public function applyInternalEffects($object, $value) {
17
$object->setPoints($value);
18
}
19
20
public function shouldHide() {
21
if (!ManiphestTaskPoints::getIsEnabled()) {
22
return true;
23
}
24
return false;
25
}
26
27
public function getTitle() {
28
$old = $this->getOldValue();
29
$new = $this->getNewValue();
30
31
if ($old === null) {
32
return pht(
33
'%s set the point value for this task to %s.',
34
$this->renderAuthor(),
35
$this->renderNewValue());
36
} else if ($new === null) {
37
return pht(
38
'%s removed the point value for this task.',
39
$this->renderAuthor());
40
} else {
41
return pht(
42
'%s changed the point value for this task from %s to %s.',
43
$this->renderAuthor(),
44
$this->renderOldValue(),
45
$this->renderNewValue());
46
}
47
}
48
49
public function getTitleForFeed() {
50
$old = $this->getOldValue();
51
$new = $this->getNewValue();
52
53
if ($old === null) {
54
return pht(
55
'%s set the point value for %s to %s.',
56
$this->renderAuthor(),
57
$this->renderObject(),
58
$this->renderNewValue());
59
} else if ($new === null) {
60
return pht(
61
'%s removed the point value for %s.',
62
$this->renderAuthor(),
63
$this->renderObject());
64
} else {
65
return pht(
66
'%s changed the point value for %s from %s to %s.',
67
$this->renderAuthor(),
68
$this->renderObject(),
69
$this->renderOldValue(),
70
$this->renderNewValue());
71
}
72
}
73
74
75
public function validateTransactions($object, array $xactions) {
76
$errors = array();
77
78
foreach ($xactions as $xaction) {
79
$new = $xaction->getNewValue();
80
if (strlen($new) && !is_numeric($new)) {
81
$errors[] = $this->newInvalidError(
82
pht('Points value must be numeric or empty.'));
83
continue;
84
}
85
86
if ((double)$new < 0) {
87
$errors[] = $this->newInvalidError(
88
pht('Points value must be nonnegative.'));
89
continue;
90
}
91
}
92
93
return $errors;
94
}
95
96
public function getIcon() {
97
return 'fa-calculator';
98
}
99
100
private function getValueForPoints($value) {
101
if ($value !== null && !strlen($value)) {
102
$value = null;
103
}
104
if ($value !== null) {
105
$value = (double)$value;
106
}
107
return $value;
108
}
109
110
public function getTransactionTypeForConduit($xaction) {
111
return 'points';
112
}
113
114
public function getFieldValuesForConduit($xaction, $data) {
115
return array(
116
'old' => $xaction->getOldValue(),
117
'new' => $xaction->getNewValue(),
118
);
119
}
120
121
122
}
123
124