|
@@ -12,7 +12,7 @@ abstract class LuDataAccess {
|
12
|
12
|
{
|
13
|
13
|
$class = get_called_class();
|
14
|
14
|
$me = new $class();
|
15
|
|
- return call_user_func_array(array($me, $name), $arguments);
|
|
15
|
+ return call_user_func_array(array($me, '_' . $name), $arguments);
|
16
|
16
|
}
|
17
|
17
|
|
18
|
18
|
/**
|
|
@@ -73,7 +73,7 @@ abstract class LuDataAccess {
|
73
|
73
|
* @param $id int
|
74
|
74
|
* @return LuModel
|
75
|
75
|
*/
|
76
|
|
- protected function getModelById($id)
|
|
76
|
+ protected function _getModelById($id)
|
77
|
77
|
{
|
78
|
78
|
return $this->model->where('id', '=', $id)->first();
|
79
|
79
|
}
|
|
@@ -82,9 +82,9 @@ abstract class LuDataAccess {
|
82
|
82
|
* @param $id int
|
83
|
83
|
* @return LuDbo|null
|
84
|
84
|
*/
|
85
|
|
- public function getById($id)
|
|
85
|
+ public function _getById($id)
|
86
|
86
|
{
|
87
|
|
- $data = $this->getModelById($id);
|
|
87
|
+ $data = $this->_getModelById($id);
|
88
|
88
|
if (is_null($data))
|
89
|
89
|
return null;
|
90
|
90
|
return $data->toDbo();
|
|
@@ -95,7 +95,7 @@ abstract class LuDataAccess {
|
95
|
95
|
*/
|
96
|
96
|
public function deleteById($id)
|
97
|
97
|
{
|
98
|
|
- $data = $this->getModelById($id);
|
|
98
|
+ $data = $this->_getModelById($id);
|
99
|
99
|
if (is_null($data))
|
100
|
100
|
return;
|
101
|
101
|
$data->delete();
|
|
@@ -105,7 +105,7 @@ abstract class LuDataAccess {
|
105
|
105
|
* @param $data LuDbo
|
106
|
106
|
* @return int
|
107
|
107
|
*/
|
108
|
|
- public function addId($data)
|
|
108
|
+ public function _addId($data)
|
109
|
109
|
{
|
110
|
110
|
$data = $this->model->fromDBO($data);
|
111
|
111
|
$data->save();
|
|
@@ -115,7 +115,7 @@ abstract class LuDataAccess {
|
115
|
115
|
/**
|
116
|
116
|
* @param $data LuDbo
|
117
|
117
|
*/
|
118
|
|
- public function add($data)
|
|
118
|
+ public function _add($data)
|
119
|
119
|
{
|
120
|
120
|
$data = $this->model->fromDBO($data);
|
121
|
121
|
$data->save();
|
|
@@ -126,8 +126,33 @@ abstract class LuDataAccess {
|
126
|
126
|
* @param $data LuDbo
|
127
|
127
|
* @return LuDbo|null
|
128
|
128
|
*/
|
129
|
|
- public function editById($id, $data)
|
|
129
|
+ public function _editById($id, $data)
|
130
|
130
|
{
|
131
|
|
- return $this->model->fromDBO($data, $this->getModelById($id))->save();
|
|
131
|
+ return $this->model->fromDBO($data, $this->_getModelById($id))->save();
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ /**
|
|
135
|
+ * @param $predicates array
|
|
136
|
+ * @param $orders array
|
|
137
|
+ * @param int $page
|
|
138
|
+ * @param int $perPage
|
|
139
|
+ * @return array
|
|
140
|
+ */
|
|
141
|
+ public function _getMultiple($predicates, $orders, $page = 0, $perPage = PHP_INT_MAX)
|
|
142
|
+ {
|
|
143
|
+ $model = $this->model;
|
|
144
|
+ foreach($predicates as $predicate)
|
|
145
|
+ {
|
|
146
|
+ $model = $model->where($predicate[0], $predicate[1], $predicate[2]);
|
|
147
|
+ }
|
|
148
|
+ $count = $model->count();
|
|
149
|
+ foreach($orders as $order)
|
|
150
|
+ {
|
|
151
|
+ $model = $model->orderBy($order[0], $order[1]);
|
|
152
|
+ }
|
|
153
|
+ $data = $model->take($perPage)->offset($page * $perPage)->get();
|
|
154
|
+ $dbo = self::arrayToDbo($data);
|
|
155
|
+
|
|
156
|
+ return array("Count" => $count, "Data" => $dbo);
|
132
|
157
|
}
|
133
|
158
|
}
|