PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / Settings / SettingsService.php

SettingsService.php in The Innovative Form Builder – IvyForms 1.0, at backend/src/Services/Settings/SettingsService.php

164 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Settings hook for settings
5 */
6
7 namespace IvyForms\Services\Settings;
8
9 /**
10 * Class SettingsService
11 *
12 * @package IvyForms\Services\Settings
13 */
14 class SettingsService
15 {
16 /** @var array|mixed */
17 private $settingsCache;
18
19 /**
20 * @var array<string, string> // Define that both keys and values are strings
21 * */
22 private static array $wpSettings = [
23 'dateFormat' => 'date_format',
24 'timeFormat' => 'time_format',
25 'startOfWeek' => 'start_of_week',
26 'timeZoneString' => 'timezone_string',
27 'gmtOffset' => 'gmt_offset'
28 ];
29
30 /**
31 * SettingsService constructor.
32 */
33 public function __construct()
34 {
35 $this->settingsCache = json_decode(get_option('ivyforms_settings'), true);
36
37 foreach (self::$wpSettings as $setting => $wpSetting) {
38 $this->settingsCache['wordpress'][$setting] = get_option($wpSetting);
39 }
40 }
41
42 /**
43 * @param string $settingCategoryKey
44 * @param string $settingKey
45 *
46 * @return mixed
47 */
48 public function getSetting(string $settingCategoryKey, string $settingKey)
49 {
50 return $this->settingsCache[$settingCategoryKey][$settingKey] ?? null;
51 }
52
53 /**
54 * @param string $settingCategoryKey
55 *
56 * @return mixed
57 */
58 public function getCategorySettings(string $settingCategoryKey)
59 {
60 return $this->settingsCache[$settingCategoryKey] ?? null;
61 }
62
63 /**
64 * @return mixed[]
65 */
66 public function getAllSettings(): array
67 {
68 return $this->settingsCache;
69 }
70
71 /**
72 * Return settings for frontend
73 *
74 * @return mixed[]
75 */
76 public function getFrontendSettings(): array
77 {
78 // $capabilities = [];
79 //
80 // if (is_admin()) {
81 // $currentScreenId = get_current_screen()->id;
82 //
83 // $currentScreen = substr($currentScreenId, strrpos($currentScreenId, '-') + 1);
84 //
85 // $capabilities = [
86 // 'canRead' => current_user_can('ivyforms_read_' . $currentScreen),
87 // 'canReadOthers' => current_user_can('ivyforms_read_others_' . $currentScreen),
88 // 'canWrite' => current_user_can('ivyforms_write_' . $currentScreen),
89 // 'canWriteOthers' => current_user_can('ivyforms_write_others_' . $currentScreen),
90 // 'canDelete' => current_user_can('ivyforms_delete_' . $currentScreen),
91 // 'canWriteStatus' => current_user_can('ivyforms_write_status_' . $currentScreen),
92 // ];
93 // }
94
95 return [
96 //'capabilities' => $capabilities,
97 'general' => [
98 'fullscreen' => $this->getSetting('general', 'fullscreen'),
99 ],
100 'wordpress' => [
101 'dateFormat' => $this->getSetting('wordpress', 'dateFormat'),
102 'timeFormat' => $this->getSetting('wordpress', 'timeFormat'),
103 'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'),
104 'timezone' => $this->getSetting('wordpress', 'timeZoneString'),
105 ],
106 ];
107 }
108
109 /**
110 * @param string $settingCategoryKey
111 * @param string $settingKey
112 * @param mixed $settingValue
113 *
114 * @return void
115 */
116 public function setSetting(string $settingCategoryKey, string $settingKey, $settingValue)
117 {
118 $this->settingsCache[$settingCategoryKey][$settingKey] = $settingValue;
119
120 $settingsCopy = $this->settingsCache;
121
122 unset($settingsCopy['wordpress']);
123
124 update_option('ivyforms_settings', json_encode($settingsCopy));
125 }
126
127 /**
128 * @param string $settingCategoryKey
129 * @param mixed $settingValue
130 *
131 * @return void
132 */
133 public function setCategorySettings(string $settingCategoryKey, $settingValue)
134 {
135 $this->settingsCache[$settingCategoryKey] = $settingValue;
136
137 $settingsCopy = $this->settingsCache;
138
139 unset($settingsCopy['wordpress']);
140
141 update_option('ivyforms_settings', json_encode($settingsCopy));
142 }
143
144 /**
145 * Get all settings
146 *
147 * Specify that $settings is an associative array with string keys and mixed values
148 * @param array<string, mixed> $settings
149 *
150 */
151 public function setAllSettings(array $settings): void
152 {
153 foreach ($settings as $settingCategoryKey => $settingValues) {
154 $this->settingsCache[$settingCategoryKey] = $settingValues;
155 }
156
157 $settingsCopy = $this->settingsCache;
158
159 unset($settingsCopy['wordpress']);
160
161 update_option('ivyforms_settings', json_encode($settingsCopy));
162 }
163 }
164