-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrencyModel.php
More file actions
87 lines (73 loc) · 2.64 KB
/
CurrencyModel.php
File metadata and controls
87 lines (73 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* @see https://github.com/codenomdev/codeigniter4-framework for the canonical source repository
*
* @copyright 2020 - Codenom Dev (https://codenom.com).
* @license https://github.com/codenomdev/codeigniter4-framework/blob/master/LICENSE MIT License
*/
namespace Codenom\Framework\Models\Currency;
use CodeIgniter\Model;
use Codenom\Framework\Entities\Currency\CurrencyEntity;
class CurrencyModel extends Model
{
protected $table = 'currency';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = CurrencyEntity::class;
protected $useSoftDeletes = true;
protected $allowedFields = ['title', 'code', 'symbol_left', 'symbol_right', 'decimal_places', 'value', 'status'];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
protected $validationRules = [
'title' => [
'label' => 'Currency.form.label.titleCurrency',
'rules' => 'required|min_length[3]|max_length[32]',
],
'code' => [
'label' => 'Currency.form.label.codeCurrency',
'rules' => 'required|iso_code_3',
],
// 'symbol_left' => [
// 'label' => 'Currency.form.label.symbolLeftCurrency',
// ],
// 'symbol_right' => [
// 'label' => 'Currency.form.label.symbolRightCurrency',
// ],
// 'decimal_places' => [
// 'label' => 'Currency.form.label.decimalPlaces',
// ],
// 'value' => [
// 'label' => 'Currency.form.label.value',
// ],
'status' => [
'label' => 'Currency.form.label.status',
'rules' => 'required|in_list[1,0]'
]
];
protected $validationMessages = [];
protected $skipValidation = false;
protected $beforeUpdate = ['beforeUpdate'];
protected $beforeInsert = ['beforeInsert'];
protected function beforeUpdate(array $data)
{
cache()->delete($data['id'][0] . '_currencyById');
cache()->delete('currencyCollection');
return $data;
}
// public function deleteCurrencyById($id)
// {
// cache()->delete($id . '_currencyById');
// cache()->delete('currencyCollection');
// return $this->db->table($this->table)->where(['id' => $id])->purgeDeleted();
// }
protected function beforeInsert(array $data)
{
if ($data['data']['code']) {
$data['data']['code'] = \strtoupper($data['data']['code']);
}
cache()->delete('currencyCollection');
return $data;
}
}