@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * Fetch all records with relations from model repository. |
39 | 39 | * |
40 | - * @return \Illuminate\Http\Response |
|
40 | + * @return \Illuminate\Http\JsonResponse|null |
|
41 | 41 | */ |
42 | 42 | public function getIndex() |
43 | 43 | { |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * Fetch the single object with relations from model repository. |
53 | 53 | * |
54 | 54 | * @param integer $id |
55 | - * @return \Illuminate\Http\Response |
|
55 | + * @return \Illuminate\Http\JsonResponse|null |
|
56 | 56 | */ |
57 | 57 | public function getFind($id) |
58 | 58 | { |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | * @param string $query |
71 | 71 | * @param integer $perPage |
72 | 72 | * @param string $sortBy |
73 | - * @param boolean $desc |
|
74 | - * @return \Illuminate\Http\Response |
|
73 | + * @param integer $desc |
|
74 | + * @return \Illuminate\Http\JsonResponse|null |
|
75 | 75 | */ |
76 | 76 | public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
77 | 77 | { |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @param \Illuminate\Http\Request $request |
90 | 90 | * @param string $sortBy |
91 | - * @param boolean $desc |
|
92 | - * @return \Illuminate\Http\Response |
|
91 | + * @param integer $desc |
|
92 | + * @return \Illuminate\Http\JsonResponse|null |
|
93 | 93 | */ |
94 | 94 | public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
95 | 95 | { |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * condition. |
106 | 106 | * |
107 | 107 | * @param \Illuminate\Http\Request $request |
108 | - * @return \Illuminate\Http\Response |
|
108 | + * @return \Illuminate\Http\JsonResponse|null |
|
109 | 109 | */ |
110 | 110 | public function postFirst(Request $request) |
111 | 111 | { |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @param integer $perPage |
123 | 123 | * @param string $sortBy |
124 | - * @param boolean $desc |
|
125 | - * @return \Illuminate\Http\Response |
|
124 | + * @param integer $desc |
|
125 | + * @return \Illuminate\Http\JsonResponse|null |
|
126 | 126 | */ |
127 | 127 | public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
128 | 128 | { |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | * @param \Illuminate\Http\Request $request |
141 | 141 | * @param integer $perPage |
142 | 142 | * @param string $sortBy |
143 | - * @param boolean $desc |
|
144 | - * @return \Illuminate\Http\Response |
|
143 | + * @param integer $desc |
|
144 | + * @return \Illuminate\Http\JsonResponse|null |
|
145 | 145 | */ |
146 | 146 | public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
147 | 147 | { |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * Save the given model to repository. |
157 | 157 | * |
158 | 158 | * @param \Illuminate\Http\Request $request |
159 | - * @return \Illuminate\Http\Response |
|
159 | + * @return \Illuminate\Http\JsonResponse|null |
|
160 | 160 | */ |
161 | 161 | public function postSave(Request $request) |
162 | 162 | { |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * Delete by the given id from model repository. |
190 | 190 | * |
191 | 191 | * @param integer $id |
192 | - * @return \Illuminate\Http\Response |
|
192 | + * @return \Illuminate\Http\JsonResponse|null |
|
193 | 193 | */ |
194 | 194 | public function getDelete($id) |
195 | 195 | { |
@@ -6,219 +6,219 @@ |
||
6 | 6 | |
7 | 7 | class BaseApiController extends Controller |
8 | 8 | { |
9 | - /** |
|
10 | - * The model implementation. |
|
11 | - * |
|
12 | - * @var model |
|
13 | - */ |
|
14 | - protected $model; |
|
15 | - |
|
16 | - /** |
|
17 | - * The config implementation. |
|
18 | - * |
|
19 | - * @var config |
|
20 | - */ |
|
21 | - protected $config; |
|
22 | - |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
9 | + /** |
|
10 | + * The model implementation. |
|
11 | + * |
|
12 | + * @var model |
|
13 | + */ |
|
14 | + protected $model; |
|
15 | + |
|
16 | + /** |
|
17 | + * The config implementation. |
|
18 | + * |
|
19 | + * @var config |
|
20 | + */ |
|
21 | + protected $config; |
|
22 | + |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
26 | 26 | |
27 | - $this->config = \CoreConfig::getConfig(); |
|
28 | - $this->model = property_exists($this, 'model') ? $this->model : false; |
|
29 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
30 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
31 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
32 | - $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
33 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
34 | - $this->checkPermission(explode('_', snake_case($route))[1]); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Fetch all records with relations from model repository. |
|
39 | - * |
|
40 | - * @return \Illuminate\Http\Response |
|
41 | - */ |
|
42 | - public function getIndex() |
|
43 | - { |
|
44 | - if ($this->model) |
|
45 | - { |
|
46 | - $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
47 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Fetch the single object with relations from model repository. |
|
53 | - * |
|
54 | - * @param integer $id |
|
55 | - * @return \Illuminate\Http\Response |
|
56 | - */ |
|
57 | - public function getFind($id) |
|
58 | - { |
|
59 | - if ($this->model) |
|
60 | - { |
|
61 | - $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
62 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Paginate all records with relations from model repository |
|
68 | - * that matche the given query. |
|
69 | - * |
|
70 | - * @param string $query |
|
71 | - * @param integer $perPage |
|
72 | - * @param string $sortBy |
|
73 | - * @param boolean $desc |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
77 | - { |
|
78 | - if ($this->model) |
|
79 | - { |
|
80 | - $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
81 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Fetch records from the storage based on the given |
|
87 | - * condition. |
|
88 | - * |
|
89 | - * @param \Illuminate\Http\Request $request |
|
90 | - * @param string $sortBy |
|
91 | - * @param boolean $desc |
|
92 | - * @return \Illuminate\Http\Response |
|
93 | - */ |
|
94 | - public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
95 | - { |
|
96 | - if ($this->model) |
|
97 | - { |
|
98 | - $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
99 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Fetch the first record from the storage based on the given |
|
105 | - * condition. |
|
106 | - * |
|
107 | - * @param \Illuminate\Http\Request $request |
|
108 | - * @return \Illuminate\Http\Response |
|
109 | - */ |
|
110 | - public function postFirst(Request $request) |
|
111 | - { |
|
112 | - if ($this->model) |
|
113 | - { |
|
114 | - $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
115 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Paginate all records with relations from model repository. |
|
121 | - * |
|
122 | - * @param integer $perPage |
|
123 | - * @param string $sortBy |
|
124 | - * @param boolean $desc |
|
125 | - * @return \Illuminate\Http\Response |
|
126 | - */ |
|
127 | - public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
128 | - { |
|
129 | - if ($this->model) |
|
130 | - { |
|
131 | - $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
132 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Fetch all records with relations based on |
|
138 | - * the given condition from storage in pages. |
|
139 | - * |
|
140 | - * @param \Illuminate\Http\Request $request |
|
141 | - * @param integer $perPage |
|
142 | - * @param string $sortBy |
|
143 | - * @param boolean $desc |
|
144 | - * @return \Illuminate\Http\Response |
|
145 | - */ |
|
146 | - public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
147 | - { |
|
148 | - if ($this->model) |
|
149 | - { |
|
150 | - $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
151 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Save the given model to repository. |
|
157 | - * |
|
158 | - * @param \Illuminate\Http\Request $request |
|
159 | - * @return \Illuminate\Http\Response |
|
160 | - */ |
|
161 | - public function postSave(Request $request) |
|
162 | - { |
|
163 | - foreach ($this->validationRules as &$rule) |
|
164 | - { |
|
165 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
166 | - { |
|
167 | - $rule .= ',deleted_at,NULL'; |
|
168 | - } |
|
169 | - |
|
170 | - if ($request->has('id')) |
|
171 | - { |
|
172 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
173 | - } |
|
174 | - else |
|
175 | - { |
|
176 | - $rule = str_replace(',{id}', '', $rule); |
|
177 | - } |
|
178 | - } |
|
27 | + $this->config = \CoreConfig::getConfig(); |
|
28 | + $this->model = property_exists($this, 'model') ? $this->model : false; |
|
29 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
30 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
31 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
32 | + $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
33 | + $route = explode('@',\Route::currentRouteAction())[1]; |
|
34 | + $this->checkPermission(explode('_', snake_case($route))[1]); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Fetch all records with relations from model repository. |
|
39 | + * |
|
40 | + * @return \Illuminate\Http\Response |
|
41 | + */ |
|
42 | + public function getIndex() |
|
43 | + { |
|
44 | + if ($this->model) |
|
45 | + { |
|
46 | + $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
47 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Fetch the single object with relations from model repository. |
|
53 | + * |
|
54 | + * @param integer $id |
|
55 | + * @return \Illuminate\Http\Response |
|
56 | + */ |
|
57 | + public function getFind($id) |
|
58 | + { |
|
59 | + if ($this->model) |
|
60 | + { |
|
61 | + $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
62 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Paginate all records with relations from model repository |
|
68 | + * that matche the given query. |
|
69 | + * |
|
70 | + * @param string $query |
|
71 | + * @param integer $perPage |
|
72 | + * @param string $sortBy |
|
73 | + * @param boolean $desc |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
77 | + { |
|
78 | + if ($this->model) |
|
79 | + { |
|
80 | + $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
81 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Fetch records from the storage based on the given |
|
87 | + * condition. |
|
88 | + * |
|
89 | + * @param \Illuminate\Http\Request $request |
|
90 | + * @param string $sortBy |
|
91 | + * @param boolean $desc |
|
92 | + * @return \Illuminate\Http\Response |
|
93 | + */ |
|
94 | + public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
95 | + { |
|
96 | + if ($this->model) |
|
97 | + { |
|
98 | + $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
99 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Fetch the first record from the storage based on the given |
|
105 | + * condition. |
|
106 | + * |
|
107 | + * @param \Illuminate\Http\Request $request |
|
108 | + * @return \Illuminate\Http\Response |
|
109 | + */ |
|
110 | + public function postFirst(Request $request) |
|
111 | + { |
|
112 | + if ($this->model) |
|
113 | + { |
|
114 | + $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
115 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Paginate all records with relations from model repository. |
|
121 | + * |
|
122 | + * @param integer $perPage |
|
123 | + * @param string $sortBy |
|
124 | + * @param boolean $desc |
|
125 | + * @return \Illuminate\Http\Response |
|
126 | + */ |
|
127 | + public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
128 | + { |
|
129 | + if ($this->model) |
|
130 | + { |
|
131 | + $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
132 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Fetch all records with relations based on |
|
138 | + * the given condition from storage in pages. |
|
139 | + * |
|
140 | + * @param \Illuminate\Http\Request $request |
|
141 | + * @param integer $perPage |
|
142 | + * @param string $sortBy |
|
143 | + * @param boolean $desc |
|
144 | + * @return \Illuminate\Http\Response |
|
145 | + */ |
|
146 | + public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
147 | + { |
|
148 | + if ($this->model) |
|
149 | + { |
|
150 | + $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
151 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Save the given model to repository. |
|
157 | + * |
|
158 | + * @param \Illuminate\Http\Request $request |
|
159 | + * @return \Illuminate\Http\Response |
|
160 | + */ |
|
161 | + public function postSave(Request $request) |
|
162 | + { |
|
163 | + foreach ($this->validationRules as &$rule) |
|
164 | + { |
|
165 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
166 | + { |
|
167 | + $rule .= ',deleted_at,NULL'; |
|
168 | + } |
|
169 | + |
|
170 | + if ($request->has('id')) |
|
171 | + { |
|
172 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
173 | + } |
|
174 | + else |
|
175 | + { |
|
176 | + $rule = str_replace(',{id}', '', $rule); |
|
177 | + } |
|
178 | + } |
|
179 | 179 | |
180 | - $this->validate($request, $this->validationRules); |
|
181 | - |
|
182 | - if ($this->model) |
|
183 | - { |
|
184 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Delete by the given id from model repository. |
|
190 | - * |
|
191 | - * @param integer $id |
|
192 | - * @return \Illuminate\Http\Response |
|
193 | - */ |
|
194 | - public function getDelete($id) |
|
195 | - { |
|
196 | - if ($this->model) |
|
197 | - { |
|
198 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Check if the logged in user can do the given permission. |
|
204 | - * |
|
205 | - * @param string $permission |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - private function checkPermission($permission) |
|
209 | - { |
|
210 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
211 | - if ($permission == 'method') |
|
212 | - { |
|
213 | - \ErrorHandler::notFound('method'); |
|
214 | - } |
|
215 | - else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
216 | - { |
|
217 | - \JWTAuth::parseToken()->authenticate(); |
|
218 | - if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
219 | - { |
|
220 | - \ErrorHandler::noPermissions(); |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
180 | + $this->validate($request, $this->validationRules); |
|
181 | + |
|
182 | + if ($this->model) |
|
183 | + { |
|
184 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Delete by the given id from model repository. |
|
190 | + * |
|
191 | + * @param integer $id |
|
192 | + * @return \Illuminate\Http\Response |
|
193 | + */ |
|
194 | + public function getDelete($id) |
|
195 | + { |
|
196 | + if ($this->model) |
|
197 | + { |
|
198 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Check if the logged in user can do the given permission. |
|
204 | + * |
|
205 | + * @param string $permission |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + private function checkPermission($permission) |
|
209 | + { |
|
210 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
211 | + if ($permission == 'method') |
|
212 | + { |
|
213 | + \ErrorHandler::notFound('method'); |
|
214 | + } |
|
215 | + else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
216 | + { |
|
217 | + \JWTAuth::parseToken()->authenticate(); |
|
218 | + if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
219 | + { |
|
220 | + \ErrorHandler::noPermissions(); |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | 224 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @param array $relations |
9 | 9 | * @param array $sortBy |
10 | - * @param array $desc |
|
10 | + * @param integer $desc |
|
11 | 11 | * @param array $columns |
12 | 12 | * @return collection |
13 | 13 | */ |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param integer $perPage |
22 | 22 | * @param array $relations |
23 | 23 | * @param array $sortBy |
24 | - * @param array $desc |
|
24 | + * @param integer $desc |
|
25 | 25 | * @param array $columns |
26 | 26 | * @return collection |
27 | 27 | */ |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param integer $perPage |
34 | 34 | * @param array $relations |
35 | 35 | * @param array $sortBy |
36 | - * @param array $desc |
|
36 | + * @param integer $desc |
|
37 | 37 | * @param array $columns |
38 | 38 | * @return collection |
39 | 39 | */ |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param integer $perPage |
48 | 48 | * @param array $relations |
49 | 49 | * @param array $sortBy |
50 | - * @param array $desc |
|
50 | + * @param integer $desc |
|
51 | 51 | * @param array $columns |
52 | 52 | * @return collection |
53 | 53 | */ |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param array $conditions array of conditions |
91 | 91 | * @param array $relations |
92 | 92 | * @param array $sortBy |
93 | - * @param array $desc |
|
93 | + * @param integer $desc |
|
94 | 94 | * @param array $columns |
95 | 95 | * @return collection |
96 | 96 | */ |
@@ -3,107 +3,107 @@ |
||
3 | 3 | interface RepositoryInterface |
4 | 4 | { |
5 | 5 | /** |
6 | - * Fetch all records with relations from the storage. |
|
7 | - * |
|
8 | - * @param array $relations |
|
9 | - * @param array $sortBy |
|
10 | - * @param array $desc |
|
11 | - * @param array $columns |
|
12 | - * @return collection |
|
13 | - */ |
|
6 | + * Fetch all records with relations from the storage. |
|
7 | + * |
|
8 | + * @param array $relations |
|
9 | + * @param array $sortBy |
|
10 | + * @param array $desc |
|
11 | + * @param array $columns |
|
12 | + * @return collection |
|
13 | + */ |
|
14 | 14 | public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
15 | 15 | |
16 | - /** |
|
17 | - * Fetch all records with relations from storage in pages |
|
18 | - * that matche the given query. |
|
19 | - * |
|
20 | - * @param string $query |
|
21 | - * @param integer $perPage |
|
22 | - * @param array $relations |
|
23 | - * @param array $sortBy |
|
24 | - * @param array $desc |
|
25 | - * @param array $columns |
|
26 | - * @return collection |
|
27 | - */ |
|
28 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
16 | + /** |
|
17 | + * Fetch all records with relations from storage in pages |
|
18 | + * that matche the given query. |
|
19 | + * |
|
20 | + * @param string $query |
|
21 | + * @param integer $perPage |
|
22 | + * @param array $relations |
|
23 | + * @param array $sortBy |
|
24 | + * @param array $desc |
|
25 | + * @param array $columns |
|
26 | + * @return collection |
|
27 | + */ |
|
28 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
29 | 29 | |
30 | 30 | /** |
31 | - * Fetch all records with relations from storage in pages. |
|
32 | - * |
|
33 | - * @param integer $perPage |
|
34 | - * @param array $relations |
|
35 | - * @param array $sortBy |
|
36 | - * @param array $desc |
|
37 | - * @param array $columns |
|
38 | - * @return collection |
|
39 | - */ |
|
40 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
31 | + * Fetch all records with relations from storage in pages. |
|
32 | + * |
|
33 | + * @param integer $perPage |
|
34 | + * @param array $relations |
|
35 | + * @param array $sortBy |
|
36 | + * @param array $desc |
|
37 | + * @param array $columns |
|
38 | + * @return collection |
|
39 | + */ |
|
40 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
41 | 41 | |
42 | 42 | /** |
43 | - * Fetch all records with relations based on |
|
44 | - * the given condition from storage in pages. |
|
45 | - * |
|
46 | - * @param array $conditions array of conditions |
|
47 | - * @param integer $perPage |
|
48 | - * @param array $relations |
|
49 | - * @param array $sortBy |
|
50 | - * @param array $desc |
|
51 | - * @param array $columns |
|
52 | - * @return collection |
|
53 | - */ |
|
54 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
43 | + * Fetch all records with relations based on |
|
44 | + * the given condition from storage in pages. |
|
45 | + * |
|
46 | + * @param array $conditions array of conditions |
|
47 | + * @param integer $perPage |
|
48 | + * @param array $relations |
|
49 | + * @param array $sortBy |
|
50 | + * @param array $desc |
|
51 | + * @param array $columns |
|
52 | + * @return collection |
|
53 | + */ |
|
54 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Save the given model/models to the storage. |
|
58 | - * |
|
59 | - * @param array $data |
|
60 | - * @param boolean $saveLog |
|
61 | - * @return object |
|
62 | - */ |
|
63 | - public function save(array $data, $saveLog = true); |
|
56 | + /** |
|
57 | + * Save the given model/models to the storage. |
|
58 | + * |
|
59 | + * @param array $data |
|
60 | + * @param boolean $saveLog |
|
61 | + * @return object |
|
62 | + */ |
|
63 | + public function save(array $data, $saveLog = true); |
|
64 | 64 | |
65 | 65 | /** |
66 | - * Delete record from the storage based on the given |
|
67 | - * condition. |
|
68 | - * |
|
69 | - * @param var $value condition value |
|
70 | - * @param string $attribute condition column name |
|
71 | - * @return integer affected rows |
|
72 | - */ |
|
73 | - public function delete($value, $attribute = 'id'); |
|
66 | + * Delete record from the storage based on the given |
|
67 | + * condition. |
|
68 | + * |
|
69 | + * @param var $value condition value |
|
70 | + * @param string $attribute condition column name |
|
71 | + * @return integer affected rows |
|
72 | + */ |
|
73 | + public function delete($value, $attribute = 'id'); |
|
74 | 74 | |
75 | 75 | /** |
76 | - * Fetch records from the storage based on the given |
|
77 | - * id. |
|
78 | - * |
|
79 | - * @param integer $id |
|
80 | - * @param array $relations |
|
81 | - * @param array $columns |
|
82 | - * @return object |
|
83 | - */ |
|
84 | - public function find($id, $relations = [], $columns = array('*')); |
|
76 | + * Fetch records from the storage based on the given |
|
77 | + * id. |
|
78 | + * |
|
79 | + * @param integer $id |
|
80 | + * @param array $relations |
|
81 | + * @param array $columns |
|
82 | + * @return object |
|
83 | + */ |
|
84 | + public function find($id, $relations = [], $columns = array('*')); |
|
85 | 85 | |
86 | 86 | /** |
87 | - * Fetch records from the storage based on the given |
|
88 | - * condition. |
|
89 | - * |
|
90 | - * @param array $conditions array of conditions |
|
91 | - * @param array $relations |
|
92 | - * @param array $sortBy |
|
93 | - * @param array $desc |
|
94 | - * @param array $columns |
|
95 | - * @return collection |
|
96 | - */ |
|
97 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
87 | + * Fetch records from the storage based on the given |
|
88 | + * condition. |
|
89 | + * |
|
90 | + * @param array $conditions array of conditions |
|
91 | + * @param array $relations |
|
92 | + * @param array $sortBy |
|
93 | + * @param array $desc |
|
94 | + * @param array $columns |
|
95 | + * @return collection |
|
96 | + */ |
|
97 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
98 | 98 | |
99 | - /** |
|
100 | - * Fetch the first record fro the storage based on the given |
|
101 | - * condition. |
|
102 | - * |
|
103 | - * @param array $conditions array of conditions |
|
104 | - * @param array $relations |
|
105 | - * @param array $columns |
|
106 | - * @return object |
|
107 | - */ |
|
108 | - public function first($conditions, $relations = [], $columns = array('*')); |
|
99 | + /** |
|
100 | + * Fetch the first record fro the storage based on the given |
|
101 | + * condition. |
|
102 | + * |
|
103 | + * @param array $conditions array of conditions |
|
104 | + * @param array $relations |
|
105 | + * @param array $columns |
|
106 | + * @return object |
|
107 | + */ |
|
108 | + public function first($conditions, $relations = [], $columns = array('*')); |
|
109 | 109 | } |
110 | 110 | \ No newline at end of file |
@@ -15,23 +15,23 @@ |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | - * Set the notification notified to true. |
|
19 | - * |
|
20 | - * @param integer $id |
|
21 | - * @return object |
|
22 | - */ |
|
23 | - public function notified($id) |
|
24 | - { |
|
25 | - return $this->save(['id' => $id, 'notified' => 1]); |
|
26 | - } |
|
18 | + * Set the notification notified to true. |
|
19 | + * |
|
20 | + * @param integer $id |
|
21 | + * @return object |
|
22 | + */ |
|
23 | + public function notified($id) |
|
24 | + { |
|
25 | + return $this->save(['id' => $id, 'notified' => 1]); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Set the notification notified to all. |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function notifyAll() |
|
34 | - { |
|
35 | - \Core::notifications()->update(false, ['notified' => 1], 'notified'); |
|
36 | - } |
|
28 | + /** |
|
29 | + * Set the notification notified to all. |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function notifyAll() |
|
34 | + { |
|
35 | + \Core::notifications()->update(false, ['notified' => 1], 'notified'); |
|
36 | + } |
|
37 | 37 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | use App\Modules\V1\Core\AbstractRepositories\AbstractRepositoryContainer; |
4 | 4 | |
5 | -class Core extends AbstractRepositoryContainer{ |
|
5 | +class Core extends AbstractRepositoryContainer { |
|
6 | 6 | /** |
7 | 7 | * Specify module repositories name space. |
8 | 8 | * |
@@ -2,17 +2,17 @@ |
||
2 | 2 | |
3 | 3 | class Logging |
4 | 4 | { |
5 | - public function saveLog($action, $item_name, $item_type, $item_id) |
|
6 | - { |
|
7 | - if (\Core::logs() && $item_name !== 'Log') |
|
8 | - { |
|
9 | - \Core::logs()->save([ |
|
10 | - 'action' => $action, |
|
11 | - 'item_name' => $item_name, |
|
12 | - 'item_type' => $item_type, |
|
13 | - 'item_id' => $item_id, |
|
14 | - 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
15 | - ], false, false); |
|
16 | - } |
|
17 | - } |
|
5 | + public function saveLog($action, $item_name, $item_type, $item_id) |
|
6 | + { |
|
7 | + if (\Core::logs() && $item_name !== 'Log') |
|
8 | + { |
|
9 | + \Core::logs()->save([ |
|
10 | + 'action' => $action, |
|
11 | + 'item_name' => $item_name, |
|
12 | + 'item_type' => $item_type, |
|
13 | + 'item_id' => $item_id, |
|
14 | + 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
15 | + ], false, false); |
|
16 | + } |
|
17 | + } |
|
18 | 18 | } |
19 | 19 | \ No newline at end of file |
@@ -15,54 +15,54 @@ |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | - * Render the given report db view. |
|
19 | - * |
|
20 | - * @param integer $id |
|
21 | - * @param array $relations |
|
22 | - * @param array $columns |
|
23 | - * @return object |
|
24 | - */ |
|
25 | - public function find($id, $relations = [], $columns = array('*')) |
|
26 | - { |
|
18 | + * Render the given report db view. |
|
19 | + * |
|
20 | + * @param integer $id |
|
21 | + * @param array $relations |
|
22 | + * @param array $columns |
|
23 | + * @return object |
|
24 | + */ |
|
25 | + public function find($id, $relations = [], $columns = array('*')) |
|
26 | + { |
|
27 | 27 | $report = call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns); |
28 | 28 | |
29 | - if ( ! $report) |
|
30 | - { |
|
31 | - \ErrorHandler::notFound('report'); |
|
32 | - } |
|
29 | + if ( ! $report) |
|
30 | + { |
|
31 | + \ErrorHandler::notFound('report'); |
|
32 | + } |
|
33 | 33 | |
34 | - if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
35 | - { |
|
36 | - \ErrorHandler::noPermissions(); |
|
37 | - } |
|
34 | + if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
35 | + { |
|
36 | + \ErrorHandler::noPermissions(); |
|
37 | + } |
|
38 | 38 | |
39 | - return \DB::table($report->view_name)->get(); |
|
40 | - } |
|
39 | + return \DB::table($report->view_name)->get(); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Render the given report db view based on the given |
|
44 | - * condition. |
|
45 | - * |
|
46 | - * @param array $conditions array of conditions |
|
47 | - * @param array $relations |
|
48 | - * @param array $colunmns |
|
49 | - * @return object |
|
50 | - */ |
|
51 | - public function first($conditions, $relations = [], $columns = array('*')) |
|
52 | - { |
|
42 | + /** |
|
43 | + * Render the given report db view based on the given |
|
44 | + * condition. |
|
45 | + * |
|
46 | + * @param array $conditions array of conditions |
|
47 | + * @param array $relations |
|
48 | + * @param array $colunmns |
|
49 | + * @return object |
|
50 | + */ |
|
51 | + public function first($conditions, $relations = [], $columns = array('*')) |
|
52 | + { |
|
53 | 53 | $conditions = $this->constructConditions($conditions); |
54 | 54 | $report = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
55 | 55 | |
56 | - if ( ! $report) |
|
57 | - { |
|
58 | - \ErrorHandler::notFound('report'); |
|
59 | - } |
|
56 | + if ( ! $report) |
|
57 | + { |
|
58 | + \ErrorHandler::notFound('report'); |
|
59 | + } |
|
60 | 60 | |
61 | - if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
62 | - { |
|
63 | - \ErrorHandler::noPermissions(); |
|
64 | - } |
|
61 | + if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
62 | + { |
|
63 | + \ErrorHandler::noPermissions(); |
|
64 | + } |
|
65 | 65 | |
66 | - return \DB::table($report->view_name)->get(); |
|
67 | - } |
|
66 | + return \DB::table($report->view_name)->get(); |
|
67 | + } |
|
68 | 68 | } |