| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Created by PhpStorm. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * User: Matt | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Date: 20/04/2016 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Time: 2:32 PM | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Freshdesk\Resources; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Freshdesk\Resources\Traits\DeleteTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Freshdesk\Resources\Traits\MonitorTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Freshdesk\Resources\Traits\UpdateTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Freshdesk\Resources\Traits\ViewTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * TimeEntry resource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @internal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @package Freshdesk\Resources | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class TimeEntry extends AbstractResource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     use ViewTrait, UpdateTrait, DeleteTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * The time entries resource endpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     protected $endpoint = '/time_entries'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * The tickets resource endpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     private $ticketsEndpoint = '/tickets'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * Creates the forums endpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @param null $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     protected function ticketsEndpoint($id = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return $id == null ? $this->ticketsEndpoint : $this->ticketsEndpoint . '/' . $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * Create a time entry for a ticket | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @param int $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @param array $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @throws \Freshdesk\Exceptions\AccessDeniedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @throws \Freshdesk\Exceptions\ApiException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @throws \Freshdesk\Exceptions\AuthenticationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @throws \Freshdesk\Exceptions\ConflictingStateException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @throws \Freshdesk\Exceptions\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @throws \Freshdesk\Exceptions\RateLimitExceededException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @throws \Freshdesk\Exceptions\MethodNotAllowedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @throws \Freshdesk\Exceptions\ValidationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     public function create($id, array $data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         return $this->api()->request('POST', $this->ticketsEndpoint($id . '/time_entries'), $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * List time entries for a ticket | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @param int $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @param array|null $query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @throws \Freshdesk\Exceptions\AccessDeniedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @throws \Freshdesk\Exceptions\ApiException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @throws \Freshdesk\Exceptions\AuthenticationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @throws \Freshdesk\Exceptions\ConflictingStateException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @throws \Freshdesk\Exceptions\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @throws \Freshdesk\Exceptions\RateLimitExceededException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @throws \Freshdesk\Exceptions\MethodNotAllowedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @throws \Freshdesk\Exceptions\ValidationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function all($id, array $query = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return $this->api()->request('GET', $this->ticketsEndpoint($id . '/time_entries'), null, $query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * Start / stop the timer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @param int $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @throws \Freshdesk\Exceptions\AccessDeniedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * @throws \Freshdesk\Exceptions\ApiException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * @throws \Freshdesk\Exceptions\AuthenticationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @throws \Freshdesk\Exceptions\ConflictingStateException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * @throws \Freshdesk\Exceptions\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * @throws \Freshdesk\Exceptions\RateLimitExceededException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @throws \Freshdesk\Exceptions\MethodNotAllowedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @throws \Freshdesk\Exceptions\ValidationException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |     public function toggle($id) | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |         return $this->api()->request('PUT', $this->endpoint($id)); | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 118 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 119 |  |  |  |