Path: blob/master/src/applications/maniphest/xaction/ManiphestTaskPointsTransaction.php
12256 views
<?php12final class ManiphestTaskPointsTransaction3extends ManiphestTaskTransactionType {45const TRANSACTIONTYPE = 'points';67public function generateOldValue($object) {8return $this->getValueForPoints($object->getPoints());9}1011public function generateNewValue($object, $value) {12return $this->getValueForPoints($value);13}1415public function applyInternalEffects($object, $value) {16$object->setPoints($value);17}1819public function shouldHide() {20if (!ManiphestTaskPoints::getIsEnabled()) {21return true;22}23return false;24}2526public function getTitle() {27$old = $this->getOldValue();28$new = $this->getNewValue();2930if ($old === null) {31return pht(32'%s set the point value for this task to %s.',33$this->renderAuthor(),34$this->renderNewValue());35} else if ($new === null) {36return pht(37'%s removed the point value for this task.',38$this->renderAuthor());39} else {40return pht(41'%s changed the point value for this task from %s to %s.',42$this->renderAuthor(),43$this->renderOldValue(),44$this->renderNewValue());45}46}4748public function getTitleForFeed() {49$old = $this->getOldValue();50$new = $this->getNewValue();5152if ($old === null) {53return pht(54'%s set the point value for %s to %s.',55$this->renderAuthor(),56$this->renderObject(),57$this->renderNewValue());58} else if ($new === null) {59return pht(60'%s removed the point value for %s.',61$this->renderAuthor(),62$this->renderObject());63} else {64return pht(65'%s changed the point value for %s from %s to %s.',66$this->renderAuthor(),67$this->renderObject(),68$this->renderOldValue(),69$this->renderNewValue());70}71}727374public function validateTransactions($object, array $xactions) {75$errors = array();7677foreach ($xactions as $xaction) {78$new = $xaction->getNewValue();79if (strlen($new) && !is_numeric($new)) {80$errors[] = $this->newInvalidError(81pht('Points value must be numeric or empty.'));82continue;83}8485if ((double)$new < 0) {86$errors[] = $this->newInvalidError(87pht('Points value must be nonnegative.'));88continue;89}90}9192return $errors;93}9495public function getIcon() {96return 'fa-calculator';97}9899private function getValueForPoints($value) {100if ($value !== null && !strlen($value)) {101$value = null;102}103if ($value !== null) {104$value = (double)$value;105}106return $value;107}108109public function getTransactionTypeForConduit($xaction) {110return 'points';111}112113public function getFieldValuesForConduit($xaction, $data) {114return array(115'old' => $xaction->getOldValue(),116'new' => $xaction->getNewValue(),117);118}119120121}122123124