Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / maniphest / xaction / ManiphestTaskPointsTransaction.php
blob2037a7112769b78f4dd851355ee291361eda133a
1 <?php
3 final class ManiphestTaskPointsTransaction
4 extends ManiphestTaskTransactionType {
6 const TRANSACTIONTYPE = 'points';
8 public function generateOldValue($object) {
9 return $this->getValueForPoints($object->getPoints());
12 public function generateNewValue($object, $value) {
13 return $this->getValueForPoints($value);
16 public function applyInternalEffects($object, $value) {
17 $object->setPoints($value);
20 public function shouldHide() {
21 if (!ManiphestTaskPoints::getIsEnabled()) {
22 return true;
24 return false;
27 public function getTitle() {
28 $old = $this->getOldValue();
29 $new = $this->getNewValue();
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());
49 public function getTitleForFeed() {
50 $old = $this->getOldValue();
51 $new = $this->getNewValue();
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());
75 public function validateTransactions($object, array $xactions) {
76 $errors = array();
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;
86 if ((double)$new < 0) {
87 $errors[] = $this->newInvalidError(
88 pht('Points value must be nonnegative.'));
89 continue;
93 return $errors;
96 public function getIcon() {
97 return 'fa-calculator';
100 private function getValueForPoints($value) {
101 if ($value !== null && !strlen($value)) {
102 $value = null;
104 if ($value !== null) {
105 $value = (double)$value;
107 return $value;
110 public function getTransactionTypeForConduit($xaction) {
111 return 'points';
114 public function getFieldValuesForConduit($xaction, $data) {
115 return array(
116 'old' => $xaction->getOldValue(),
117 'new' => $xaction->getNewValue(),