model; } /** * @param $data LuModel[] * @return LuDbo[] */ protected static function arrayToDbo($data) { $tab = []; foreach ($data as $q) { if (!is_null($q)) { $tab[] = $q->toDbo(); } } return $tab; } /** * @param $page int * @param $perPage int * @param $column string * @param $order string * @param $query string * @return LuDbo[] */ public function search($page, $perPage, $column, $order, $query = null) { if (is_null($query)) $data = $this->model; else $data = $this->search_($page, $perPage, $column, $order, $query); $data = $data->orderBy($column, $order)->take($perPage)->offset($page * $perPage)->get(); $tab = $this->arrayToDbo($data); return $tab; } /** * @param $id int * @return LuModel */ protected function _getModelById($id) { return $this->model->where('id', '=', $id)->first(); } /** * @param $id int * @return LuDbo|null */ public function _getById($id) { $data = $this->_getModelById($id); if (is_null($data)) return null; return $data->toDbo(); } /** * @param $id int */ public function deleteById($id) { $data = $this->_getModelById($id); if (is_null($data)) return; $data->delete(); } /** * @param $data LuDbo * @return int */ public function _addId($data) { $data = $this->model->fromDBO($data); $data->save(); return $data->id; } /** * @param $data LuDbo */ public function _add($data) { $data = $this->model->fromDBO($data); $data->save(); } /** * @param $id int * @param $data LuDbo * @return LuDbo|null */ public function _editById($id, $data) { return $this->model->fromDBO($data, $this->_getModelById($id))->save(); } /** * @param $predicates array * @param $orders array * @param int $page * @param int $perPage * @return array */ public function _getMultiple($predicates, $orders, $page = 0, $perPage = PHP_INT_MAX) { $model = $this->model; foreach($predicates as $predicate) { $model = $model->where($predicate[0], $predicate[1], $predicate[2]); } $count = $model->count(); foreach($orders as $order) { $model = $model->orderBy($order[0], $order[1]); } $data = $model->take($perPage)->offset($page * $perPage)->get(); $dbo = self::arrayToDbo($data); return new LuMultipleDbo($count, $dbo); } }