@@ -6,20 +6,20 @@ |
||
6 | 6 | |
7 | 7 | class Report extends JsonResource |
8 | 8 | { |
9 | - /** |
|
10 | - * Transform the resource into an array. |
|
11 | - * |
|
12 | - * @param \Illuminate\Http\Request $request |
|
13 | - * @return array |
|
14 | - */ |
|
15 | - public function toArray($request) |
|
16 | - { |
|
17 | - return [ |
|
18 | - 'id' => $this->id, |
|
19 | - 'reportName' => $this->report_name, |
|
20 | - 'viewName' => $this->view_name, |
|
21 | - 'createdAt' => $this->created_at, |
|
22 | - 'updatedAt' => $this->updated_at, |
|
23 | - ]; |
|
24 | - } |
|
9 | + /** |
|
10 | + * Transform the resource into an array. |
|
11 | + * |
|
12 | + * @param \Illuminate\Http\Request $request |
|
13 | + * @return array |
|
14 | + */ |
|
15 | + public function toArray($request) |
|
16 | + { |
|
17 | + return [ |
|
18 | + 'id' => $this->id, |
|
19 | + 'reportName' => $this->report_name, |
|
20 | + 'viewName' => $this->view_name, |
|
21 | + 'createdAt' => $this->created_at, |
|
22 | + 'updatedAt' => $this->updated_at, |
|
23 | + ]; |
|
24 | + } |
|
25 | 25 | } |
@@ -9,35 +9,35 @@ |
||
9 | 9 | |
10 | 10 | class ReportsController extends BaseApiController |
11 | 11 | { |
12 | - /** |
|
13 | - * List of all route actions that the base api controller |
|
14 | - * will skip permissions check for them. |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $skipPermissionCheck = ['getReport']; |
|
12 | + /** |
|
13 | + * List of all route actions that the base api controller |
|
14 | + * will skip permissions check for them. |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $skipPermissionCheck = ['getReport']; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Init new object. |
|
21 | - * |
|
22 | - * @param ReportRepository $repo |
|
23 | - * @param CoreConfig $config |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function __construct(ReportRepository $repo, CoreConfig $config) |
|
27 | - { |
|
28 | - parent::__construct($repo, $config, 'App\Modules\Reporting\Http\Resources\Report'); |
|
29 | - } |
|
19 | + /** |
|
20 | + * Init new object. |
|
21 | + * |
|
22 | + * @param ReportRepository $repo |
|
23 | + * @param CoreConfig $config |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function __construct(ReportRepository $repo, CoreConfig $config) |
|
27 | + { |
|
28 | + parent::__construct($repo, $config, 'App\Modules\Reporting\Http\Resources\Report'); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Render the given report name with the given conditions. |
|
33 | - * |
|
34 | - * @param \Illuminate\Http\Request $request |
|
35 | - * @param string $reportName Name of the requested report |
|
36 | - * @param integer $perPage Number of rows per page default all data. |
|
37 | - * @return \Illuminate\Http\Response |
|
38 | - */ |
|
39 | - public function getReport(Request $request, $reportName, $perPage = 0) |
|
40 | - { |
|
41 | - return \Response::json($this->repo->getReport($reportName, $request->all(), $perPage), 200); |
|
42 | - } |
|
31 | + /** |
|
32 | + * Render the given report name with the given conditions. |
|
33 | + * |
|
34 | + * @param \Illuminate\Http\Request $request |
|
35 | + * @param string $reportName Name of the requested report |
|
36 | + * @param integer $perPage Number of rows per page default all data. |
|
37 | + * @return \Illuminate\Http\Response |
|
38 | + */ |
|
39 | + public function getReport(Request $request, $reportName, $perPage = 0) |
|
40 | + { |
|
41 | + return \Response::json($this->repo->getReport($reportName, $request->all(), $perPage), 200); |
|
42 | + } |
|
43 | 43 | } |
@@ -9,41 +9,41 @@ |
||
9 | 9 | |
10 | 10 | class ConfirmEmail extends Notification implements ShouldQueue |
11 | 11 | { |
12 | - use Queueable; |
|
12 | + use Queueable; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Init new object. |
|
16 | - * |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - // |
|
22 | - } |
|
14 | + /** |
|
15 | + * Init new object. |
|
16 | + * |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + // |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Get the notification's delivery channels. |
|
26 | - * |
|
27 | - * @param mixed $notifiable |
|
28 | - * @return string[] |
|
29 | - */ |
|
30 | - public function via($notifiable) |
|
31 | - { |
|
32 | - return ['mail']; |
|
33 | - } |
|
24 | + /** |
|
25 | + * Get the notification's delivery channels. |
|
26 | + * |
|
27 | + * @param mixed $notifiable |
|
28 | + * @return string[] |
|
29 | + */ |
|
30 | + public function via($notifiable) |
|
31 | + { |
|
32 | + return ['mail']; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Get the mail representation of the notification. |
|
37 | - * |
|
38 | - * @param mixed $notifiable |
|
39 | - * @return \Illuminate\Notifications\Messages\MailMessage |
|
40 | - */ |
|
41 | - public function toMail($notifiable) |
|
42 | - { |
|
43 | - return (new MailMessage) |
|
44 | - ->subject('Email verification') |
|
45 | - ->line('Email verification') |
|
46 | - ->line('To validate your email click on the button below') |
|
47 | - ->action('Verify your email', config('skeleton.confrim_email_url').'/'.$notifiable->confirmation_code); |
|
48 | - } |
|
35 | + /** |
|
36 | + * Get the mail representation of the notification. |
|
37 | + * |
|
38 | + * @param mixed $notifiable |
|
39 | + * @return \Illuminate\Notifications\Messages\MailMessage |
|
40 | + */ |
|
41 | + public function toMail($notifiable) |
|
42 | + { |
|
43 | + return (new MailMessage) |
|
44 | + ->subject('Email verification') |
|
45 | + ->line('Email verification') |
|
46 | + ->line('To validate your email click on the button below') |
|
47 | + ->action('Verify your email', config('skeleton.confrim_email_url').'/'.$notifiable->confirmation_code); |
|
48 | + } |
|
49 | 49 | } |
@@ -9,43 +9,43 @@ |
||
9 | 9 | |
10 | 10 | class ResetPassword extends Notification implements ShouldQueue |
11 | 11 | { |
12 | - use Queueable; |
|
12 | + use Queueable; |
|
13 | 13 | |
14 | - protected $token; |
|
14 | + protected $token; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Init new object. |
|
18 | - * |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - public function __construct($token) |
|
22 | - { |
|
23 | - $this->token = $token; |
|
24 | - } |
|
16 | + /** |
|
17 | + * Init new object. |
|
18 | + * |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + public function __construct($token) |
|
22 | + { |
|
23 | + $this->token = $token; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Get the notification's delivery channels. |
|
28 | - * |
|
29 | - * @param mixed $notifiable |
|
30 | - * @return string[] |
|
31 | - */ |
|
32 | - public function via($notifiable) |
|
33 | - { |
|
34 | - return ['mail']; |
|
35 | - } |
|
26 | + /** |
|
27 | + * Get the notification's delivery channels. |
|
28 | + * |
|
29 | + * @param mixed $notifiable |
|
30 | + * @return string[] |
|
31 | + */ |
|
32 | + public function via($notifiable) |
|
33 | + { |
|
34 | + return ['mail']; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get the mail representation of the notification. |
|
39 | - * |
|
40 | - * @param mixed $notifiable |
|
41 | - * @return \Illuminate\Notifications\Messages\MailMessage |
|
42 | - */ |
|
43 | - public function toMail($notifiable) |
|
44 | - { |
|
45 | - return (new MailMessage) |
|
46 | - ->subject('Reset passowrd') |
|
47 | - ->line('Reset passowrd') |
|
48 | - ->line('To reset your password click on the button below') |
|
49 | - ->action('Reset password', config('skeleton.reset_password_url').'/'.$this->token); |
|
50 | - } |
|
37 | + /** |
|
38 | + * Get the mail representation of the notification. |
|
39 | + * |
|
40 | + * @param mixed $notifiable |
|
41 | + * @return \Illuminate\Notifications\Messages\MailMessage |
|
42 | + */ |
|
43 | + public function toMail($notifiable) |
|
44 | + { |
|
45 | + return (new MailMessage) |
|
46 | + ->subject('Reset passowrd') |
|
47 | + ->line('Reset passowrd') |
|
48 | + ->line('To reset your password click on the button below') |
|
49 | + ->action('Reset password', config('skeleton.reset_password_url').'/'.$this->token); |
|
50 | + } |
|
51 | 51 | } |
@@ -5,73 +5,73 @@ |
||
5 | 5 | |
6 | 6 | class NotificationRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param Notification $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(Notification $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param Notification $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(Notification $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Retrieve all notifications of the logged in user. |
|
21 | - * |
|
22 | - * @param integer $perPage |
|
23 | - * @return Collection |
|
24 | - */ |
|
25 | - public function list($perPage) |
|
26 | - { |
|
27 | - return \Auth::user()->notifications()->paginate($perPage); |
|
28 | - } |
|
19 | + /** |
|
20 | + * Retrieve all notifications of the logged in user. |
|
21 | + * |
|
22 | + * @param integer $perPage |
|
23 | + * @return Collection |
|
24 | + */ |
|
25 | + public function list($perPage) |
|
26 | + { |
|
27 | + return \Auth::user()->notifications()->paginate($perPage); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Retrieve unread notifications of the logged in user. |
|
32 | - * |
|
33 | - * @param integer $perPage |
|
34 | - * @return Collection |
|
35 | - */ |
|
36 | - public function unread($perPage) |
|
37 | - { |
|
38 | - return \Auth::user()->unreadNotifications()->paginate($perPage); |
|
39 | - } |
|
30 | + /** |
|
31 | + * Retrieve unread notifications of the logged in user. |
|
32 | + * |
|
33 | + * @param integer $perPage |
|
34 | + * @return Collection |
|
35 | + */ |
|
36 | + public function unread($perPage) |
|
37 | + { |
|
38 | + return \Auth::user()->unreadNotifications()->paginate($perPage); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Mark the notification as read. |
|
43 | - * |
|
44 | - * @param integer $id |
|
45 | - * @return object |
|
46 | - */ |
|
47 | - public function markAsRead($id) |
|
48 | - { |
|
49 | - if ($notification = \Auth::user()->unreadNotifications()->where('id', $id)->first()) { |
|
50 | - $notification->markAsRead(); |
|
51 | - } |
|
52 | - } |
|
41 | + /** |
|
42 | + * Mark the notification as read. |
|
43 | + * |
|
44 | + * @param integer $id |
|
45 | + * @return object |
|
46 | + */ |
|
47 | + public function markAsRead($id) |
|
48 | + { |
|
49 | + if ($notification = \Auth::user()->unreadNotifications()->where('id', $id)->first()) { |
|
50 | + $notification->markAsRead(); |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Mark all notifications as read. |
|
56 | - * |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public function markAllAsRead() |
|
60 | - { |
|
61 | - \Auth::user()->unreadNotifications()->update(['read_at' => now()]); |
|
62 | - } |
|
54 | + /** |
|
55 | + * Mark all notifications as read. |
|
56 | + * |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public function markAllAsRead() |
|
60 | + { |
|
61 | + \Auth::user()->unreadNotifications()->update(['read_at' => now()]); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Notify th given user with the given notification. |
|
66 | - * |
|
67 | - * @param collection $users |
|
68 | - * @param string $notification |
|
69 | - * @param object $notificationData |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function notify($users, $notification, $notificationData = false) |
|
73 | - { |
|
74 | - $notification = 'App\Modules\Notifications\Notifications\\'.$notification; |
|
75 | - \Notification::send($users, new $notification($notificationData)); |
|
76 | - } |
|
64 | + /** |
|
65 | + * Notify th given user with the given notification. |
|
66 | + * |
|
67 | + * @param collection $users |
|
68 | + * @param string $notification |
|
69 | + * @param object $notificationData |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function notify($users, $notification, $notificationData = false) |
|
73 | + { |
|
74 | + $notification = 'App\Modules\Notifications\Notifications\\'.$notification; |
|
75 | + \Notification::send($users, new $notification($notificationData)); |
|
76 | + } |
|
77 | 77 | } |
@@ -8,60 +8,60 @@ |
||
8 | 8 | |
9 | 9 | class PushNotificationDeviceRepository extends BaseRepository |
10 | 10 | { |
11 | - /** |
|
12 | - * Init new object. |
|
13 | - * |
|
14 | - * @param PushNotificationDevice $model |
|
15 | - * @return void |
|
16 | - */ |
|
17 | - public function __construct(PushNotificationDevice $model) |
|
18 | - { |
|
19 | - parent::__construct($model); |
|
20 | - } |
|
11 | + /** |
|
12 | + * Init new object. |
|
13 | + * |
|
14 | + * @param PushNotificationDevice $model |
|
15 | + * @return void |
|
16 | + */ |
|
17 | + public function __construct(PushNotificationDevice $model) |
|
18 | + { |
|
19 | + parent::__construct($model); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Register the given device to the logged in user. |
|
24 | - * |
|
25 | - * @param array $data |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function registerDevice($data) |
|
29 | - { |
|
30 | - $data['access_token'] = \Auth::user()->token(); |
|
31 | - $data['user_id'] = \Auth::id(); |
|
32 | - $device = $this->model->where('device_token', $data['device_token'])-> |
|
33 | - where('user_id', $data['user_id'])-> |
|
34 | - first(); |
|
22 | + /** |
|
23 | + * Register the given device to the logged in user. |
|
24 | + * |
|
25 | + * @param array $data |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function registerDevice($data) |
|
29 | + { |
|
30 | + $data['access_token'] = \Auth::user()->token(); |
|
31 | + $data['user_id'] = \Auth::id(); |
|
32 | + $device = $this->model->where('device_token', $data['device_token'])-> |
|
33 | + where('user_id', $data['user_id'])-> |
|
34 | + first(); |
|
35 | 35 | |
36 | - if ($device) { |
|
37 | - $data['id'] = $device->id; |
|
38 | - } |
|
36 | + if ($device) { |
|
37 | + $data['id'] = $device->id; |
|
38 | + } |
|
39 | 39 | |
40 | - return $this->save($data); |
|
41 | - } |
|
40 | + return $this->save($data); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Generate the given message data. |
|
45 | - * |
|
46 | - * @param string $title |
|
47 | - * @param string $message |
|
48 | - * @param array $data |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function generateMessageData($title, $message, $data = []) |
|
52 | - { |
|
53 | - $optionBuilder = new OptionsBuilder(); |
|
54 | - $notificationBuilder = new PayloadNotificationBuilder($title); |
|
55 | - $dataBuilder = new PayloadDataBuilder(); |
|
43 | + /** |
|
44 | + * Generate the given message data. |
|
45 | + * |
|
46 | + * @param string $title |
|
47 | + * @param string $message |
|
48 | + * @param array $data |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function generateMessageData($title, $message, $data = []) |
|
52 | + { |
|
53 | + $optionBuilder = new OptionsBuilder(); |
|
54 | + $notificationBuilder = new PayloadNotificationBuilder($title); |
|
55 | + $dataBuilder = new PayloadDataBuilder(); |
|
56 | 56 | |
57 | - $optionBuilder->setTimeToLive(60 * 20); |
|
58 | - $notificationBuilder->setBody($message); |
|
59 | - $dataBuilder->addData($data); |
|
57 | + $optionBuilder->setTimeToLive(60 * 20); |
|
58 | + $notificationBuilder->setBody($message); |
|
59 | + $dataBuilder->addData($data); |
|
60 | 60 | |
61 | - $options = $optionBuilder->build(); |
|
62 | - $notification = $notificationBuilder->build(); |
|
63 | - $data = $dataBuilder->build(); |
|
61 | + $options = $optionBuilder->build(); |
|
62 | + $notification = $notificationBuilder->build(); |
|
63 | + $data = $dataBuilder->build(); |
|
64 | 64 | |
65 | - return compact('options', 'notification', 'data'); |
|
66 | - } |
|
65 | + return compact('options', 'notification', 'data'); |
|
66 | + } |
|
67 | 67 | } |
@@ -5,32 +5,32 @@ |
||
5 | 5 | |
6 | 6 | class Core implements BaseFactoryInterface |
7 | 7 | { |
8 | - /** |
|
9 | - * Construct the repository class name based on |
|
10 | - * the method name called, search in the |
|
11 | - * given namespaces for the class and |
|
12 | - * return an instance. |
|
13 | - * |
|
14 | - * @param string $name the called method name |
|
15 | - * @param array $arguments the method arguments |
|
16 | - * @return object |
|
17 | - */ |
|
18 | - public function __call($name, $arguments) |
|
19 | - { |
|
20 | - foreach (\Module::all() as $module) { |
|
21 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
22 | - $model = ucfirst(\Str::singular($name)); |
|
23 | - $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
24 | - $decoratedClass = $class . '\\Decorated'; |
|
8 | + /** |
|
9 | + * Construct the repository class name based on |
|
10 | + * the method name called, search in the |
|
11 | + * given namespaces for the class and |
|
12 | + * return an instance. |
|
13 | + * |
|
14 | + * @param string $name the called method name |
|
15 | + * @param array $arguments the method arguments |
|
16 | + * @return object |
|
17 | + */ |
|
18 | + public function __call($name, $arguments) |
|
19 | + { |
|
20 | + foreach (\Module::all() as $module) { |
|
21 | + $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
22 | + $model = ucfirst(\Str::singular($name)); |
|
23 | + $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
24 | + $decoratedClass = $class . '\\Decorated'; |
|
25 | 25 | |
26 | - if (class_exists($class)) { |
|
27 | - $classObj = \App::make($class); |
|
28 | - \App::singleton($class, function ($app) use ($classObj) { |
|
29 | - return new CachingDecorator($classObj, $app['cache.store']); |
|
30 | - }); |
|
26 | + if (class_exists($class)) { |
|
27 | + $classObj = \App::make($class); |
|
28 | + \App::singleton($class, function ($app) use ($classObj) { |
|
29 | + return new CachingDecorator($classObj, $app['cache.store']); |
|
30 | + }); |
|
31 | 31 | |
32 | - return \App::make($class); |
|
33 | - } |
|
34 | - } |
|
35 | - } |
|
32 | + return \App::make($class); |
|
33 | + } |
|
34 | + } |
|
35 | + } |
|
36 | 36 | } |
@@ -5,29 +5,29 @@ |
||
5 | 5 | |
6 | 6 | class SettingRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param Setting $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(Setting $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param Setting $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(Setting $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Save list of settings. |
|
21 | - * |
|
22 | - * @param array $data |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - public function saveMany(array $data) |
|
26 | - { |
|
27 | - \DB::transaction(function () use ($data) { |
|
28 | - foreach ($data as $value) { |
|
29 | - $this->save($value); |
|
30 | - } |
|
31 | - }); |
|
32 | - } |
|
19 | + /** |
|
20 | + * Save list of settings. |
|
21 | + * |
|
22 | + * @param array $data |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + public function saveMany(array $data) |
|
26 | + { |
|
27 | + \DB::transaction(function () use ($data) { |
|
28 | + foreach ($data as $value) { |
|
29 | + $this->save($value); |
|
30 | + } |
|
31 | + }); |
|
32 | + } |
|
33 | 33 | } |
@@ -9,303 +9,303 @@ |
||
9 | 9 | |
10 | 10 | class BaseApiController extends Controller |
11 | 11 | { |
12 | - /** |
|
13 | - * The config implementation. |
|
14 | - * |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $config; |
|
18 | - |
|
19 | - /** |
|
20 | - * The relations implementation. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $relations; |
|
25 | - |
|
26 | - /** |
|
27 | - * The repo implementation. |
|
28 | - * |
|
29 | - * @var object |
|
30 | - */ |
|
31 | - protected $repo; |
|
32 | - |
|
33 | - /** |
|
34 | - * Init new object. |
|
35 | - * |
|
36 | - * @param mixed $repo |
|
37 | - * @param CoreConfig $config |
|
38 | - * @param string $modelResource |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - public function __construct($repo, $config, $modelResource) |
|
42 | - { |
|
43 | - $this->repo = $repo; |
|
44 | - $this->modelResource = $modelResource; |
|
45 | - $this->config = $config->getConfig(); |
|
46 | - $this->modelName = explode('\\', get_called_class()); |
|
47 | - $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
48 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
49 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
50 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
51 | - $route = explode('@', \Route::currentRouteAction())[1]; |
|
52 | - |
|
53 | - $this->setSessions(); |
|
54 | - $this->checkPermission($route); |
|
55 | - $this->setRelations($route); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Fetch all records with relations from storage. |
|
60 | - * |
|
61 | - * @param string $sortBy The name of the column to sort by. |
|
62 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
63 | - * @return \Illuminate\Http\Response |
|
64 | - */ |
|
65 | - public function index($sortBy = 'created_at', $desc = 1) |
|
66 | - { |
|
67 | - return $this->modelResource::collection($this->repo->all($this->relations, $sortBy, $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 | - * Paginate all records with relations from storage |
|
83 | - * that matche the given query. |
|
84 | - * |
|
85 | - * @param string $query The search text. |
|
86 | - * @param integer $perPage Number of rows per page default 15. |
|
87 | - * @param string $sortBy The name of the column to sort by. |
|
88 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
89 | - * @return \Illuminate\Http\Response |
|
90 | - */ |
|
91 | - public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
92 | - { |
|
93 | - return $this->modelResource::collection($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc)); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Fetch records from the storage based on the given |
|
98 | - * condition. |
|
99 | - * |
|
100 | - * @param \Illuminate\Http\Request $request |
|
101 | - * @param string $sortBy The name of the column to sort by. |
|
102 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
103 | - * @return \Illuminate\Http\Response |
|
104 | - */ |
|
105 | - public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
106 | - { |
|
107 | - return $this->modelResource::collection($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc)); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Fetch the first record from the storage based on the given |
|
112 | - * condition. |
|
113 | - * |
|
114 | - * @param \Illuminate\Http\Request $request |
|
115 | - * @return \Illuminate\Http\Response |
|
116 | - */ |
|
117 | - public function first(Request $request) |
|
118 | - { |
|
119 | - return new $this->modelResource($this->repo->first($request->all(), $this->relations)); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Paginate all records with relations from storage. |
|
124 | - * |
|
125 | - * @param integer $perPage Number of rows per page default 15. |
|
126 | - * @param string $sortBy The name of the column to sort by. |
|
127 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
128 | - * @return \Illuminate\Http\Response |
|
129 | - */ |
|
130 | - public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
131 | - { |
|
132 | - return $this->modelResource::collection($this->repo->paginate($perPage, $this->relations, $sortBy, $desc)); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Fetch all records with relations based on |
|
137 | - * the given condition from storage in pages. |
|
138 | - * |
|
139 | - * @param \Illuminate\Http\Request $request |
|
140 | - * @param integer $perPage Number of rows per page default 15. |
|
141 | - * @param string $sortBy The name of the column to sort by. |
|
142 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
143 | - * @return \Illuminate\Http\Response |
|
144 | - */ |
|
145 | - public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
146 | - { |
|
147 | - return $this->modelResource::collection($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc)); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Save the given model to storage. |
|
152 | - * |
|
153 | - * @param \Illuminate\Http\Request $request |
|
154 | - * @return \Illuminate\Http\Response |
|
155 | - */ |
|
156 | - public function save(Request $request) |
|
157 | - { |
|
158 | - foreach ($this->validationRules as &$rule) { |
|
159 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) { |
|
160 | - $rule .= ',deleted_at,NULL'; |
|
161 | - } |
|
162 | - |
|
163 | - if ($request->has('id')) { |
|
164 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
165 | - } else { |
|
166 | - $rule = str_replace(',{id}', '', $rule); |
|
167 | - } |
|
168 | - } |
|
12 | + /** |
|
13 | + * The config implementation. |
|
14 | + * |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $config; |
|
18 | + |
|
19 | + /** |
|
20 | + * The relations implementation. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $relations; |
|
25 | + |
|
26 | + /** |
|
27 | + * The repo implementation. |
|
28 | + * |
|
29 | + * @var object |
|
30 | + */ |
|
31 | + protected $repo; |
|
32 | + |
|
33 | + /** |
|
34 | + * Init new object. |
|
35 | + * |
|
36 | + * @param mixed $repo |
|
37 | + * @param CoreConfig $config |
|
38 | + * @param string $modelResource |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + public function __construct($repo, $config, $modelResource) |
|
42 | + { |
|
43 | + $this->repo = $repo; |
|
44 | + $this->modelResource = $modelResource; |
|
45 | + $this->config = $config->getConfig(); |
|
46 | + $this->modelName = explode('\\', get_called_class()); |
|
47 | + $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
48 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
49 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
50 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
51 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
52 | + |
|
53 | + $this->setSessions(); |
|
54 | + $this->checkPermission($route); |
|
55 | + $this->setRelations($route); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Fetch all records with relations from storage. |
|
60 | + * |
|
61 | + * @param string $sortBy The name of the column to sort by. |
|
62 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
63 | + * @return \Illuminate\Http\Response |
|
64 | + */ |
|
65 | + public function index($sortBy = 'created_at', $desc = 1) |
|
66 | + { |
|
67 | + return $this->modelResource::collection($this->repo->all($this->relations, $sortBy, $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 | + * Paginate all records with relations from storage |
|
83 | + * that matche the given query. |
|
84 | + * |
|
85 | + * @param string $query The search text. |
|
86 | + * @param integer $perPage Number of rows per page default 15. |
|
87 | + * @param string $sortBy The name of the column to sort by. |
|
88 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
89 | + * @return \Illuminate\Http\Response |
|
90 | + */ |
|
91 | + public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
92 | + { |
|
93 | + return $this->modelResource::collection($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc)); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Fetch records from the storage based on the given |
|
98 | + * condition. |
|
99 | + * |
|
100 | + * @param \Illuminate\Http\Request $request |
|
101 | + * @param string $sortBy The name of the column to sort by. |
|
102 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
103 | + * @return \Illuminate\Http\Response |
|
104 | + */ |
|
105 | + public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
106 | + { |
|
107 | + return $this->modelResource::collection($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc)); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Fetch the first record from the storage based on the given |
|
112 | + * condition. |
|
113 | + * |
|
114 | + * @param \Illuminate\Http\Request $request |
|
115 | + * @return \Illuminate\Http\Response |
|
116 | + */ |
|
117 | + public function first(Request $request) |
|
118 | + { |
|
119 | + return new $this->modelResource($this->repo->first($request->all(), $this->relations)); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Paginate all records with relations from storage. |
|
124 | + * |
|
125 | + * @param integer $perPage Number of rows per page default 15. |
|
126 | + * @param string $sortBy The name of the column to sort by. |
|
127 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
128 | + * @return \Illuminate\Http\Response |
|
129 | + */ |
|
130 | + public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
131 | + { |
|
132 | + return $this->modelResource::collection($this->repo->paginate($perPage, $this->relations, $sortBy, $desc)); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Fetch all records with relations based on |
|
137 | + * the given condition from storage in pages. |
|
138 | + * |
|
139 | + * @param \Illuminate\Http\Request $request |
|
140 | + * @param integer $perPage Number of rows per page default 15. |
|
141 | + * @param string $sortBy The name of the column to sort by. |
|
142 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
143 | + * @return \Illuminate\Http\Response |
|
144 | + */ |
|
145 | + public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
146 | + { |
|
147 | + return $this->modelResource::collection($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc)); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Save the given model to storage. |
|
152 | + * |
|
153 | + * @param \Illuminate\Http\Request $request |
|
154 | + * @return \Illuminate\Http\Response |
|
155 | + */ |
|
156 | + public function save(Request $request) |
|
157 | + { |
|
158 | + foreach ($this->validationRules as &$rule) { |
|
159 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) { |
|
160 | + $rule .= ',deleted_at,NULL'; |
|
161 | + } |
|
162 | + |
|
163 | + if ($request->has('id')) { |
|
164 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
165 | + } else { |
|
166 | + $rule = str_replace(',{id}', '', $rule); |
|
167 | + } |
|
168 | + } |
|
169 | 169 | |
170 | - $this->validate($request, $this->validationRules); |
|
171 | - |
|
172 | - return $this->modelResource::collection($this->repo->save($request->all())); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Delete by the given id from storage. |
|
177 | - * |
|
178 | - * @param integer $id Id of the deleted model. |
|
179 | - * @return \Illuminate\Http\Response |
|
180 | - */ |
|
181 | - public function delete($id) |
|
182 | - { |
|
183 | - return new GeneralResource($this->repo->delete($id)); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Return the deleted models in pages based on the given conditions. |
|
188 | - * |
|
189 | - * @param \Illuminate\Http\Request $request |
|
190 | - * @param integer $perPage Number of rows per page default 15. |
|
191 | - * @param string $sortBy The name of the column to sort by. |
|
192 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
193 | - * @return \Illuminate\Http\Response |
|
194 | - */ |
|
195 | - public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
196 | - { |
|
197 | - return $this->modelResource::collection($this->repo->deleted($request->all(), $perPage, $sortBy, $desc)); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Restore the deleted model. |
|
202 | - * |
|
203 | - * @param integer $id Id of the restored model. |
|
204 | - * @return \Illuminate\Http\Response |
|
205 | - */ |
|
206 | - public function restore($id) |
|
207 | - { |
|
208 | - return new GeneralResource($this->repo->restore($id)); |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Check if the logged in user can do the given permission. |
|
213 | - * |
|
214 | - * @param string $permission |
|
215 | - * @return void |
|
216 | - */ |
|
217 | - private function checkPermission($permission) |
|
218 | - { |
|
219 | - \Auth::shouldUse('api'); |
|
220 | - $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
170 | + $this->validate($request, $this->validationRules); |
|
171 | + |
|
172 | + return $this->modelResource::collection($this->repo->save($request->all())); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Delete by the given id from storage. |
|
177 | + * |
|
178 | + * @param integer $id Id of the deleted model. |
|
179 | + * @return \Illuminate\Http\Response |
|
180 | + */ |
|
181 | + public function delete($id) |
|
182 | + { |
|
183 | + return new GeneralResource($this->repo->delete($id)); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Return the deleted models in pages based on the given conditions. |
|
188 | + * |
|
189 | + * @param \Illuminate\Http\Request $request |
|
190 | + * @param integer $perPage Number of rows per page default 15. |
|
191 | + * @param string $sortBy The name of the column to sort by. |
|
192 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
193 | + * @return \Illuminate\Http\Response |
|
194 | + */ |
|
195 | + public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
196 | + { |
|
197 | + return $this->modelResource::collection($this->repo->deleted($request->all(), $perPage, $sortBy, $desc)); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Restore the deleted model. |
|
202 | + * |
|
203 | + * @param integer $id Id of the restored model. |
|
204 | + * @return \Illuminate\Http\Response |
|
205 | + */ |
|
206 | + public function restore($id) |
|
207 | + { |
|
208 | + return new GeneralResource($this->repo->restore($id)); |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Check if the logged in user can do the given permission. |
|
213 | + * |
|
214 | + * @param string $permission |
|
215 | + * @return void |
|
216 | + */ |
|
217 | + private function checkPermission($permission) |
|
218 | + { |
|
219 | + \Auth::shouldUse('api'); |
|
220 | + $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
221 | 221 | |
222 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
223 | - $user = \Auth::user(); |
|
224 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
225 | - $isPasswordClient = $user->token()->client->password_client; |
|
226 | - $this->updateLocaleAndTimezone($user); |
|
227 | - |
|
228 | - if ($user->blocked) { |
|
229 | - \ErrorHandler::userIsBlocked(); |
|
230 | - } |
|
231 | - |
|
232 | - if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
233 | - } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
234 | - } else { |
|
235 | - \ErrorHandler::noPermissions(); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Set sessions based on the given headers in the request. |
|
242 | - * |
|
243 | - * @return void |
|
244 | - */ |
|
245 | - private function setSessions() |
|
246 | - { |
|
247 | - \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
248 | - |
|
249 | - $locale = \Request::header('locale'); |
|
250 | - switch ($locale) { |
|
251 | - case 'en': |
|
252 | - \App::setLocale('en'); |
|
253 | - \Session::put('locale', 'en'); |
|
254 | - break; |
|
255 | - |
|
256 | - case 'ar': |
|
257 | - \App::setLocale('ar'); |
|
258 | - \Session::put('locale', 'ar'); |
|
259 | - break; |
|
260 | - |
|
261 | - case 'all': |
|
262 | - \App::setLocale('en'); |
|
263 | - \Session::put('locale', 'all'); |
|
264 | - break; |
|
265 | - |
|
266 | - default: |
|
267 | - \App::setLocale('en'); |
|
268 | - \Session::put('locale', 'en'); |
|
269 | - break; |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Set relation based on the called api. |
|
275 | - * |
|
276 | - * @param string $route |
|
277 | - * @return void |
|
278 | - */ |
|
279 | - private function setRelations($route) |
|
280 | - { |
|
281 | - $route = $route !== 'index' ? $route : 'list'; |
|
282 | - $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
283 | - $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Update the logged in user locale and time zone. |
|
288 | - * |
|
289 | - * @param object $user |
|
290 | - * @return void |
|
291 | - */ |
|
292 | - private function updateLocaleAndTimezone($user) |
|
293 | - { |
|
294 | - $update = false; |
|
295 | - $locale = \Session::get('locale'); |
|
296 | - $timezone = \Session::get('time-zone'); |
|
297 | - if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
298 | - $user->locale = $locale; |
|
299 | - $update = true; |
|
300 | - } |
|
301 | - |
|
302 | - if ($timezone && $timezone !== $user->timezone) { |
|
303 | - $user->timezone = $timezone; |
|
304 | - $update = true; |
|
305 | - } |
|
306 | - |
|
307 | - if ($update) { |
|
308 | - $user->save(); |
|
309 | - } |
|
310 | - } |
|
222 | + if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
223 | + $user = \Auth::user(); |
|
224 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
225 | + $isPasswordClient = $user->token()->client->password_client; |
|
226 | + $this->updateLocaleAndTimezone($user); |
|
227 | + |
|
228 | + if ($user->blocked) { |
|
229 | + \ErrorHandler::userIsBlocked(); |
|
230 | + } |
|
231 | + |
|
232 | + if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
233 | + } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
234 | + } else { |
|
235 | + \ErrorHandler::noPermissions(); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Set sessions based on the given headers in the request. |
|
242 | + * |
|
243 | + * @return void |
|
244 | + */ |
|
245 | + private function setSessions() |
|
246 | + { |
|
247 | + \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
248 | + |
|
249 | + $locale = \Request::header('locale'); |
|
250 | + switch ($locale) { |
|
251 | + case 'en': |
|
252 | + \App::setLocale('en'); |
|
253 | + \Session::put('locale', 'en'); |
|
254 | + break; |
|
255 | + |
|
256 | + case 'ar': |
|
257 | + \App::setLocale('ar'); |
|
258 | + \Session::put('locale', 'ar'); |
|
259 | + break; |
|
260 | + |
|
261 | + case 'all': |
|
262 | + \App::setLocale('en'); |
|
263 | + \Session::put('locale', 'all'); |
|
264 | + break; |
|
265 | + |
|
266 | + default: |
|
267 | + \App::setLocale('en'); |
|
268 | + \Session::put('locale', 'en'); |
|
269 | + break; |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Set relation based on the called api. |
|
275 | + * |
|
276 | + * @param string $route |
|
277 | + * @return void |
|
278 | + */ |
|
279 | + private function setRelations($route) |
|
280 | + { |
|
281 | + $route = $route !== 'index' ? $route : 'list'; |
|
282 | + $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
283 | + $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Update the logged in user locale and time zone. |
|
288 | + * |
|
289 | + * @param object $user |
|
290 | + * @return void |
|
291 | + */ |
|
292 | + private function updateLocaleAndTimezone($user) |
|
293 | + { |
|
294 | + $update = false; |
|
295 | + $locale = \Session::get('locale'); |
|
296 | + $timezone = \Session::get('time-zone'); |
|
297 | + if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
298 | + $user->locale = $locale; |
|
299 | + $update = true; |
|
300 | + } |
|
301 | + |
|
302 | + if ($timezone && $timezone !== $user->timezone) { |
|
303 | + $user->timezone = $timezone; |
|
304 | + $update = true; |
|
305 | + } |
|
306 | + |
|
307 | + if ($update) { |
|
308 | + $user->save(); |
|
309 | + } |
|
310 | + } |
|
311 | 311 | } |