3 final class AlmanacDeviceStatusTransaction
4 extends AlmanacDeviceTransactionType
{
6 const TRANSACTIONTYPE
= 'almanac:device:status';
8 public function generateOldValue($object) {
9 return $object->getStatus();
12 public function applyInternalEffects($object, $value) {
13 $object->setStatus($value);
16 public function getTitle() {
17 $old_value = $this->getOldValue();
18 $new_value = $this->getNewValue();
20 $old_status = AlmanacDeviceStatus
::newStatusFromValue($old_value);
21 $new_status = AlmanacDeviceStatus
::newStatusFromValue($new_value);
23 $old_name = $old_status->getName();
24 $new_name = $new_status->getName();
27 '%s changed the status of this device from %s to %s.',
28 $this->renderAuthor(),
29 $this->renderValue($old_name),
30 $this->renderValue($new_name));
33 public function validateTransactions($object, array $xactions) {
36 $status_map = AlmanacDeviceStatus
::getStatusMap();
38 $old_value = $this->generateOldValue($object);
39 foreach ($xactions as $xaction) {
40 $new_value = $xaction->getNewValue();
42 if ($new_value === $old_value) {
46 if (!isset($status_map[$new_value])) {
47 $errors[] = $this->newInvalidError(
49 'Almanac device status "%s" is unrecognized. Valid status '.
52 implode(', ', array_keys($status_map))),