| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright 2017 Vladimir Jimenez | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license   https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | namespace allejo\DaPulse\Objects; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use allejo\DaPulse\Exceptions\ColumnNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use allejo\DaPulse\Exceptions\HttpException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use allejo\DaPulse\Exceptions\InvalidObjectException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use allejo\DaPulse\PulseColumn; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * The base class used for column values belonging to a specified class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @internal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @package allejo\DaPulse\Objects | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @since   0.1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | abstract class PulseColumnValue extends ApiObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     const API_PREFIX = "boards"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * The default return value for getValue() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @internal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     const DEFAULT_VALUE = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * The ID of the parent board that this column's Pulse belongs to. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     protected $board_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * The ID of the current column. This is a unique identifier when accessing columns through the API. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     protected $column_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * The ID of the Pulse this column value belongs to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @var int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     protected $pulse_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * The value that this column has. The data type can be an integer, string, or DateTime depending on the column type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @var mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     protected $column_value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * This constructor only accepts an array of the data regarding a specific column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @internal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @param array $array An associative array containing information regarding a column's value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @since 0.1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @throws \InvalidArgumentException An ID is given when an instance of this object can only be created from an | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 38 |  |      *                                   array of existing data | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 38 |  |     public function __construct ($array) | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 75 | 38 |  |         $this->arrayConstructionOnly = true; | 
            
                                                                        
                            
            
                                    
            
            
                | 76 | 38 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |         parent::__construct($array); | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * This function must be overloaded by child classes solely calling this function to allow each implementation to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 17 |  |      * have its own phpDocs. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 17 |  |     public function getValue () | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 7 |  |         $this->lazyLoad(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         if ($this->isNullValue()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 13 |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             return static::DEFAULT_VALUE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 6 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         if (!isset($this->column_value)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 13 |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             $this->setValue($this->jsonResponse); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         return $this->column_value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * Create the appropriate object based on the type of column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * @internal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * @param string $type The type of column as specified by DaPulse's API; i.e. 'text', 'date', 'status', 'person' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * @param array  $data An associative array containing data regarding the column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @since 0.1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @todo  Fix the hardcoded "color" case statement. See: https://github.com/allejo/PhpPulse/issues/5 | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 39 |  |      * @throws InvalidObjectException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * @return PulseColumnStatusValue|PulseColumnDateValue|PulseColumnNumericValue|PulseColumnPersonValue|PulseColumnTextValue|PulseColumnTimelineValue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 39 |  |     public static function _createColumnType ($type, $data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 4 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         switch ($type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 35 |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 35 |  |             case PulseColumn::Text: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 6 |  |                 return (new PulseColumnTextValue($data)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 29 |  |             case "color": | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 | 7 |  |             case PulseColumn::Status: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                 return (new PulseColumnStatusValue($data)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 22 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 9 |  |             case PulseColumn::Numeric: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                 return (new PulseColumnNumericValue($data)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 13 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 | 7 |  |             case PulseColumn::Person: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                 return (new PulseColumnPersonValue($data)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 6 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 5 |  |             case PulseColumn::Date: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                 return (new PulseColumnDateValue($data)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 | 1 |  |             case PulseColumn::Timeline: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                 return (new PulseColumnTimelineValue($data)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         throw new InvalidObjectException("'$type' is an unsupported column type to modify."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 17 |  |      * Check whether to return null because a column's value does not exist. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 | 17 |  |      * @return bool True if the column does not have a value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     protected function isNullValue () | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         return (is_null($this->jsonResponse["value"]) && !isset($this->column_value)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     protected function lazyLoad () | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         if (!array_key_exists('value', $this->jsonResponse)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             $url    = sprintf("%s/%d/columns/%s/value.json", self::apiEndpoint("boards"), $this->board_id, $this->column_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |                 "pulse_id" => $this->pulse_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             try | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |                 $results = self::sendGet($url, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             catch (HttpException $e) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |                 throw new ColumnNotFoundException("The '$this->column_id' column could not be found"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |             // Store our value inside of jsonResponse so all of the respective objects can treat the data the same | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |             // as when accessed through a PulseBoard | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             $this->jsonResponse['value'] = $results['value']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * Cast and set the appropriate value for this column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * @param $response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      */ | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 183 |  |  |     abstract protected function setValue ($response); | 
            
                                                        
            
                                    
            
            
                | 184 |  |  | } | 
            
                        
This check looks
TODOcomments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.