Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| DiagnosticSettingModel | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| getByOrganization | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toggle | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| forOrganization | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Modules\SupportModule\Models; |
| 4 | |
| 5 | use CodeIgniter\Model; |
| 6 | use App\Modules\SupportModule\Entities\DiagnosticSettingEntity; |
| 7 | |
| 8 | class DiagnosticSettingModel extends Model |
| 9 | { |
| 10 | protected $table = 'diagnostic_setting'; |
| 11 | |
| 12 | protected $primaryKey = 'id'; |
| 13 | |
| 14 | protected $returnType = DiagnosticSettingEntity::class; |
| 15 | |
| 16 | protected $allowedFields = [ |
| 17 | 'organization_id', // CHANGED (remplace tenant) |
| 18 | 'enabled', |
| 19 | 'created_at', |
| 20 | 'updated_at', |
| 21 | ]; |
| 22 | |
| 23 | protected $useTimestamps = true; |
| 24 | protected $createdField = 'created_at'; |
| 25 | protected $updatedField = 'updated_at'; |
| 26 | |
| 27 | protected $skipValidation = true; |
| 28 | |
| 29 | /** |
| 30 | * Récupération configuration organisation |
| 31 | */ |
| 32 | public function getByOrganization(int $organizationId) |
| 33 | { |
| 34 | return $this->where('organization_id', $organizationId)->first(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Toggle propre (UPSERT logique) |
| 39 | */ |
| 40 | public function toggle(int $organizationId, bool $enabled): bool |
| 41 | { |
| 42 | $existing = $this->where('organization_id', $organizationId)->first(); |
| 43 | |
| 44 | if ($existing) { |
| 45 | return (bool) $this->update($existing->id, [ |
| 46 | 'enabled' => $enabled |
| 47 | ]); |
| 48 | } |
| 49 | |
| 50 | return (bool) $this->insert([ |
| 51 | 'organization_id' => $organizationId, |
| 52 | 'enabled' => $enabled |
| 53 | ]); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Scope organisation |
| 58 | */ |
| 59 | public function forOrganization(int $organizationId) |
| 60 | { |
| 61 | return $this->where('organization_id', $organizationId); |
| 62 | } |
| 63 | } |