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