This commit is contained in:
2025-08-01 14:29:50 +03:00
parent 2ab819ff30
commit b86b8ff923
54 changed files with 1512 additions and 672 deletions

View File

@@ -3,6 +3,7 @@
namespace kernel\modules\option\service;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\modules\option\models\Option;
class OptionService
@@ -49,6 +50,26 @@ class OptionService
return false;
}
public static function createOrUpdate(string $key, string $value, string $label = ''): false|Option
{
/** @var Option $option */
$option = self::getItemObject($key);
if (!$option) {
$option = new Option();
$option->key = $key;
}
$option->value = $value;
if (!empty($label)){
$option->label = $label;
}
if ($option->save()) {
return $option;
}
return false;
}
/**
* @param $key
* @return false|array|string
@@ -63,6 +84,20 @@ class OptionService
return false;
}
/**
* @param $key
* @return false|array|string|Option
*/
public static function getItemObject($key): false|array|string|Option
{
$item = Option::where("key", $key)->first();
if ($item){
return $item;
}
return false;
}
public static function removeOptionByKey(string $key): bool
{
$option = Option::where("key", $key)->first();