AJAX.php
4 months ago
AJAX_Manager.php
2 weeks ago
Archive_Link.php
4 months ago
Clear_Favorite_Report.php
2 weeks ago
Click_Tracking_Cache_Cleared.php
4 months ago
Configure_Pruner.php
4 months ago
Copy_Report.php
4 months ago
Create_Campaign.php
2 years ago
Create_Report.php
4 months ago
Delete_Campaign.php
2 years ago
Delete_Data.php
4 months ago
Delete_Link.php
4 months ago
Delete_Module.php
4 months ago
Delete_Report.php
4 months ago
Dismiss_Notice.php
1 year ago
Edit_Link.php
4 months ago
Edit_Module.php
4 months ago
Export_Report_Statistics.php
2 months ago
Export_Report_Table.php
9 months ago
Export_Reports.php
4 days ago
FetchRealTimeData.php
2 weeks ago
Filter.php
2 months ago
Get_Journey_Timeline.php
6 months ago
Get_Markup_For_Module.php
1 year ago
Get_Markup_For_Modules.php
4 months ago
Import_Reports.php
4 months ago
Migration_Status.php
4 months ago
Pause_Email_Reports.php
4 months ago
Preview_Email.php
2 months ago
Refresh_Modules.php
4 months ago
Rename_Report.php
4 months ago
Reorder_Modules.php
4 months ago
Reset_Analytics.php
4 months ago
Reset_Overview.php
4 months ago
SaveRealTimePreferences.php
4 days ago
Save_Module.php
4 months ago
Save_Report.php
4 months ago
Set_Favorite_Report.php
1 year ago
Set_WooCommerce_Statuses_To_Track.php
4 months ago
Sort_Links.php
4 months ago
Sort_Reports.php
4 months ago
Test_Email.php
2 months ago
Update_Capabilities.php
4 months ago
Update_User_Settings.php
4 months ago
SaveRealTimePreferences.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\AJAX; |
| 4 | |
| 5 | use IAWP\Env; |
| 6 | use IAWP\RealTime\RealTime; |
| 7 | /** @internal */ |
| 8 | class SaveRealTimePreferences extends \IAWP\AJAX\AJAX |
| 9 | { |
| 10 | protected function action_name() : string |
| 11 | { |
| 12 | return 'iawp_save_real_time_preferences'; |
| 13 | } |
| 14 | protected function action_callback() : void |
| 15 | { |
| 16 | $chart_minutes = $this->get_int_field('chartMinutes'); |
| 17 | $table = $this->get_field('table'); |
| 18 | $group = $this->get_field('group'); |
| 19 | if (\is_int($chart_minutes)) { |
| 20 | $this->save_chart_minutes($chart_minutes); |
| 21 | } |
| 22 | if (\is_string($table) && \is_string($group)) { |
| 23 | $this->save_group($table, $group); |
| 24 | } |
| 25 | } |
| 26 | private function save_chart_minutes(int $chart_minutes) : void |
| 27 | { |
| 28 | if (!\in_array($chart_minutes, RealTime::CHART_MINUTES, \true)) { |
| 29 | return; |
| 30 | } |
| 31 | \update_user_meta(\get_current_user_id(), 'iawp_real_time_chart_minutes', $chart_minutes); |
| 32 | } |
| 33 | private function save_group(string $table, string $group) : void |
| 34 | { |
| 35 | // Validate the table and group area real combination |
| 36 | $table_class = Env::get_table($table); |
| 37 | $table_instance = new $table_class($group); |
| 38 | $groups = \get_user_meta(\get_current_user_id(), 'iawp_real_time_groups', \true); |
| 39 | if (!\is_array($groups)) { |
| 40 | $groups = []; |
| 41 | } |
| 42 | $groups[$table_instance->id()] = $table_instance->group()->id(); |
| 43 | $allowed_keys = ['referrers', 'devices', 'geo', 'campaigns']; |
| 44 | $invalid_keys = \array_diff(\array_keys($groups), $allowed_keys); |
| 45 | if (!empty($invalid_keys)) { |
| 46 | return; |
| 47 | } |
| 48 | $sanitized = \array_map('sanitize_text_field', $groups); |
| 49 | \update_user_meta(\get_current_user_id(), 'iawp_real_time_groups', $sanitized); |
| 50 | } |
| 51 | } |
| 52 |