Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SafeConfigurationController
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getCurrentConfig
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 updateConfig
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2namespace BuyerKiosk\Cash\Controllers;
3
4class SafeConfigurationController {
5    private $repository;
6    private $app;
7
8    public function __construct($db, $app) {
9        $this->repository = new \BuyerKiosk\Cash\SafeConfiguration($db);
10        $this->app = $app;
11    }
12
13    public function getCurrentConfig() {
14        return $this->repository->getLatest();
15    }
16
17    public function updateConfig($data) {
18        $data['timeStamp'] = date('Y-m-d H:i:s');
19        $data['userId'] = $this->app->user->id;
20
21        $currentConfig = $this->repository->getLatest();
22
23        try {
24            if (!empty($currentConfig) && isset($currentConfig['id'])) {
25                $result = $this->repository->update($currentConfig['id'], $data);
26            } else {
27                $result = $this->repository->create($data);
28            }
29
30            return [
31                'success' => true,
32                'message' => 'Safe configuration updated successfully'
33            ];
34        } catch (\Exception $e) {
35            return [
36                'success' => false,
37                'message' => 'Failed to update safe configuration: ' . $e->getMessage()
38            ];
39        }
40    }
41}