2017-05-15 19:23:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ManiphestTaskPointsTransaction
|
|
|
|
extends ManiphestTaskTransactionType {
|
|
|
|
|
|
|
|
const TRANSACTIONTYPE = 'points';
|
|
|
|
|
|
|
|
public function generateOldValue($object) {
|
Generate newValue for ManiphestTaskPointTransaction
Summary: I think this is the correct fix, sets a consistent value for transactions, old and new, for Maniphest point values.
Test Plan:
Edit title, see no point feed story, set points, see point story, set points to same value, see no story, remove points, see remove point story.
{F4958233}
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin
Differential Revision: https://secure.phabricator.com/D17885
2017-05-15 20:16:34 +02:00
|
|
|
return $this->getValueForPoints($object->getPoints());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generateNewValue($object, $value) {
|
|
|
|
return $this->getValueForPoints($value);
|
2017-05-15 19:23:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function applyInternalEffects($object, $value) {
|
|
|
|
$object->setPoints($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldHide() {
|
|
|
|
if (!ManiphestTaskPoints::getIsEnabled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitle() {
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
if ($old === null) {
|
|
|
|
return pht(
|
|
|
|
'%s set the point value for this task to %s.',
|
|
|
|
$this->renderAuthor(),
|
|
|
|
$this->renderNewValue());
|
|
|
|
} else if ($new === null) {
|
|
|
|
return pht(
|
|
|
|
'%s removed the point value for this task.',
|
|
|
|
$this->renderAuthor());
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s changed the point value for this task from %s to %s.',
|
|
|
|
$this->renderAuthor(),
|
|
|
|
$this->renderOldValue(),
|
|
|
|
$this->renderNewValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-25 22:03:41 +02:00
|
|
|
public function getTitleForFeed() {
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
if ($old === null) {
|
|
|
|
return pht(
|
|
|
|
'%s set the point value for %s to %s.',
|
|
|
|
$this->renderAuthor(),
|
|
|
|
$this->renderObject(),
|
|
|
|
$this->renderNewValue());
|
|
|
|
} else if ($new === null) {
|
|
|
|
return pht(
|
|
|
|
'%s removed the point value for %s.',
|
|
|
|
$this->renderAuthor(),
|
|
|
|
$this->renderObject());
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s changed the point value for %s from %s to %s.',
|
|
|
|
$this->renderAuthor(),
|
|
|
|
$this->renderObject(),
|
|
|
|
$this->renderOldValue(),
|
|
|
|
$this->renderNewValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-15 19:23:20 +02:00
|
|
|
public function validateTransactions($object, array $xactions) {
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
$new = $xaction->getNewValue();
|
|
|
|
if (strlen($new) && !is_numeric($new)) {
|
|
|
|
$errors[] = $this->newInvalidError(
|
|
|
|
pht('Points value must be numeric or empty.'));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((double)$new < 0) {
|
|
|
|
$errors[] = $this->newInvalidError(
|
|
|
|
pht('Points value must be nonnegative.'));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
2017-05-16 21:38:11 +02:00
|
|
|
public function getIcon() {
|
|
|
|
return 'fa-calculator';
|
|
|
|
}
|
|
|
|
|
2023-05-23 11:56:26 +02:00
|
|
|
/**
|
|
|
|
* Normalize your Story Points from generic stuff to double or null.
|
|
|
|
* @param mixed $value Your raw Story Points
|
|
|
|
* @return double|null
|
|
|
|
*/
|
Generate newValue for ManiphestTaskPointTransaction
Summary: I think this is the correct fix, sets a consistent value for transactions, old and new, for Maniphest point values.
Test Plan:
Edit title, see no point feed story, set points, see point story, set points to same value, see no story, remove points, see remove point story.
{F4958233}
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin
Differential Revision: https://secure.phabricator.com/D17885
2017-05-15 20:16:34 +02:00
|
|
|
private function getValueForPoints($value) {
|
2023-05-23 11:56:26 +02:00
|
|
|
// The Point can be various types also thanks to Conduit API
|
|
|
|
// like integers, floats, null, and strings of course.
|
|
|
|
// Everything meaningful must be printable as a string.
|
|
|
|
$is_empty = phutil_string_cast($value) === '';
|
|
|
|
if ($is_empty) {
|
Generate newValue for ManiphestTaskPointTransaction
Summary: I think this is the correct fix, sets a consistent value for transactions, old and new, for Maniphest point values.
Test Plan:
Edit title, see no point feed story, set points, see point story, set points to same value, see no story, remove points, see remove point story.
{F4958233}
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin
Differential Revision: https://secure.phabricator.com/D17885
2017-05-15 20:16:34 +02:00
|
|
|
$value = null;
|
|
|
|
}
|
|
|
|
if ($value !== null) {
|
|
|
|
$value = (double)$value;
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2017-11-06 19:25:37 +01:00
|
|
|
public function getTransactionTypeForConduit($xaction) {
|
|
|
|
return 'points';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldValuesForConduit($xaction, $data) {
|
|
|
|
return array(
|
|
|
|
'old' => $xaction->getOldValue(),
|
|
|
|
'new' => $xaction->getNewValue(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-15 19:23:20 +02:00
|
|
|
}
|