@@ -4,34 +4,34 @@ |
||
| 4 | 4 | |
| 5 | 5 | abstract class AbstractRepositoryContainer implements RepositoryContainerInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Construct the repository class name based on |
|
| 9 | - * the method name called, search in the |
|
| 10 | - * given namespaces for the class and |
|
| 11 | - * return an instance. |
|
| 12 | - * |
|
| 13 | - * @param string $name the called method name |
|
| 14 | - * @param array $arguments the method arguments |
|
| 15 | - * @return object |
|
| 16 | - */ |
|
| 7 | + /** |
|
| 8 | + * Construct the repository class name based on |
|
| 9 | + * the method name called, search in the |
|
| 10 | + * given namespaces for the class and |
|
| 11 | + * return an instance. |
|
| 12 | + * |
|
| 13 | + * @param string $name the called method name |
|
| 14 | + * @param array $arguments the method arguments |
|
| 15 | + * @return object |
|
| 16 | + */ |
|
| 17 | 17 | public function __call($name, $arguments) |
| 18 | - { |
|
| 19 | - foreach ($this->getRepoNameSpace() as $repoNameSpace) |
|
| 20 | - { |
|
| 21 | - $class = rtrim($repoNameSpace, '\\') . '\\' . ucfirst(str_singular($name)) . 'Repository'; |
|
| 22 | - if (class_exists($class)) |
|
| 23 | - { |
|
| 24 | - return \App::make($class); |
|
| 25 | - } |
|
| 26 | - } |
|
| 27 | - } |
|
| 18 | + { |
|
| 19 | + foreach ($this->getRepoNameSpace() as $repoNameSpace) |
|
| 20 | + { |
|
| 21 | + $class = rtrim($repoNameSpace, '\\') . '\\' . ucfirst(str_singular($name)) . 'Repository'; |
|
| 22 | + if (class_exists($class)) |
|
| 23 | + { |
|
| 24 | + return \App::make($class); |
|
| 25 | + } |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Abstract methods that return the necessary |
|
| 31 | - * information (repositories namespaces) |
|
| 32 | - * needed to preform the previous actions. |
|
| 33 | - * |
|
| 34 | - * @return array |
|
| 35 | - */ |
|
| 36 | - abstract protected function getRepoNameSpace(); |
|
| 29 | + /** |
|
| 30 | + * Abstract methods that return the necessary |
|
| 31 | + * information (repositories namespaces) |
|
| 32 | + * needed to preform the previous actions. |
|
| 33 | + * |
|
| 34 | + * @return array |
|
| 35 | + */ |
|
| 36 | + abstract protected function getRepoNameSpace(); |
|
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | { |
| 19 | 19 | foreach ($this->getRepoNameSpace() as $repoNameSpace) |
| 20 | 20 | { |
| 21 | - $class = rtrim($repoNameSpace, '\\') . '\\' . ucfirst(str_singular($name)) . 'Repository'; |
|
| 21 | + $class = rtrim($repoNameSpace, '\\').'\\'.ucfirst(str_singular($name)).'Repository'; |
|
| 22 | 22 | if (class_exists($class)) |
| 23 | 23 | { |
| 24 | 24 | return \App::make($class); |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | class LogsController extends BaseApiController |
| 9 | 9 | { |
| 10 | 10 | /** |
| 11 | - * The name of the model that is used by the base api controller |
|
| 12 | - * to preform actions like (add, edit ... etc). |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $model = 'logs'; |
|
| 11 | + * The name of the model that is used by the base api controller |
|
| 12 | + * to preform actions like (add, edit ... etc). |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $model = 'logs'; |
|
| 16 | 16 | } |
@@ -12,5 +12,5 @@ |
||
| 12 | 12 | * to preform actions like (add, edit ... etc). |
| 13 | 13 | * @var string |
| 14 | 14 | */ |
| 15 | - protected $model = 'logs'; |
|
| 15 | + protected $model = 'logs'; |
|
| 16 | 16 | } |
@@ -8,20 +8,20 @@ |
||
| 8 | 8 | |
| 9 | 9 | class SettingsController extends BaseApiController |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The name of the model that is used by the base api controller |
|
| 13 | - * to preform actions like (add, edit ... etc). |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $model = 'settings'; |
|
| 11 | + /** |
|
| 12 | + * The name of the model that is used by the base api controller |
|
| 13 | + * to preform actions like (add, edit ... etc). |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $model = 'settings'; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The validations rules used by the base api controller |
|
| 20 | - * to check before add. |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $validationRules = [ |
|
| 24 | - 'name' => 'required|string|max:100', |
|
| 25 | - 'value' => 'required|string|max:100' |
|
| 26 | - ]; |
|
| 18 | + /** |
|
| 19 | + * The validations rules used by the base api controller |
|
| 20 | + * to check before add. |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $validationRules = [ |
|
| 24 | + 'name' => 'required|string|max:100', |
|
| 25 | + 'value' => 'required|string|max:100' |
|
| 26 | + ]; |
|
| 27 | 27 | } |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | * to preform actions like (add, edit ... etc). |
| 14 | 14 | * @var string |
| 15 | 15 | */ |
| 16 | - protected $model = 'settings'; |
|
| 16 | + protected $model = 'settings'; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * The validations rules used by the base api controller |
| 20 | 20 | * to check before add. |
| 21 | 21 | * @var array |
| 22 | 22 | */ |
| 23 | - protected $validationRules = [ |
|
| 23 | + protected $validationRules = [ |
|
| 24 | 24 | 'name' => 'required|string|max:100', |
| 25 | 25 | 'value' => 'required|string|max:100' |
| 26 | 26 | ]; |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
| 48 | 48 | |
| 49 | 49 | $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
| 50 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
| 50 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
| 51 | 51 | $this->checkPermission(explode('_', snake_case($route))[1]); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -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,215 +6,215 @@ |
||
| 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($route); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Fetch all records with relations from model repository. |
|
| 39 | - * |
|
| 40 | - * @return \Illuminate\Http\Response |
|
| 41 | - */ |
|
| 42 | - public function index() |
|
| 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 find($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 search($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 findby(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 first(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 paginate($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 paginateby(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 save(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($route); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Fetch all records with relations from model repository. |
|
| 39 | + * |
|
| 40 | + * @return \Illuminate\Http\Response |
|
| 41 | + */ |
|
| 42 | + public function index() |
|
| 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 find($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 search($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 findby(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 first(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 paginate($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 paginateby(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 save(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 delete($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 ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 212 | - { |
|
| 213 | - \JWTAuth::parseToken()->authenticate(); |
|
| 214 | - if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
| 215 | - { |
|
| 216 | - \ErrorHandler::noPermissions(); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } |
|
| 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 delete($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 ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 212 | + { |
|
| 213 | + \JWTAuth::parseToken()->authenticate(); |
|
| 214 | + if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
| 215 | + { |
|
| 216 | + \ErrorHandler::noPermissions(); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | 220 | } |
@@ -170,8 +170,7 @@ |
||
| 170 | 170 | if ($request->has('id')) |
| 171 | 171 | { |
| 172 | 172 | $rule = str_replace('{id}', $request->get('id'), $rule); |
| 173 | - } |
|
| 174 | - else |
|
| 173 | + } else |
|
| 175 | 174 | { |
| 176 | 175 | $rule = str_replace(',{id}', '', $rule); |
| 177 | 176 | } |
@@ -22,15 +22,15 @@ |
||
| 22 | 22 | "); |
| 23 | 23 | |
| 24 | 24 | DB::table('reports')->insert( |
| 25 | - [ |
|
| 26 | - [ |
|
| 25 | + [ |
|
| 26 | + [ |
|
| 27 | 27 | 'report_name' => 'admin_count', |
| 28 | 28 | 'view_name' => 'admin_count', |
| 29 | 29 | 'created_at' => \DB::raw('NOW()'), |
| 30 | 30 | 'updated_at' => \DB::raw('NOW()') |
| 31 | - ] |
|
| 32 | - ] |
|
| 33 | - ); |
|
| 31 | + ] |
|
| 32 | + ] |
|
| 33 | + ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -12,8 +12,8 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - DB::statement( "DROP VIEW IF EXISTS admin_count"); |
|
| 16 | - DB::statement( "CREATE VIEW admin_count AS |
|
| 15 | + DB::statement("DROP VIEW IF EXISTS admin_count"); |
|
| 16 | + DB::statement("CREATE VIEW admin_count AS |
|
| 17 | 17 | select count(u.id) |
| 18 | 18 | from users u, groups g ,users_groups ug |
| 19 | 19 | where |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | $table->string('view_name',100); |
| 19 | 19 | $table->softDeletes(); |
| 20 | 20 | $table->timestamps(); |
| 21 | - }); |
|
| 21 | + }); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -12,10 +12,10 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - Schema::create('reports', function (Blueprint $table) { |
|
| 15 | + Schema::create('reports', function(Blueprint $table) { |
|
| 16 | 16 | $table->increments('id'); |
| 17 | - $table->string('report_name',100); |
|
| 18 | - $table->string('view_name',100); |
|
| 17 | + $table->string('report_name', 100); |
|
| 18 | + $table->string('view_name', 100); |
|
| 19 | 19 | $table->softDeletes(); |
| 20 | 20 | $table->timestamps(); |
| 21 | 21 | }); |
@@ -12,71 +12,71 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Delete previous permissions. |
|
| 17 | - */ |
|
| 15 | + /** |
|
| 16 | + * Delete previous permissions. |
|
| 17 | + */ |
|
| 18 | 18 | DB::table('permissions')->whereIn('model', ['reports'])->delete(); |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | - * Insert the permissions related to this module. |
|
| 22 | - */ |
|
| 23 | - DB::table('permissions')->insert( |
|
| 24 | - [ |
|
| 25 | - /** |
|
| 26 | - * Reporting model permissions. |
|
| 27 | - */ |
|
| 28 | - [ |
|
| 29 | - 'name' => 'find', |
|
| 30 | - 'model' => 'reports', |
|
| 31 | - 'created_at' => \DB::raw('NOW()'), |
|
| 32 | - 'updated_at' => \DB::raw('NOW()') |
|
| 33 | - ], |
|
| 34 | - [ |
|
| 35 | - 'name' => 'search', |
|
| 36 | - 'model' => 'reports', |
|
| 37 | - 'created_at' => \DB::raw('NOW()'), |
|
| 38 | - 'updated_at' => \DB::raw('NOW()') |
|
| 39 | - ], |
|
| 40 | - [ |
|
| 41 | - 'name' => 'list', |
|
| 42 | - 'model' => 'reports', |
|
| 43 | - 'created_at' => \DB::raw('NOW()'), |
|
| 44 | - 'updated_at' => \DB::raw('NOW()') |
|
| 45 | - ], |
|
| 46 | - [ |
|
| 47 | - 'name' => 'findby', |
|
| 48 | - 'model' => 'reports', |
|
| 49 | - 'created_at' => \DB::raw('NOW()'), |
|
| 50 | - 'updated_at' => \DB::raw('NOW()') |
|
| 51 | - ], |
|
| 52 | - [ |
|
| 53 | - 'name' => 'first', |
|
| 54 | - 'model' => 'reports', |
|
| 55 | - 'created_at' => \DB::raw('NOW()'), |
|
| 56 | - 'updated_at' => \DB::raw('NOW()') |
|
| 57 | - ], |
|
| 58 | - [ |
|
| 59 | - 'name' => 'paginate', |
|
| 60 | - 'model' => 'reports', |
|
| 61 | - 'created_at' => \DB::raw('NOW()'), |
|
| 62 | - 'updated_at' => \DB::raw('NOW()') |
|
| 63 | - ], |
|
| 64 | - [ |
|
| 65 | - 'name' => 'paginateby', |
|
| 66 | - 'model' => 'reports', |
|
| 67 | - 'created_at' => \DB::raw('NOW()'), |
|
| 68 | - 'updated_at' => \DB::raw('NOW()') |
|
| 69 | - ], |
|
| 70 | - [ |
|
| 71 | - 'name' => 'admin_count', |
|
| 72 | - 'model' => 'reports', |
|
| 73 | - 'created_at' => \DB::raw('NOW()'), |
|
| 74 | - 'updated_at' => \DB::raw('NOW()') |
|
| 75 | - ] |
|
| 76 | - ] |
|
| 77 | - ); |
|
| 21 | + * Insert the permissions related to this module. |
|
| 22 | + */ |
|
| 23 | + DB::table('permissions')->insert( |
|
| 24 | + [ |
|
| 25 | + /** |
|
| 26 | + * Reporting model permissions. |
|
| 27 | + */ |
|
| 28 | + [ |
|
| 29 | + 'name' => 'find', |
|
| 30 | + 'model' => 'reports', |
|
| 31 | + 'created_at' => \DB::raw('NOW()'), |
|
| 32 | + 'updated_at' => \DB::raw('NOW()') |
|
| 33 | + ], |
|
| 34 | + [ |
|
| 35 | + 'name' => 'search', |
|
| 36 | + 'model' => 'reports', |
|
| 37 | + 'created_at' => \DB::raw('NOW()'), |
|
| 38 | + 'updated_at' => \DB::raw('NOW()') |
|
| 39 | + ], |
|
| 40 | + [ |
|
| 41 | + 'name' => 'list', |
|
| 42 | + 'model' => 'reports', |
|
| 43 | + 'created_at' => \DB::raw('NOW()'), |
|
| 44 | + 'updated_at' => \DB::raw('NOW()') |
|
| 45 | + ], |
|
| 46 | + [ |
|
| 47 | + 'name' => 'findby', |
|
| 48 | + 'model' => 'reports', |
|
| 49 | + 'created_at' => \DB::raw('NOW()'), |
|
| 50 | + 'updated_at' => \DB::raw('NOW()') |
|
| 51 | + ], |
|
| 52 | + [ |
|
| 53 | + 'name' => 'first', |
|
| 54 | + 'model' => 'reports', |
|
| 55 | + 'created_at' => \DB::raw('NOW()'), |
|
| 56 | + 'updated_at' => \DB::raw('NOW()') |
|
| 57 | + ], |
|
| 58 | + [ |
|
| 59 | + 'name' => 'paginate', |
|
| 60 | + 'model' => 'reports', |
|
| 61 | + 'created_at' => \DB::raw('NOW()'), |
|
| 62 | + 'updated_at' => \DB::raw('NOW()') |
|
| 63 | + ], |
|
| 64 | + [ |
|
| 65 | + 'name' => 'paginateby', |
|
| 66 | + 'model' => 'reports', |
|
| 67 | + 'created_at' => \DB::raw('NOW()'), |
|
| 68 | + 'updated_at' => \DB::raw('NOW()') |
|
| 69 | + ], |
|
| 70 | + [ |
|
| 71 | + 'name' => 'admin_count', |
|
| 72 | + 'model' => 'reports', |
|
| 73 | + 'created_at' => \DB::raw('NOW()'), |
|
| 74 | + 'updated_at' => \DB::raw('NOW()') |
|
| 75 | + ] |
|
| 76 | + ] |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - /** |
|
| 79 | + /** |
|
| 80 | 80 | * Assign the permissions to the admin group. |
| 81 | 81 | */ |
| 82 | 82 | $permissionIds = DB::table('permissions')->whereIn('model', ['reports'])->select('id')->lists('id'); |
@@ -5,44 +5,44 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class LogObserver { |
| 7 | 7 | |
| 8 | - public function saving($model) |
|
| 9 | - { |
|
| 10 | - // |
|
| 11 | - } |
|
| 12 | - |
|
| 13 | - public function saved($model) |
|
| 14 | - { |
|
| 15 | - // |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - public function creating($model) |
|
| 19 | - { |
|
| 20 | - // |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function created($model) |
|
| 24 | - { |
|
| 25 | - // |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function updating($model) |
|
| 29 | - { |
|
| 30 | - // |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function updated($model) |
|
| 34 | - { |
|
| 35 | - // |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function deleting($model) |
|
| 39 | - { |
|
| 40 | - // |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function deleted($model) |
|
| 44 | - { |
|
| 45 | - // |
|
| 46 | - } |
|
| 8 | + public function saving($model) |
|
| 9 | + { |
|
| 10 | + // |
|
| 11 | + } |
|
| 12 | + |
|
| 13 | + public function saved($model) |
|
| 14 | + { |
|
| 15 | + // |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + public function creating($model) |
|
| 19 | + { |
|
| 20 | + // |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function created($model) |
|
| 24 | + { |
|
| 25 | + // |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function updating($model) |
|
| 29 | + { |
|
| 30 | + // |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function updated($model) |
|
| 34 | + { |
|
| 35 | + // |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function deleting($model) |
|
| 39 | + { |
|
| 40 | + // |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function deleted($model) |
|
| 44 | + { |
|
| 45 | + // |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | } |
| 49 | 49 | \ No newline at end of file |
@@ -8,16 +8,16 @@ |
||
| 8 | 8 | class ReportsController extends BaseApiController |
| 9 | 9 | { |
| 10 | 10 | /** |
| 11 | - * The name of the model that is used by the base api controller |
|
| 12 | - * to preform actions like (add, edit ... etc). |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $model = 'reports'; |
|
| 11 | + * The name of the model that is used by the base api controller |
|
| 12 | + * to preform actions like (add, edit ... etc). |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $model = 'reports'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * List of all route actions that the base api controller |
|
| 19 | - * will skip permissions check for them. |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $skipPermissionCheck = ['find', 'first']; |
|
| 17 | + /** |
|
| 18 | + * List of all route actions that the base api controller |
|
| 19 | + * will skip permissions check for them. |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $skipPermissionCheck = ['find', 'first']; |
|
| 23 | 23 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | * to preform actions like (add, edit ... etc). |
| 13 | 13 | * @var string |
| 14 | 14 | */ |
| 15 | - protected $model = 'reports'; |
|
| 15 | + protected $model = 'reports'; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * List of all route actions that the base api controller |