|
@@ -17,7 +17,11 @@ class LuticateSettingsUsersBusiness extends LuBusiness {
|
17
|
17
|
{
|
18
|
18
|
LuticateUsersBusiness::checkUserId($user_id);
|
19
|
19
|
LuticateSettingsBusiness::checkSettingName($setting_name);
|
20
|
|
- return LuticateSettingsUsersDataAccess::getByName($user_id, $setting_name);
|
|
20
|
+ $setting = LuticateSettingsUsersDataAccess::getByName($user_id, $setting_name);
|
|
21
|
+ if (is_null($setting)) {
|
|
22
|
+ self::notFound("User setting not found");
|
|
23
|
+ }
|
|
24
|
+ return $setting;
|
21
|
25
|
}
|
22
|
26
|
|
23
|
27
|
public static function getAllByUser($user_id, $page = 0, $perPage = 2000000000)
|
|
@@ -25,35 +29,30 @@ class LuticateSettingsUsersBusiness extends LuBusiness {
|
25
|
29
|
return LuticateSettingsUsersDataAccess::getAllByUser($user_id, $page, $perPage);
|
26
|
30
|
}
|
27
|
31
|
|
28
|
|
- public static function get($user_id, $setting_name)
|
29
|
|
- {
|
30
|
|
- return LuticateSettingsUsersDataAccess::getByName($user_id, $setting_name);
|
31
|
|
- }
|
32
|
|
-
|
33
|
|
- public static function add($user_id, $setting_name, $setting_value)
|
|
32
|
+ public static function edit($user_id, $setting_name, $setting_value)
|
34
|
33
|
{
|
35
|
|
- $setting = self::checkSettingUserName($user_id, $setting_name);
|
36
|
|
- if (!is_null($setting)) {
|
37
|
|
- self::badInput("User setting already exists");
|
|
34
|
+ $setting_value = json_decode($setting_value);
|
|
35
|
+ LuticateUsersBusiness::checkUserId($user_id);
|
|
36
|
+ $setting = LuticateSettingsBusiness::checkSettingName($setting_name);
|
|
37
|
+ if (is_null($setting_value)) {
|
|
38
|
+ LuticateSettingsUsersDataAccess::delete($user_id, $setting_name);
|
|
39
|
+ } else {
|
|
40
|
+ $setting->setValue($setting_value);
|
|
41
|
+ LuticateSettingsBusiness::checkSetting($setting);
|
|
42
|
+ $setting_value = json_encode($setting_value);
|
|
43
|
+ $user_setting = LuticateSettingsUsersDataAccess::getByName($user_id, $setting_name);
|
|
44
|
+ if (is_null($user_setting)) {
|
|
45
|
+ $user_setting = new LuticateSettingsUsersDbo();
|
|
46
|
+ $user_setting->setName($setting_name);
|
|
47
|
+ $user_setting->setValue($setting_value);
|
|
48
|
+ $user_setting->setUserId($user_id);
|
|
49
|
+ LuticateSettingsUsersDataAccess::add($user_setting);
|
|
50
|
+ }
|
|
51
|
+ else {
|
|
52
|
+ $user_setting->setValue($setting_value);
|
|
53
|
+ LuticateSettingsUsersDataAccess::edit($user_setting);
|
|
54
|
+ }
|
38
|
55
|
}
|
39
|
|
- $setting = new LuticateSettingsUsersDbo();
|
40
|
|
- $setting->setName($setting_name);
|
41
|
|
- $setting->setValue($setting_value);
|
42
|
|
- $setting->setUserId($user_id);
|
43
|
|
- LuticateSettingsUsersDataAccess::add($setting);
|
44
|
|
- return true;
|
45
|
|
- }
|
46
|
|
-
|
47
|
|
- public static function del($user_id, $setting_name)
|
48
|
|
- {
|
49
|
|
- self::checkSettingUserName($user_id, $setting_name);
|
50
|
|
- LuticateSettingsUsersDataAccess::delete($user_id, $setting_name);
|
51
|
56
|
return true;
|
52
|
57
|
}
|
53
|
|
-
|
54
|
|
- public static function edit($user_id, $setting_name, $setting_value)
|
55
|
|
- {
|
56
|
|
- self::del($user_id, $setting_name);
|
57
|
|
- return self::add($user_id, $setting_name, $setting_value);
|
58
|
|
- }
|
59
|
58
|
}
|