You are here

class LingotekAccount in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lib/Drupal/lingotek/LingotekAccount.php \LingotekAccount
  2. 7.2 lib/Drupal/lingotek/LingotekAccount.php \LingotekAccount
  3. 7.3 lib/Drupal/lingotek/LingotekAccount.php \LingotekAccount
  4. 7.4 lib/Drupal/lingotek/LingotekAccount.php \LingotekAccount
  5. 7.5 lib/Drupal/lingotek/LingotekAccount.php \LingotekAccount

A class representing a Lingotek Account

The Account class works off a locally cached copy of the account information, so it doesnt have to query the billing server very often.

Hierarchy

Expanded class hierarchy of LingotekAccount

File

lib/Drupal/lingotek/LingotekAccount.php, line 13
Defines LingotekAccount.

View source
class LingotekAccount {
  const NOT_FOUND = 'not_found';
  const ACTIVE = 'active';
  const UNKNOWN = 'unknown';
  const NONE = 'none';
  const ADVANCED = 'advanced';

  /**
   * Holds the static instance of the singleton object.
   *
   * @var LingotekAccount
   */
  private static $instance;
  private $status;
  private $plan;
  private $planType;

  /**
   * Constructor.
   *
   * Sets default values
   */
  public function __construct() {
    $this->status = self::UNKNOWN;
    $this->planType = self::UNKNOWN;

    // assume an standard active account
    $current_status = variable_get('lingotek_account_status', self::ACTIVE);
    $current_plan_type = variable_get('lingotek_account_plan_type', 'standard');
    if (isset($current_status) && isset($current_plan_type)) {
      $this
        ->setStatus($current_status);
      $this
        ->setPlanType($current_plan_type);
    }
  }

  /**
   * Gets the singleton instance of the Account class.
   *
   * @return LingotekAccount
   *   An instantiated LingotekAccount object.
   */
  public static function instance() {
    if (!isset(self::$instance)) {
      $class_name = __CLASS__;
      self::$instance = new $class_name();
    }
    return self::$instance;
  }
  public function setStatus($value = 'inactive') {
    $this->status = $value;
  }
  public function getStatus() {
    return $this->status;
  }
  public function getStatusText() {
    return $this->status == 'active' ? '<span style="color: green;">' . t('Active') . '</span>' : '<span style="color: red;">' . t('Inactive') . '</span>';
  }
  public function setPlan($plan) {
    $this->plan = $plan;
    if (is_object($plan) && isset($plan->type)) {
      $this
        ->setPlanType($plan->type);
    }
  }
  public function getPlan() {
    return $this->plan;
  }
  public function setPlanType($type = 'unknown') {
    variable_set('lingotek_account_plan_type', $type);
    $standard_types = array(
      'cosmopolitan_monthly',
      'cosmopolitan_yearly',
    );

    // if in this list, then set to 'standard'
    $type = in_array($type, $standard_types) ? 'standard' : $type;
    $this->planType = $type;
  }
  public function getPlanType() {
    return $this->planType;
  }
  public function isPlanType($type) {

    // isPlanType type values: 'advanced', 'standard'
    $account_type = $this
      ->getPlanType();
    return strcasecmp($type, $account_type) == 0;
  }
  public function getPlanTypeText() {
    $plan_pieces = explode('_', $this
      ->getPlanType());
    $details = ucwords(end($plan_pieces));

    // e.g., Enterprise, Monthly, Yearly
    return $details;
  }
  public function showAdvanced() {
    return $this
      ->isPlanType(self::ADVANCED);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekAccount::$instance private static property Holds the static instance of the singleton object.
LingotekAccount::$plan private property
LingotekAccount::$planType private property
LingotekAccount::$status private property
LingotekAccount::ACTIVE constant
LingotekAccount::ADVANCED constant
LingotekAccount::getPlan public function
LingotekAccount::getPlanType public function
LingotekAccount::getPlanTypeText public function
LingotekAccount::getStatus public function
LingotekAccount::getStatusText public function
LingotekAccount::instance public static function Gets the singleton instance of the Account class.
LingotekAccount::isPlanType public function
LingotekAccount::NONE constant
LingotekAccount::NOT_FOUND constant
LingotekAccount::setPlan public function
LingotekAccount::setPlanType public function
LingotekAccount::setStatus public function
LingotekAccount::showAdvanced public function
LingotekAccount::UNKNOWN constant
LingotekAccount::__construct public function Constructor.