| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace mikemix\Wiziq\API; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use mikemix\Wiziq\API\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use mikemix\Wiziq\Common\Api\ClassroomApiInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use mikemix\Wiziq\Entity\Classroom; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use mikemix\Wiziq\Entity\PermaClassroom; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class ClassroomApi implements ClassroomApiInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     /** @var Gateway */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     protected $gateway; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 | 3 |  |     public function __construct(Gateway $requester) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 | 3 |  |         $this->gateway = $requester; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 1 |  |     public function create(Classroom $classroom) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 1 |  |         $response = $this->gateway->sendRequest(new Request\Create($classroom)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 1 |  |             'class_id'      => (int)$response->create[0]->class_details[0]->class_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 1 |  |             'recording_url' => (string)$response->create[0]->class_details[0]->recording_url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 1 |  |             'presenters'    => $this->getPresentersFromResponse($response) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 1 |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 1 |  |     public function createPermaClas(PermaClassroom $classroom) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 1 |  |         $response = $this->gateway->sendRequest(new Request\CreatePermaClass($classroom)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 1 |  |         $details  = $response->create_perma_class[0]->perma_class_details[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 1 |  |             'class_id'        => (int)$details->class_master_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |             'attendee_url'    => (string)$details->common_perma_attendee_url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 1 |  |             'presenter_email' => (string)$details->presenter[0]->presenter_email, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  |             'presenter_url'   => (string)$details->presenter[0]->presenter_url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 1 |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @param \SimpleXMLElement $response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 53 | 1 |  |     protected function getPresentersFromResponse(\SimpleXMLElement $response) | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 55 | 1 |  |         $presenters = []; | 
            
                                                        
            
                                    
            
            
                | 56 | 1 |  |         foreach ($response->create[0]->class_details[0]->presenter_list[0] as $presenter) { | 
            
                                                        
            
                                    
            
            
                | 57 | 1 |  |             $presenters[] = [ | 
            
                                                        
            
                                    
            
            
                | 58 | 1 |  |                 'email' => (string)$presenter->presenter_email, | 
            
                                                        
            
                                    
            
            
                | 59 | 1 |  |                 'url'   => (string)$presenter->presenter_url, | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |             ]; | 
            
                                                        
            
                                    
            
            
                | 61 | 1 |  |         } | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 63 | 1 |  |         return $presenters; | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  |