Many fixes
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
/**
|
||||
* Модель настроек модулей
|
||||
*
|
||||
* Хранит переопределённые настройки модулей в БД.
|
||||
*/
|
||||
class ModuleSettingsModel extends Model
|
||||
{
|
||||
protected $table = 'module_settings';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $allowedFields = [
|
||||
'module_code',
|
||||
'name',
|
||||
'description',
|
||||
'price_monthly',
|
||||
'price_yearly',
|
||||
'trial_days',
|
||||
'is_active',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
protected $useTimestamps = false;
|
||||
|
||||
/**
|
||||
* Получение настроек модуля по коду
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @return array|null
|
||||
*/
|
||||
public function getByModuleCode(string $moduleCode): ?array
|
||||
{
|
||||
return $this->where('module_code', $moduleCode)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновление или создание настроек модуля
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function upsert(string $moduleCode, array $data): bool
|
||||
{
|
||||
$existing = $this->getByModuleCode($moduleCode);
|
||||
|
||||
$data['module_code'] = $moduleCode;
|
||||
$data['updated_at'] = date('Y-m-d H:i:s');
|
||||
|
||||
if ($existing) {
|
||||
return $this->update($existing['id'], $data);
|
||||
}
|
||||
|
||||
$data['created_at'] = date('Y-m-d H:i:s');
|
||||
return $this->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение всех активных настроек модулей
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllActive(): array
|
||||
{
|
||||
return $this->where('is_active', 1)->findAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user