chg:[userSetting] Functions for easier manipulation of user settings

pull/72/head
Sami Mokaddem 2021-10-08 16:51:10 +02:00
parent 79f4bc3c6b
commit 0b9b54f14a
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 31 additions and 1 deletions

View File

@ -26,4 +26,34 @@ class UserSettingsTable extends AppTable
->notEmptyString('user_id', __('Please supply the user id to which this setting belongs to'));
return $validator;
}
}
public function getSettingByName($user, $name)
{
return $this->find()->where([
'user_id' => $user->id,
'name' => $name,
])->first();
}
public function createSetting($user, $name, $value)
{
$setting = $this->newEmptyEntity();
$data = [
'name' => $name,
'value' => $value,
'user_id' => $user->id,
];
$setting = $this->patchEntity($setting, $data);
$savedData = $this->save($setting);
return $savedData;
}
public function editSetting($user, $name, $value)
{
$setting = $this->getSettingByName($user, $name);
$setting = $this->patchEntity($setting, [
'value' => $value
]);
$savedData = $this->save($setting);
return $savedData;
}