summaryrefslogtreecommitdiffstats
path: root/lib/Drupal/lingotek/LingotekPhase.php
blob: 73278e08355add9613ee0084a64dcf5792486779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php

/**
 * @file
 * Defines LingotekPhase.
 */
 
/**
 * A class representing a Lingotek Workflow Phase.
 */
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;
  }
}