Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SystemStateModel | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| getState | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setState | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| removeState | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use CodeIgniter\Model; |
| 6 | |
| 7 | class SystemStateModel extends Model |
| 8 | { |
| 9 | protected $table = 'system_state'; |
| 10 | protected $primaryKey = 'id'; |
| 11 | |
| 12 | protected $allowedFields = [ |
| 13 | 'state_key', |
| 14 | 'state_value', |
| 15 | 'updated_at', |
| 16 | ]; |
| 17 | |
| 18 | protected $useTimestamps = false; |
| 19 | |
| 20 | /** |
| 21 | * Récupère une valeur système |
| 22 | */ |
| 23 | public function getState(string $key) |
| 24 | { |
| 25 | return $this->where('state_key', $key)->first(); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Définit ou met à jour une valeur système |
| 30 | */ |
| 31 | public function setState(string $key, $value): bool |
| 32 | { |
| 33 | $existing = $this->where('state_key', $key)->first(); |
| 34 | |
| 35 | if ($existing) { |
| 36 | return $this->update($existing['id'], [ |
| 37 | 'state_value' => $value, |
| 38 | 'updated_at' => date('Y-m-d H:i:s'), |
| 39 | ]); |
| 40 | } |
| 41 | |
| 42 | return (bool) $this->insert([ |
| 43 | 'state_key' => $key, |
| 44 | 'state_value' => $value, |
| 45 | 'updated_at' => date('Y-m-d H:i:s'), |
| 46 | ]); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Supprime un état |
| 51 | */ |
| 52 | public function removeState(string $key): bool |
| 53 | { |
| 54 | return $this->where('state_key', $key)->delete(); |
| 55 | } |
| 56 | } |