| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BristolSU\Module\StaticPage\Events; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use BristolSU\Module\StaticPage\Models\ButtonClick; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use BristolSU\Module\StaticPage\Models\PageView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use BristolSU\Support\Action\Contracts\TriggerableEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use BristolSU\Support\ModuleInstance\Contracts\ModuleInstanceRepository; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | class ButtonSubmitted implements TriggerableEvent | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |      * @var ButtonClick | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     private $buttonClick; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 5 |  |     public function __construct(ButtonClick $buttonClick) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 | 5 |  |         $this->buttonClick = $buttonClick; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 | 5 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      * Register metadata about the fields the event supplies. | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * For each field returned in getFields, pass in a label and a helptext. | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      * e.g. [ | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      *      'user_id' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      *          'label' => 'User ID', | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      *          'helptext' => 'The ID of the user who posted the comment.' | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      *          ], | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      *      ... | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * ] | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * @return array | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 | 1 |  |     public static function getFieldMetaData(): array | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |           'user_id' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 42 | 1 |  |             'label' => 'User ID', | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             'helptext' => 'The ID of the user' | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |           'user_email' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             'label' => 'Email Address', | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |             'helptext' => 'Email Address of the user. May be empty.' | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |           'user_first_name' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             'label' => 'First Name', | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             'helptext' => 'First Name of the user. May be empty.' | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |           'user_last_name' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             'label' => 'Last Name', | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |             'helptext' => 'Last Name of the user. May be empty.' | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |           'user_preferred_name' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |             'label' => 'Preferred Name', | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |             'helptext' => 'Preferred Name of the user. May be empty.' | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |           'module_instance_id' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             'label' => 'Module Instance ID', | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |             'helptext' => 'ID of the module instance viewed' | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |           'module_instance_name' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |             'label' => 'Module Instance Name', | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |             'helptext' => 'Name of the module instance viewed.' | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |           'activity_instance_id' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |             'label' => 'Activity Instance ID', | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |             'helptext' => 'The id of the activity instance viewed.' | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |           'activity_instance_name' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |             'label' => 'Activity Instance Name', | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |             'helptext' => 'The name of the activity instance viewed.' | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |           'clicked_at' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |             'label' => 'Button Clicked At', | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |             'helptext' => 'The date and time the button was clicked at' | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |           ], | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |      * Get the fields that the event registers. | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |      * If the event has parameters which should be used in the framework, return them here. | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |      * e.g. [ | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |      *      'user_id' => 1, | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |      *      'comment_id' => 4, | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |      *      'post_id' => 3 | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |      * ] | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |      * @return array | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 2 |  |     public function getFields(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 2 |  |         $moduleInstance = app(ModuleInstanceRepository::class)->getById($this->buttonClick->module_instance_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 2 |  |         $activityInstance = app(ActivityInstanceRepository::class)->getById($this->buttonClick->activity_instance_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 2 |  |           'user_id' => $this->buttonClick->user->id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 2 |  |           'user_email' => $this->buttonClick->user->data()->email(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 2 |  |           'user_first_name' => $this->buttonClick->user->data()->firstName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 2 |  |           'user_last_name' => $this->buttonClick->user->data()->lastName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 2 |  |           'user_preferred_name' => $this->buttonClick->user->data()->preferredName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 2 |  |           'clicked_at' => $this->buttonClick->created_at->format('Y-m-d H:i:s'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 2 |  |           'module_instance_id' => $moduleInstance->id, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 2 |  |           'module_instance_name' => $moduleInstance->name, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 2 |  |           'activity_instance_id' => $activityInstance->id, | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 110 | 2 |  |           'activity_instance_name' => $activityInstance->name, | 
            
                                                                        
                                                                
            
                                    
            
            
                | 111 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |  |