Total Complexity | 15 |
Total Lines | 96 |
Duplicated Lines | 0 % |
Coverage | 29.73% |
Changes | 0 |
1 | <?php |
||
13 | trait ActiveRecordTrait |
||
14 | { |
||
15 | use RecordTrait; |
||
16 | use HasPrimaryKeyTrait; |
||
17 | |||
18 | protected $dbData = []; |
||
19 | |||
20 | /** |
||
21 | * @param bool|array $data |
||
22 | */ |
||
23 | 4 | public function writeDBData($data = false) |
|
24 | { |
||
25 | 4 | foreach ($data as $key => $value) { |
|
26 | 1 | $this->dbData[$key] = $value; |
|
27 | } |
||
28 | 4 | } |
|
29 | |||
30 | /** |
||
31 | * @return array |
||
32 | */ |
||
33 | public function getDBData() |
||
34 | { |
||
35 | return $this->dbData; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param $field |
||
40 | * @return bool |
||
41 | */ |
||
42 | 1 | public function fieldUpdatedFromDb($field) |
|
43 | { |
||
44 | 1 | if (!isset($this->{$field})) { |
|
45 | 1 | return false; |
|
46 | } |
||
47 | 1 | if (!isset($this->dbData[$field])) { |
|
48 | return false; |
||
49 | } |
||
50 | 1 | if ($this->{$field} == $this->dbData[$field]) { |
|
51 | 1 | return false; |
|
52 | } |
||
53 | 1 | return true; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return bool |
||
58 | */ |
||
59 | public function insert() |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return bool|\Nip\Database\Result |
||
72 | */ |
||
73 | public function update() |
||
74 | { |
||
75 | $return = $this->getManager()->update($this); |
||
76 | return $return; |
||
77 | } |
||
78 | |||
79 | public function save() |
||
80 | { |
||
81 | $this->getManager()->save($this); |
||
82 | } |
||
83 | |||
84 | public function saveRecord() |
||
87 | } |
||
88 | |||
89 | public function delete() |
||
90 | { |
||
91 | $this->getManager()->delete($this); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return bool |
||
96 | */ |
||
97 | public function isInDB() |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @return bool|false|Record |
||
105 | */ |
||
106 | public function exists() |
||
109 | } |
||
110 | } |
||
111 |