You are here

class LingotekPhase in Lingotek Translation 7.6

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

A class representing a Lingotek Workflow Phase.

Hierarchy

Expanded class hierarchy of LingotekPhase

2 string references to 'LingotekPhase'
LingotekDocument::hasPhasesToComplete in lib/Drupal/lingotek/LingotekDocument.php
Determines whether or not the document has Translation Targets in a complete-eligible phase.
lingotek_mark_phases_complete in ./lingotek.page.inc
Form constructor for the lingotek_mark_phases_complete form.

File

lib/Drupal/lingotek/LingotekPhase.php, line 11
Defines LingotekPhase.

View source
class LingotekPhase {

  /**
   * The phase data
   *
   * @var int
   */
  protected $phase;

  /**
   * Constructor.
   *
   * @param object $phase
   *   Phase data as returned by a getPhase API call.
   */
  public function __construct($phase) {
    $this->phase = $phase;
  }

  /**
   * Injects reference to an API object.
   *
   * @param LingotekApi $api
   *   An instantiated Lingotek API object.
   */
  public function setApi(LingotekApi $api) {
    $this->api = $api;
  }

  /**
   * Factory method for getting a loaded LingotekPhase object.
   *
   * @param int $phase_id
   *   A phase ID.
   *
   * @return LingotekPhase
   *   A loaded LingotekPhase object.
   */
  public static function load($phase_id) {
    $api = LingotekApi::instance();
    $api_phase = $api
      ->get_phase($phase_id);
    $phase = new LingotekPhase($api_phase);
    $phase
      ->setApi($api);
    return $phase;
  }

  /**
   * Factory method for getting a loaded LingotekPhase object.
   *
   * @param object $api_phase
   *   Phase data as returned by a getPhase Lingotek API call.
   *
   * @return LingotekPhase
   *   A loaded LingotekPhase object.
   */
  public static function loadWithData($api_phase) {
    $api = LingotekApi::instance();
    $phase = new LingotekPhase($api_phase);
    $phase
      ->setApi($api);
    return $phase;
  }

  /**
   * Determines whether or not the current phase is eligible to be marked as complete.
   *
   * @return bool
   *   TRUE if the phase can be marked as complete. FALSE otherwise.
   */
  public function canBeMarkedComplete() {
    $result = FALSE;

    // These phase types need to be at 100% complete in order to
    // be eligible for mark as complete.
    $needs_100_complete_phase_types = array(
      'TRANSLATION',
      'REVIEW',
    );
    if (in_array($this->phase->type, $needs_100_complete_phase_types)) {
      if ($this->phase->percentComplete == 100 && !$this->phase->isMarkedComplete) {
        $result = TRUE;
      }
    }
    elseif (!$this->phase->isMarkedComplete) {

      // All other phase types should be able to be marked as complete regardless
      // of completion percentage.
      $result = TRUE;
    }
    return $result;
  }

  /**
   * Magic get for phase property access.
   */
  public function __get($property) {
    $value = NULL;
    if (!empty($this->phase->{$property})) {
      $value = $this->phase->{$property};
    }
    return $value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekPhase::$phase protected property The phase data
LingotekPhase::canBeMarkedComplete public function Determines whether or not the current phase is eligible to be marked as complete.
LingotekPhase::load public static function Factory method for getting a loaded LingotekPhase object.
LingotekPhase::loadWithData public static function Factory method for getting a loaded LingotekPhase object.
LingotekPhase::setApi public function Injects reference to an API object.
LingotekPhase::__construct public function Constructor.
LingotekPhase::__get public function Magic get for phase property access.