| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace AppBundle\Services; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | class GoogleCalendarManager implements GoogleCalendarInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     private $calendar; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     public function __construct(GoogleClientFactory $factory) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         $this->calendar = $factory->createCalendar('default', 'reader'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     public function createEvent($data = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $event = new \Google_Service_Calendar_Event(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $event->setSummary($data['title']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $event->setDescription($data['description']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $event->setLocation($data['location']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $event->setVisibility('public'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $start = new \Google_Service_Calendar_EventDateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $start->setDateTime($data['start']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $event->setStart($start); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $end = new \Google_Service_Calendar_EventDateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $end->setDateTime($data['end']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $event->setEnd($end); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         return $this->calendar->events->insert('primary', $event); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function getEventList($calendarId = 'primary') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         return $this->calendar | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |            ->events | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |            ->listEvents($calendarId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |            ->getItems(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     public function getEventById($id) | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         return $this->calendar->events->get('primary', $id); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     public function deleteEvent($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         return $this->calendar->events->delete('primary', $id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function editEvent($id, $data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $event = $this->getEventById($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $event->setSummary($data['title']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $event->setDescription($data['description']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $event->setLocation($data['location']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $event->setVisibility('public'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $start = new \Google_Service_Calendar_EventDateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $start->setDateTime($data['start']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $event->setStart($start); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $end = new \Google_Service_Calendar_EventDateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $end->setDateTime($data['end']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $event->setEnd($end); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         return $this->calendar->events->patch('primary', $id, $event); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function clear() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $events = $this->getEventList(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         foreach ($events as $event) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             $this->deleteEvent($event->getId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |  |