@@ -6,27 +6,27 @@ |
||
6 | 6 | |
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Bootstrap the module services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'notifications'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'notifications'); |
|
9 | + /** |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'notifications'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'notifications'); |
|
18 | 18 | |
19 | - $this->loadMigrationsFrom(module_path('notifications', 'Database/Migrations', 'app')); |
|
20 | - $this->loadFactoriesFrom(module_path('notifications', 'Database/Factories', 'app')); |
|
21 | - } |
|
19 | + $this->loadMigrationsFrom(module_path('notifications', 'Database/Migrations', 'app')); |
|
20 | + $this->loadFactoriesFrom(module_path('notifications', 'Database/Factories', 'app')); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Register the module services. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register() |
|
29 | - { |
|
30 | - $this->app->register(RouteServiceProvider::class); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Register the module services. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register() |
|
29 | + { |
|
30 | + $this->app->register(RouteServiceProvider::class); |
|
31 | + } |
|
32 | 32 | } |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class Notification extends JsonResource |
8 | 8 | { |
9 | - /** |
|
10 | - * Transform the resource into an array. |
|
11 | - * |
|
12 | - * @param Request $request |
|
13 | - * @return array |
|
14 | - */ |
|
15 | - public function toArray($request) |
|
16 | - { |
|
17 | - if (! $this->resource) { |
|
18 | - return []; |
|
19 | - } |
|
9 | + /** |
|
10 | + * Transform the resource into an array. |
|
11 | + * |
|
12 | + * @param Request $request |
|
13 | + * @return array |
|
14 | + */ |
|
15 | + public function toArray($request) |
|
16 | + { |
|
17 | + if (! $this->resource) { |
|
18 | + return []; |
|
19 | + } |
|
20 | 20 | |
21 | - return [ |
|
22 | - 'id' => $this->id, |
|
23 | - 'type' => $this->type, |
|
24 | - 'data' => $this->data, |
|
25 | - 'read_at' => $this->read_at, |
|
26 | - 'created_at' => $this->created_at, |
|
27 | - 'updated_at' => $this->updated_at, |
|
28 | - ]; |
|
29 | - } |
|
21 | + return [ |
|
22 | + 'id' => $this->id, |
|
23 | + 'type' => $this->type, |
|
24 | + 'data' => $this->data, |
|
25 | + 'read_at' => $this->read_at, |
|
26 | + 'created_at' => $this->created_at, |
|
27 | + 'updated_at' => $this->updated_at, |
|
28 | + ]; |
|
29 | + } |
|
30 | 30 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | */ |
18 | 18 | public function toArray($request) |
19 | 19 | { |
20 | - if (! $this->resource) { |
|
20 | + if ( ! $this->resource) { |
|
21 | 21 | return []; |
22 | 22 | } |
23 | 23 |
@@ -10,65 +10,65 @@ |
||
10 | 10 | |
11 | 11 | class NotificationController extends BaseApiController |
12 | 12 | { |
13 | - /** |
|
14 | - * List of all route actions that the base api controller |
|
15 | - * will skip permissions check for them. |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $skipPermissionCheck = ['markAsRead', 'markAllAsRead', 'index', 'unread']; |
|
13 | + /** |
|
14 | + * List of all route actions that the base api controller |
|
15 | + * will skip permissions check for them. |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $skipPermissionCheck = ['markAsRead', 'markAllAsRead', 'index', 'unread']; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Init new object. |
|
22 | - * |
|
23 | - * @param NotificationRepository $repo |
|
24 | - * @param CoreConfig $config |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - public function __construct(NotificationRepository $repo, CoreConfig $config) |
|
28 | - { |
|
29 | - parent::__construct($repo, $config, 'App\Modules\Notifications\Http\Resources\Notification'); |
|
30 | - } |
|
20 | + /** |
|
21 | + * Init new object. |
|
22 | + * |
|
23 | + * @param NotificationRepository $repo |
|
24 | + * @param CoreConfig $config |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + public function __construct(NotificationRepository $repo, CoreConfig $config) |
|
28 | + { |
|
29 | + parent::__construct($repo, $config, 'App\Modules\Notifications\Http\Resources\Notification'); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Retrieve all notifications of the logged in user. |
|
34 | - * |
|
35 | - * @param Request $request |
|
36 | - * @return \Illuminate\Http\Response |
|
37 | - */ |
|
38 | - public function index(Request $request) |
|
39 | - { |
|
40 | - return $this->modelResource::collection($this->repo->my($request->query('perPage'))); |
|
41 | - } |
|
32 | + /** |
|
33 | + * Retrieve all notifications of the logged in user. |
|
34 | + * |
|
35 | + * @param Request $request |
|
36 | + * @return \Illuminate\Http\Response |
|
37 | + */ |
|
38 | + public function index(Request $request) |
|
39 | + { |
|
40 | + return $this->modelResource::collection($this->repo->my($request->query('perPage'))); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Retrieve unread notifications of the logged in user. |
|
45 | - * |
|
46 | - * @param Request $request |
|
47 | - * @return \Illuminate\Http\Response |
|
48 | - */ |
|
49 | - public function unread(Request $request) |
|
50 | - { |
|
51 | - return $this->modelResource::collection($this->repo->unread($request->query('perPage'))); |
|
52 | - } |
|
43 | + /** |
|
44 | + * Retrieve unread notifications of the logged in user. |
|
45 | + * |
|
46 | + * @param Request $request |
|
47 | + * @return \Illuminate\Http\Response |
|
48 | + */ |
|
49 | + public function unread(Request $request) |
|
50 | + { |
|
51 | + return $this->modelResource::collection($this->repo->unread($request->query('perPage'))); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Mark the notification as read. |
|
56 | - * |
|
57 | - * @param integer $id Id of the notification. |
|
58 | - * @return \Illuminate\Http\Response |
|
59 | - */ |
|
60 | - public function markAsRead($id) |
|
61 | - { |
|
62 | - return new GeneralResource($this->repo->markAsRead($id)); |
|
63 | - } |
|
54 | + /** |
|
55 | + * Mark the notification as read. |
|
56 | + * |
|
57 | + * @param integer $id Id of the notification. |
|
58 | + * @return \Illuminate\Http\Response |
|
59 | + */ |
|
60 | + public function markAsRead($id) |
|
61 | + { |
|
62 | + return new GeneralResource($this->repo->markAsRead($id)); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Mark all notifications as read. |
|
67 | - * |
|
68 | - * @return \Illuminate\Http\Response |
|
69 | - */ |
|
70 | - public function markAllAsRead() |
|
71 | - { |
|
72 | - return new GeneralResource($this->repo->markAllAsRead()); |
|
73 | - } |
|
65 | + /** |
|
66 | + * Mark all notifications as read. |
|
67 | + * |
|
68 | + * @return \Illuminate\Http\Response |
|
69 | + */ |
|
70 | + public function markAllAsRead() |
|
71 | + { |
|
72 | + return new GeneralResource($this->repo->markAllAsRead()); |
|
73 | + } |
|
74 | 74 | } |
@@ -4,26 +4,26 @@ |
||
4 | 4 | |
5 | 5 | class Core implements BaseFactoryInterface |
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 | - */ |
|
17 | - public function __call($name, $arguments) |
|
18 | - { |
|
19 | - foreach (\Module::all() as $module) { |
|
20 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
21 | - $model = ucfirst(\Str::singular($name)); |
|
22 | - $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
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 | + public function __call($name, $arguments) |
|
18 | + { |
|
19 | + foreach (\Module::all() as $module) { |
|
20 | + $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
21 | + $model = ucfirst(\Str::singular($name)); |
|
22 | + $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
23 | 23 | |
24 | - if (class_exists($class)) { |
|
25 | - return \App::make($class); |
|
26 | - } |
|
27 | - } |
|
28 | - } |
|
24 | + if (class_exists($class)) { |
|
25 | + return \App::make($class); |
|
26 | + } |
|
27 | + } |
|
28 | + } |
|
29 | 29 | } |
@@ -17,9 +17,9 @@ |
||
17 | 17 | public function __call($name, $arguments) |
18 | 18 | { |
19 | 19 | foreach (\Module::all() as $module) { |
20 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
20 | + $nameSpace = 'App\\Modules\\'.$module['basename']; |
|
21 | 21 | $model = ucfirst(\Str::singular($name)); |
22 | - $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
22 | + $class = $nameSpace.'\\Repositories\\'.$model.'Repository'; |
|
23 | 23 | |
24 | 24 | if (class_exists($class)) { |
25 | 25 | return \App::make($class); |
@@ -6,53 +6,53 @@ |
||
6 | 6 | |
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Bootstrap the module services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
18 | - |
|
19 | - $this->loadMigrationsFrom(module_path('core', 'Database/Migrations', 'app')); |
|
20 | - $this->loadFactoriesFrom(module_path('core', 'Database/Factories', 'app')); |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * Register the module services. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register() |
|
29 | - { |
|
30 | - //Bind Core Facade to the Service Container |
|
31 | - $this->app->singleton('Core', function () { |
|
32 | - return new \App\Modules\Core\Core; |
|
33 | - }); |
|
34 | - |
|
35 | - //Bind ErrorHandler Facade to the Service Container |
|
36 | - $this->app->singleton('ErrorHandler', function () { |
|
37 | - return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | - }); |
|
39 | - |
|
40 | - //Bind CoreConfig Facade to the Service Container |
|
41 | - $this->app->singleton('CoreConfig', function () { |
|
42 | - return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | - }); |
|
44 | - |
|
45 | - //Bind Media Facade to the Service Container |
|
46 | - $this->app->singleton('Media', function () { |
|
47 | - return new \App\Modules\Core\Utl\Media; |
|
48 | - }); |
|
49 | - |
|
50 | - //Bind ApiConsumer Facade to the Service Container |
|
51 | - $this->app->singleton('ApiConsumer', function () { |
|
52 | - $app = app(); |
|
53 | - return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
54 | - }); |
|
9 | + /** |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
18 | + |
|
19 | + $this->loadMigrationsFrom(module_path('core', 'Database/Migrations', 'app')); |
|
20 | + $this->loadFactoriesFrom(module_path('core', 'Database/Factories', 'app')); |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * Register the module services. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register() |
|
29 | + { |
|
30 | + //Bind Core Facade to the Service Container |
|
31 | + $this->app->singleton('Core', function () { |
|
32 | + return new \App\Modules\Core\Core; |
|
33 | + }); |
|
34 | + |
|
35 | + //Bind ErrorHandler Facade to the Service Container |
|
36 | + $this->app->singleton('ErrorHandler', function () { |
|
37 | + return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | + }); |
|
39 | + |
|
40 | + //Bind CoreConfig Facade to the Service Container |
|
41 | + $this->app->singleton('CoreConfig', function () { |
|
42 | + return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | + }); |
|
44 | + |
|
45 | + //Bind Media Facade to the Service Container |
|
46 | + $this->app->singleton('Media', function () { |
|
47 | + return new \App\Modules\Core\Utl\Media; |
|
48 | + }); |
|
49 | + |
|
50 | + //Bind ApiConsumer Facade to the Service Container |
|
51 | + $this->app->singleton('ApiConsumer', function () { |
|
52 | + $app = app(); |
|
53 | + return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
54 | + }); |
|
55 | 55 | |
56 | - $this->app->register(RouteServiceProvider::class); |
|
57 | - } |
|
56 | + $this->app->register(RouteServiceProvider::class); |
|
57 | + } |
|
58 | 58 | } |
@@ -28,27 +28,27 @@ |
||
28 | 28 | public function register() |
29 | 29 | { |
30 | 30 | //Bind Core Facade to the Service Container |
31 | - $this->app->singleton('Core', function () { |
|
31 | + $this->app->singleton('Core', function() { |
|
32 | 32 | return new \App\Modules\Core\Core; |
33 | 33 | }); |
34 | 34 | |
35 | 35 | //Bind ErrorHandler Facade to the Service Container |
36 | - $this->app->singleton('ErrorHandler', function () { |
|
36 | + $this->app->singleton('ErrorHandler', function() { |
|
37 | 37 | return new \App\Modules\Core\Utl\ErrorHandler; |
38 | 38 | }); |
39 | 39 | |
40 | 40 | //Bind CoreConfig Facade to the Service Container |
41 | - $this->app->singleton('CoreConfig', function () { |
|
41 | + $this->app->singleton('CoreConfig', function() { |
|
42 | 42 | return new \App\Modules\Core\Utl\CoreConfig; |
43 | 43 | }); |
44 | 44 | |
45 | 45 | //Bind Media Facade to the Service Container |
46 | - $this->app->singleton('Media', function () { |
|
46 | + $this->app->singleton('Media', function() { |
|
47 | 47 | return new \App\Modules\Core\Utl\Media; |
48 | 48 | }); |
49 | 49 | |
50 | 50 | //Bind ApiConsumer Facade to the Service Container |
51 | - $this->app->singleton('ApiConsumer', function () { |
|
51 | + $this->app->singleton('ApiConsumer', function() { |
|
52 | 52 | $app = app(); |
53 | 53 | return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
54 | 54 | }); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | \Auth::shouldUse('api'); |
123 | 123 | $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
124 | 124 | |
125 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
125 | + if ( ! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | 126 | $user = \Auth::user(); |
127 | 127 | $isPasswordClient = $user->token()->client->password_client; |
128 | 128 | $this->updateLocaleAndTimezone($user); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
135 | - } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
135 | + } elseif ( ! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | 136 | } else { |
137 | 137 | \ErrorHandler::noPermissions(); |
138 | 138 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | |
204 | 204 | if ($timezone && $timezone !== $user->timezone) { |
205 | 205 | $user->timezone = $timezone; |
206 | - $update = true; |
|
206 | + $update = true; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | if ($update) { |
@@ -10,204 +10,204 @@ |
||
10 | 10 | |
11 | 11 | class BaseApiController extends Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * The config implementation. |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $config; |
|
19 | - |
|
20 | - /** |
|
21 | - * The relations implementation. |
|
22 | - * |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $relations; |
|
26 | - |
|
27 | - /** |
|
28 | - * The repo implementation. |
|
29 | - * |
|
30 | - * @var object |
|
31 | - */ |
|
32 | - protected $repo; |
|
33 | - |
|
34 | - /** |
|
35 | - * Init new object. |
|
36 | - * |
|
37 | - * @param mixed $repo |
|
38 | - * @param \App\Modules\Core\Utl\CoreConfig $config |
|
39 | - * @param string $modelResource |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function __construct($repo, $config, $modelResource) |
|
43 | - { |
|
44 | - $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
45 | - $this->modelResource = $modelResource; |
|
46 | - $this->config = $config->getConfig(); |
|
47 | - $this->modelName = explode('\\', get_called_class()); |
|
48 | - $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
49 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
50 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
51 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
52 | - $route = explode('@', \Route::currentRouteAction())[1]; |
|
53 | - |
|
54 | - $this->setSessions(); |
|
55 | - $this->checkPermission($route); |
|
56 | - $this->setRelations($route); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Fetch all records with relations from storage. |
|
61 | - * |
|
62 | - * @param Request $request |
|
63 | - * @return \Illuminate\Http\Response |
|
64 | - */ |
|
65 | - public function index(Request $request) |
|
66 | - { |
|
67 | - return $this->modelResource::collection($this->repo->list($this->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Fetch the single object with relations from storage. |
|
72 | - * |
|
73 | - * @param integer $id Id of the requested model. |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function find($id) |
|
77 | - { |
|
78 | - return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Delete by the given id from storage. |
|
83 | - * |
|
84 | - * @param integer $id Id of the deleted model. |
|
85 | - * @return \Illuminate\Http\Response |
|
86 | - */ |
|
87 | - public function delete($id) |
|
88 | - { |
|
89 | - return new GeneralResource($this->repo->delete($id)); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Return the deleted models in pages based on the given conditions. |
|
94 | - * |
|
95 | - * @param Request $request |
|
96 | - * @return \Illuminate\Http\Response |
|
97 | - */ |
|
98 | - public function deleted(Request $request) |
|
99 | - { |
|
100 | - return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Restore the deleted model. |
|
105 | - * |
|
106 | - * @param integer $id Id of the restored model. |
|
107 | - * @return \Illuminate\Http\Response |
|
108 | - */ |
|
109 | - public function restore($id) |
|
110 | - { |
|
111 | - return new GeneralResource($this->repo->restore($id)); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Check if the logged in user can do the given permission. |
|
116 | - * |
|
117 | - * @param string $permission |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - private function checkPermission($permission) |
|
121 | - { |
|
122 | - \Auth::shouldUse('api'); |
|
123 | - $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
13 | + /** |
|
14 | + * The config implementation. |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $config; |
|
19 | + |
|
20 | + /** |
|
21 | + * The relations implementation. |
|
22 | + * |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $relations; |
|
26 | + |
|
27 | + /** |
|
28 | + * The repo implementation. |
|
29 | + * |
|
30 | + * @var object |
|
31 | + */ |
|
32 | + protected $repo; |
|
33 | + |
|
34 | + /** |
|
35 | + * Init new object. |
|
36 | + * |
|
37 | + * @param mixed $repo |
|
38 | + * @param \App\Modules\Core\Utl\CoreConfig $config |
|
39 | + * @param string $modelResource |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function __construct($repo, $config, $modelResource) |
|
43 | + { |
|
44 | + $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
45 | + $this->modelResource = $modelResource; |
|
46 | + $this->config = $config->getConfig(); |
|
47 | + $this->modelName = explode('\\', get_called_class()); |
|
48 | + $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
49 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
50 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
51 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
52 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
53 | + |
|
54 | + $this->setSessions(); |
|
55 | + $this->checkPermission($route); |
|
56 | + $this->setRelations($route); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Fetch all records with relations from storage. |
|
61 | + * |
|
62 | + * @param Request $request |
|
63 | + * @return \Illuminate\Http\Response |
|
64 | + */ |
|
65 | + public function index(Request $request) |
|
66 | + { |
|
67 | + return $this->modelResource::collection($this->repo->list($this->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Fetch the single object with relations from storage. |
|
72 | + * |
|
73 | + * @param integer $id Id of the requested model. |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function find($id) |
|
77 | + { |
|
78 | + return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Delete by the given id from storage. |
|
83 | + * |
|
84 | + * @param integer $id Id of the deleted model. |
|
85 | + * @return \Illuminate\Http\Response |
|
86 | + */ |
|
87 | + public function delete($id) |
|
88 | + { |
|
89 | + return new GeneralResource($this->repo->delete($id)); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Return the deleted models in pages based on the given conditions. |
|
94 | + * |
|
95 | + * @param Request $request |
|
96 | + * @return \Illuminate\Http\Response |
|
97 | + */ |
|
98 | + public function deleted(Request $request) |
|
99 | + { |
|
100 | + return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Restore the deleted model. |
|
105 | + * |
|
106 | + * @param integer $id Id of the restored model. |
|
107 | + * @return \Illuminate\Http\Response |
|
108 | + */ |
|
109 | + public function restore($id) |
|
110 | + { |
|
111 | + return new GeneralResource($this->repo->restore($id)); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Check if the logged in user can do the given permission. |
|
116 | + * |
|
117 | + * @param string $permission |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + private function checkPermission($permission) |
|
121 | + { |
|
122 | + \Auth::shouldUse('api'); |
|
123 | + $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
124 | 124 | |
125 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | - $user = \Auth::user(); |
|
127 | - $isPasswordClient = $user->token()->client->password_client; |
|
128 | - $this->updateLocaleAndTimezone($user); |
|
129 | - |
|
130 | - if ($user->blocked) { |
|
131 | - \ErrorHandler::userIsBlocked(); |
|
132 | - } |
|
133 | - |
|
134 | - if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
135 | - } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | - } else { |
|
137 | - \ErrorHandler::noPermissions(); |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Set sessions based on the given headers in the request. |
|
144 | - * |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - private function setSessions() |
|
148 | - { |
|
149 | - \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
150 | - |
|
151 | - $locale = \Request::header('locale'); |
|
152 | - switch ($locale) { |
|
153 | - case 'en': |
|
154 | - \App::setLocale('en'); |
|
155 | - \Session::put('locale', 'en'); |
|
156 | - break; |
|
157 | - |
|
158 | - case 'ar': |
|
159 | - \App::setLocale('ar'); |
|
160 | - \Session::put('locale', 'ar'); |
|
161 | - break; |
|
162 | - |
|
163 | - case 'all': |
|
164 | - \App::setLocale('en'); |
|
165 | - \Session::put('locale', 'all'); |
|
166 | - break; |
|
167 | - |
|
168 | - default: |
|
169 | - \App::setLocale('en'); |
|
170 | - \Session::put('locale', 'en'); |
|
171 | - break; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Set relation based on the called api. |
|
177 | - * |
|
178 | - * @param string $route |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - private function setRelations($route) |
|
182 | - { |
|
183 | - $route = $route !== 'index' ? $route : 'list'; |
|
184 | - $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
185 | - $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Update the logged in user locale and time zone. |
|
190 | - * |
|
191 | - * @param object $user |
|
192 | - * @return void |
|
193 | - */ |
|
194 | - private function updateLocaleAndTimezone($user) |
|
195 | - { |
|
196 | - $update = false; |
|
197 | - $locale = \Session::get('locale'); |
|
198 | - $timezone = \Session::get('time-zone'); |
|
199 | - if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
200 | - $user->locale = $locale; |
|
201 | - $update = true; |
|
202 | - } |
|
203 | - |
|
204 | - if ($timezone && $timezone !== $user->timezone) { |
|
205 | - $user->timezone = $timezone; |
|
206 | - $update = true; |
|
207 | - } |
|
208 | - |
|
209 | - if ($update) { |
|
210 | - $user->save(); |
|
211 | - } |
|
212 | - } |
|
125 | + if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | + $user = \Auth::user(); |
|
127 | + $isPasswordClient = $user->token()->client->password_client; |
|
128 | + $this->updateLocaleAndTimezone($user); |
|
129 | + |
|
130 | + if ($user->blocked) { |
|
131 | + \ErrorHandler::userIsBlocked(); |
|
132 | + } |
|
133 | + |
|
134 | + if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
135 | + } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | + } else { |
|
137 | + \ErrorHandler::noPermissions(); |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Set sessions based on the given headers in the request. |
|
144 | + * |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + private function setSessions() |
|
148 | + { |
|
149 | + \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
150 | + |
|
151 | + $locale = \Request::header('locale'); |
|
152 | + switch ($locale) { |
|
153 | + case 'en': |
|
154 | + \App::setLocale('en'); |
|
155 | + \Session::put('locale', 'en'); |
|
156 | + break; |
|
157 | + |
|
158 | + case 'ar': |
|
159 | + \App::setLocale('ar'); |
|
160 | + \Session::put('locale', 'ar'); |
|
161 | + break; |
|
162 | + |
|
163 | + case 'all': |
|
164 | + \App::setLocale('en'); |
|
165 | + \Session::put('locale', 'all'); |
|
166 | + break; |
|
167 | + |
|
168 | + default: |
|
169 | + \App::setLocale('en'); |
|
170 | + \Session::put('locale', 'en'); |
|
171 | + break; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Set relation based on the called api. |
|
177 | + * |
|
178 | + * @param string $route |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + private function setRelations($route) |
|
182 | + { |
|
183 | + $route = $route !== 'index' ? $route : 'list'; |
|
184 | + $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
185 | + $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Update the logged in user locale and time zone. |
|
190 | + * |
|
191 | + * @param object $user |
|
192 | + * @return void |
|
193 | + */ |
|
194 | + private function updateLocaleAndTimezone($user) |
|
195 | + { |
|
196 | + $update = false; |
|
197 | + $locale = \Session::get('locale'); |
|
198 | + $timezone = \Session::get('time-zone'); |
|
199 | + if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
200 | + $user->locale = $locale; |
|
201 | + $update = true; |
|
202 | + } |
|
203 | + |
|
204 | + if ($timezone && $timezone !== $user->timezone) { |
|
205 | + $user->timezone = $timezone; |
|
206 | + $update = true; |
|
207 | + } |
|
208 | + |
|
209 | + if ($update) { |
|
210 | + $user->save(); |
|
211 | + } |
|
212 | + } |
|
213 | 213 | } |
@@ -6,32 +6,32 @@ |
||
6 | 6 | |
7 | 7 | class Setting extends JsonResource |
8 | 8 | { |
9 | - /** |
|
10 | - * Indicates if the resource's collection keys should be preserved. |
|
11 | - * |
|
12 | - * @var bool |
|
13 | - */ |
|
14 | - public $preserveKeys = true; |
|
9 | + /** |
|
10 | + * Indicates if the resource's collection keys should be preserved. |
|
11 | + * |
|
12 | + * @var bool |
|
13 | + */ |
|
14 | + public $preserveKeys = true; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Transform the resource into an array. |
|
18 | - * |
|
19 | - * @param Request $request |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function toArray($request) |
|
23 | - { |
|
24 | - if (! $this->resource) { |
|
25 | - return []; |
|
26 | - } |
|
16 | + /** |
|
17 | + * Transform the resource into an array. |
|
18 | + * |
|
19 | + * @param Request $request |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function toArray($request) |
|
23 | + { |
|
24 | + if (! $this->resource) { |
|
25 | + return []; |
|
26 | + } |
|
27 | 27 | |
28 | - return [ |
|
29 | - 'id' => $this->id, |
|
30 | - 'name' => $this->name, |
|
31 | - 'value' => $this->value, |
|
32 | - 'key' => $this->key, |
|
33 | - 'created_at' => $this->created_at, |
|
34 | - 'updated_at' => $this->updated_at, |
|
35 | - ]; |
|
36 | - } |
|
28 | + return [ |
|
29 | + 'id' => $this->id, |
|
30 | + 'name' => $this->name, |
|
31 | + 'value' => $this->value, |
|
32 | + 'key' => $this->key, |
|
33 | + 'created_at' => $this->created_at, |
|
34 | + 'updated_at' => $this->updated_at, |
|
35 | + ]; |
|
36 | + } |
|
37 | 37 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | */ |
18 | 18 | public function toArray($request) |
19 | 19 | { |
20 | - if (! $this->resource) { |
|
20 | + if ( ! $this->resource) { |
|
21 | 21 | return []; |
22 | 22 | } |
23 | 23 |
@@ -6,27 +6,27 @@ |
||
6 | 6 | |
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Bootstrap the module services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'reporting'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'reporting'); |
|
9 | + /** |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'reporting'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'reporting'); |
|
18 | 18 | |
19 | - $this->loadMigrationsFrom(module_path('reporting', 'Database/Migrations', 'app')); |
|
20 | - $this->loadFactoriesFrom(module_path('reporting', 'Database/Factories', 'app')); |
|
21 | - } |
|
19 | + $this->loadMigrationsFrom(module_path('reporting', 'Database/Migrations', 'app')); |
|
20 | + $this->loadFactoriesFrom(module_path('reporting', 'Database/Factories', 'app')); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Register the module services. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register() |
|
29 | - { |
|
30 | - $this->app->register(RouteServiceProvider::class); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Register the module services. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register() |
|
29 | + { |
|
30 | + $this->app->register(RouteServiceProvider::class); |
|
31 | + } |
|
32 | 32 | } |
@@ -6,24 +6,24 @@ |
||
6 | 6 | |
7 | 7 | class Report extends JsonResource |
8 | 8 | { |
9 | - /** |
|
10 | - * Transform the resource into an array. |
|
11 | - * |
|
12 | - * @param Request $request |
|
13 | - * @return array |
|
14 | - */ |
|
15 | - public function toArray($request) |
|
16 | - { |
|
17 | - if (! $this->resource) { |
|
18 | - return []; |
|
19 | - } |
|
9 | + /** |
|
10 | + * Transform the resource into an array. |
|
11 | + * |
|
12 | + * @param Request $request |
|
13 | + * @return array |
|
14 | + */ |
|
15 | + public function toArray($request) |
|
16 | + { |
|
17 | + if (! $this->resource) { |
|
18 | + return []; |
|
19 | + } |
|
20 | 20 | |
21 | - return [ |
|
22 | - 'id' => $this->id, |
|
23 | - 'report_name' => $this->report_name, |
|
24 | - 'view_name' => $this->view_name, |
|
25 | - 'created_at' => $this->created_at, |
|
26 | - 'updated_at' => $this->updated_at, |
|
27 | - ]; |
|
28 | - } |
|
21 | + return [ |
|
22 | + 'id' => $this->id, |
|
23 | + 'report_name' => $this->report_name, |
|
24 | + 'view_name' => $this->view_name, |
|
25 | + 'created_at' => $this->created_at, |
|
26 | + 'updated_at' => $this->updated_at, |
|
27 | + ]; |
|
28 | + } |
|
29 | 29 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | */ |
18 | 18 | public function toArray($request) |
19 | 19 | { |
20 | - if (! $this->resource) { |
|
20 | + if ( ! $this->resource) { |
|
21 | 21 | return []; |
22 | 22 | } |
23 | 23 |