<?php

final class ExtensionStorePublisherStatusTransaction
  extends ExtensionStorePublisherTransactionType {

  const TRANSACTIONTYPE = 'est:publisher:status';

  public function generateOldValue($object) {
    return $object->getStatus();
  }

  public function applyInternalEffects($object, $value) {
    $object->setStatus($value);
  }

  public function getTitle() {
    if (
      $this->getNewValue() == ExtensionStorePublisherStatus::STATUS_ARCHIVED) {
      return pht(
        '%s disabled this Publisher.',
        $this->renderAuthor());
    } else {
      return pht(
        '%s enabled this Publisher.',
        $this->renderAuthor());
    }
  }

  public function getTitleForFeed() {
    if (
      $this->getNewValue() == ExtensionStorePublisherStatus::STATUS_ARCHIVED) {

      return pht(
        '%s disabled the Publisher %s.',
        $this->renderAuthor(),
        $this->renderObject());
    } else {
      return pht(
        '%s enabled the Publisher %s.',
        $this->renderAuthor(),
        $this->renderObject());
    }
  }

  public function getIcon() {
    if (
      $this->getNewValue() == ExtensionStorePublisherStatus::STATUS_ARCHIVED) {
      return 'fa-ban';
    } else {
      return 'fa-check';
    }
  }

}
