1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HnrAzevedo\Datamanager; |
4
|
|
|
|
5
|
|
|
abstract class Datamanager |
6
|
|
|
{ |
7
|
|
|
use DataTrait, SynchronizeTrait; |
8
|
|
|
|
9
|
|
|
protected ?string $table = null; |
10
|
|
|
protected ?string $primary = null; |
11
|
|
|
protected array $data = []; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
private array $where = [''=> ["1",'=',"1"] ]; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
private function mountRemove(): array |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$return = ['data' => '', 'where' => '']; |
20
|
|
|
foreach($this->where as $clause => $condition){ |
21
|
|
|
if(strlen($clause) === 0){ |
22
|
|
|
$return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]} "; |
23
|
|
|
$return['data'] .= "q_{$condition[0]}={$condition[2]}&"; |
24
|
|
|
continue; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
foreach($condition as $value){ |
28
|
|
|
$return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]} "; |
29
|
|
|
$return['data'] .= "q_{$value[0]}={$value[2]}&"; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
return $return; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
private function mountSave(): array |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$return = ['data' => []]; |
38
|
|
|
|
39
|
|
|
foreach ($this->data as $key => $value) { |
40
|
|
|
if(strstr($this->data[$key]['extra'],'auto_increment') && $key !== $this->primary){ |
41
|
|
|
continue; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if(($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key){ |
45
|
|
|
$return['data'][$key] = $this->data[$key]['value']; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
|
54
|
|
|
private function mountWhereExec(): array |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$return = ['where' => '', 'data' => []]; |
57
|
|
|
|
58
|
|
|
foreach ($this->where as $key => $value) { |
59
|
|
|
|
60
|
|
|
$key = (!$key) ? '' : " {$key} "; |
61
|
|
|
|
62
|
|
|
if(is_array($value[0])){ |
63
|
|
|
|
64
|
|
|
foreach ($value as $k => $v) { |
65
|
|
|
$return['where'] .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} "; |
66
|
|
|
$return['data']["q_{$v[0]}"] = $v[2]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
continue; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$return['where'] .= " {$key} {$value[0]} {$value[1]} :q_{$value[0]} "; |
73
|
|
|
$return['data']["q_{$value[0]}"] = $value[2]; |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
return $return; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function mountSelect() |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$select = implode(',',array_keys($this->select)); |
82
|
|
|
|
83
|
|
|
$this->query = str_replace('*', $select,$this->query); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private function mountLimit() |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
if(!is_null($this->limit)){ |
89
|
|
|
$this->query .= " LIMIT {$this->limit}"; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function mountOffset() |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
if(!is_null($this->offset)){ |
96
|
|
|
$this->query .= " OFFSET {$this->offset}"; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.