|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of product_management |
|
4
|
|
|
* User: Sinan TURGUT <[email protected]> |
|
5
|
|
|
* Date: 24.06.2019 |
|
6
|
|
|
* php version 7.2 |
|
7
|
|
|
* |
|
8
|
|
|
* @category Assessment |
|
9
|
|
|
* @package ProductManagement |
|
10
|
|
|
* @author Sinan TURGUT <[email protected]> |
|
11
|
|
|
* @license See LICENSE file |
|
12
|
|
|
* @link https://dev.sinanturgut.com.tr |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace App\Core; |
|
16
|
|
|
|
|
17
|
|
|
use App\Utility; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Model |
|
21
|
|
|
* @package App\Core |
|
22
|
|
|
*/ |
|
23
|
|
|
class Model |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var Utility\Database|null |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $Db = null; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $data = []; |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Model constructor. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->Db = Utility\Database::getInstance(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param $table |
|
47
|
|
|
* @param array $fields |
|
48
|
|
|
* @return bool|string |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function create($table, array $fields) |
|
51
|
|
|
{ |
|
52
|
|
|
return($this->Db->insert($table, $fields)); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return array |
|
57
|
|
|
*/ |
|
58
|
|
|
public function data() |
|
59
|
|
|
{ |
|
60
|
|
|
return($this->data); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
|
|
public function exists() |
|
67
|
|
|
{ |
|
68
|
|
|
return(!empty($this->data)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param $table |
|
73
|
|
|
* @param array $where |
|
74
|
|
|
* @return $this |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function find($table, array $where = []) |
|
77
|
|
|
{ |
|
78
|
|
|
$_data = $this->Db->select($table, $where); |
|
79
|
|
|
if ($_data->count()) { |
|
80
|
|
|
$this->data = $_data->first(); |
|
81
|
|
|
} |
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param $table |
|
87
|
|
|
* @param array $where |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function select($table, array $where = []) |
|
91
|
|
|
{ |
|
92
|
|
|
$_data = $this->Db->select($table, $where); |
|
93
|
|
|
if ($_data->count()) { |
|
94
|
|
|
$this->data = $_data->results(); |
|
95
|
|
|
} |
|
96
|
|
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param $sql |
|
101
|
|
|
* @param $params |
|
102
|
|
|
* @return $this |
|
103
|
|
|
*/ |
|
104
|
|
|
public function query($sql, $params = []) |
|
105
|
|
|
{ |
|
106
|
|
|
$_data = $this->Db->query($sql, $params); |
|
107
|
|
|
if ($_data->count()) { |
|
108
|
|
|
$this->data = $_data->results(); |
|
109
|
|
|
} |
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function lastInsertId() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->Db->lastInsertId(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param $table |
|
123
|
|
|
* @param array $fields |
|
124
|
|
|
* @param $recordID |
|
125
|
|
|
* @param $where |
|
126
|
|
|
* @return bool |
|
127
|
|
|
*/ |
|
128
|
|
|
protected function update($table, array $fields, $recordID, $where) |
|
129
|
|
|
{ |
|
130
|
|
|
return(!$this->Db->update($table, $recordID, $fields, $where)); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param $AParam |
|
135
|
|
|
* @return mixed |
|
136
|
|
|
*/ |
|
137
|
|
|
public function clearSQLParam($AParam) |
|
138
|
|
|
{ |
|
139
|
|
|
$result = str_replace( "'", "", $AParam ); |
|
140
|
|
|
$result = str_replace( '"', '', $result ); |
|
141
|
|
|
$result = str_replace( '\\', '', $result ); |
|
142
|
|
|
$result = str_replace( '/', '', $result ); |
|
143
|
|
|
$result = str_replace( '&', '', $result ); |
|
144
|
|
|
$result = str_replace( '$', '', $result ); |
|
145
|
|
|
$result = str_replace( '@', '', $result ); |
|
146
|
|
|
$result = str_replace( '-', '', $result ); |
|
147
|
|
|
return $result; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.