|
@@ -29,27 +29,38 @@ class LuticateSettingsUsersBusiness extends LuBusiness {
|
29
|
29
|
return LuticateSettingsUsersDataAccess::getAllByUser($user_id, $page, $perPage);
|
30
|
30
|
}
|
31
|
31
|
|
32
|
|
- public static function edit($user_id, $setting_name, $setting_value)
|
|
32
|
+ /**
|
|
33
|
+ * @param $user_setting LuticateSettingsUsersDbo
|
|
34
|
+ * @param $admin_edit bool
|
|
35
|
+ * @return bool
|
|
36
|
+ */
|
|
37
|
+ public static function edit($user_setting, $admin_edit)
|
33
|
38
|
{
|
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
|
+ LuticateUsersBusiness::checkUserId($user_setting->getUserId());
|
|
40
|
+ $setting = LuticateSettingsBusiness::checkSettingName($user_setting->getName());
|
|
41
|
+ if ($setting->getIsBlocked() && !$admin_edit) {
|
|
42
|
+ self::unauthorized("Setting is blocked");
|
|
43
|
+ }
|
|
44
|
+ if (is_null($user_setting->getValue())) {
|
|
45
|
+ LuticateSettingsUsersDataAccess::delete($user_setting->getUserId(), $user_setting->getName());
|
39
|
46
|
} else {
|
40
|
|
- $setting->setValue($setting_value);
|
|
47
|
+ $setting->setValue($user_setting->getValue());
|
41
|
48
|
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
|
+ $user_setting->setValue(json_encode($user_setting->getValue()));
|
|
50
|
+ $real_user_setting = LuticateSettingsUsersDataAccess::getByName($user_setting->getUserId(), $user_setting->getName());
|
|
51
|
+ if (is_null($real_user_setting)) {
|
|
52
|
+ if (is_null($user_setting->getIsBlocked())) {
|
|
53
|
+ $user_setting->setIsBlocked(false);
|
|
54
|
+ }
|
49
|
55
|
LuticateSettingsUsersDataAccess::add($user_setting);
|
50
|
56
|
}
|
51
|
57
|
else {
|
52
|
|
- $user_setting->setValue($setting_value);
|
|
58
|
+ if ($real_user_setting->getIsBlocked() && !$admin_edit) {
|
|
59
|
+ self::unauthorized("User setting is blocked");
|
|
60
|
+ }
|
|
61
|
+ if (is_null($user_setting->getIsBlocked())) {
|
|
62
|
+ $user_setting->setIsBlocked($real_user_setting->getIsBlocked());
|
|
63
|
+ }
|
53
|
64
|
LuticateSettingsUsersDataAccess::edit($user_setting);
|
54
|
65
|
}
|
55
|
66
|
}
|