@@ -5,14 +5,14 @@ discard block |
||
5 | 5 | |
6 | 6 | class SampelReport extends Migration |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function up() |
|
14 | - { |
|
15 | - DB::statement("CREATE VIEW admin_count AS |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function up() |
|
14 | + { |
|
15 | + DB::statement("CREATE VIEW admin_count AS |
|
16 | 16 | select count(u.id) |
17 | 17 | from users u, roles g ,role_user ug |
18 | 18 | where |
@@ -20,25 +20,25 @@ discard block |
||
20 | 20 | ug.role_id = g.id |
21 | 21 | "); |
22 | 22 | |
23 | - DB::table('reports')->insert( |
|
24 | - [ |
|
25 | - [ |
|
26 | - 'report_name' => 'admin_count', |
|
27 | - 'view_name' => 'admin_count', |
|
28 | - 'created_at' => \DB::raw('NOW()'), |
|
29 | - 'updated_at' => \DB::raw('NOW()') |
|
30 | - ] |
|
31 | - ] |
|
32 | - ); |
|
33 | - } |
|
23 | + DB::table('reports')->insert( |
|
24 | + [ |
|
25 | + [ |
|
26 | + 'report_name' => 'admin_count', |
|
27 | + 'view_name' => 'admin_count', |
|
28 | + 'created_at' => \DB::raw('NOW()'), |
|
29 | + 'updated_at' => \DB::raw('NOW()') |
|
30 | + ] |
|
31 | + ] |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Reverse the migrations. |
|
37 | - * |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public function down() |
|
41 | - { |
|
42 | - DB::statement("DROP VIEW IF EXISTS admin_count"); |
|
43 | - } |
|
35 | + /** |
|
36 | + * Reverse the migrations. |
|
37 | + * |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public function down() |
|
41 | + { |
|
42 | + DB::statement("DROP VIEW IF EXISTS admin_count"); |
|
43 | + } |
|
44 | 44 | } |
@@ -6,14 +6,14 @@ |
||
6 | 6 | |
7 | 7 | class View 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 | - return [$this->resource]; |
|
18 | - } |
|
9 | + /** |
|
10 | + * Transform the resource into an array. |
|
11 | + * |
|
12 | + * @param Request $request |
|
13 | + * @return array |
|
14 | + */ |
|
15 | + public function toArray($request) |
|
16 | + { |
|
17 | + return [$this->resource]; |
|
18 | + } |
|
19 | 19 | } |
@@ -9,40 +9,40 @@ |
||
9 | 9 | |
10 | 10 | class ReportController extends BaseApiController |
11 | 11 | { |
12 | - /** |
|
13 | - * Path of the model resource |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $modelResource = 'App\Modules\Reporting\Http\Resources\Report'; |
|
12 | + /** |
|
13 | + * Path of the model resource |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $modelResource = 'App\Modules\Reporting\Http\Resources\Report'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * List of all route actions that the base api controller |
|
21 | - * will skip permissions check for them. |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $skipPermissionCheck = ['getReport']; |
|
19 | + /** |
|
20 | + * List of all route actions that the base api controller |
|
21 | + * will skip permissions check for them. |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $skipPermissionCheck = ['getReport']; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Init new object. |
|
28 | - * |
|
29 | - * @param ReportService $service |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - public function __construct(ReportService $service) |
|
33 | - { |
|
34 | - parent::__construct($service); |
|
35 | - } |
|
26 | + /** |
|
27 | + * Init new object. |
|
28 | + * |
|
29 | + * @param ReportService $service |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + public function __construct(ReportService $service) |
|
33 | + { |
|
34 | + parent::__construct($service); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Render the given servicert name with the given conditions. |
|
39 | - * |
|
40 | - * @param Request $request |
|
41 | - * @param string $reportName Name of the requested servicert |
|
42 | - * @return \Illuminate\Http\Response |
|
43 | - */ |
|
44 | - public function getReport(Request $request, $reportName) |
|
45 | - { |
|
46 | - return new ViewResource($this->service->getReport($reportName, $request->all(), $request->query('perPage'))); |
|
47 | - } |
|
37 | + /** |
|
38 | + * Render the given servicert name with the given conditions. |
|
39 | + * |
|
40 | + * @param Request $request |
|
41 | + * @param string $reportName Name of the requested servicert |
|
42 | + * @return \Illuminate\Http\Response |
|
43 | + */ |
|
44 | + public function getReport(Request $request, $reportName) |
|
45 | + { |
|
46 | + return new ViewResource($this->service->getReport($reportName, $request->all(), $request->query('perPage'))); |
|
47 | + } |
|
48 | 48 | } |
@@ -6,49 +6,49 @@ |
||
6 | 6 | |
7 | 7 | class ReportService extends BaseService |
8 | 8 | { |
9 | - /** |
|
10 | - * @var UserService |
|
11 | - */ |
|
12 | - protected $userService; |
|
9 | + /** |
|
10 | + * @var UserService |
|
11 | + */ |
|
12 | + protected $userService; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Init new object. |
|
16 | - * |
|
17 | - * @param ReportRepository $repo |
|
18 | - * @return void |
|
19 | - */ |
|
20 | - public function __construct(ReportRepository $repo, UserService $userService) |
|
21 | - { |
|
22 | - $this->userService = $userService; |
|
23 | - parent::__construct($repo); |
|
24 | - } |
|
14 | + /** |
|
15 | + * Init new object. |
|
16 | + * |
|
17 | + * @param ReportRepository $repo |
|
18 | + * @return void |
|
19 | + */ |
|
20 | + public function __construct(ReportRepository $repo, UserService $userService) |
|
21 | + { |
|
22 | + $this->userService = $userService; |
|
23 | + parent::__construct($repo); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Render the given report db view based on the given |
|
28 | - * condition. |
|
29 | - * |
|
30 | - * @param string $reportName |
|
31 | - * @param array $conditions |
|
32 | - * @param integer $perPage |
|
33 | - * @param boolean $skipPermission |
|
34 | - * @return object |
|
35 | - */ |
|
36 | - public function getReport($reportName, $conditions = [], $perPage = 0, $skipPermission = false) |
|
37 | - { |
|
38 | - /** |
|
39 | - * Fetch the report from db. |
|
40 | - */ |
|
41 | - $report = $this->repo->first(['report_name' => $reportName]); |
|
26 | + /** |
|
27 | + * Render the given report db view based on the given |
|
28 | + * condition. |
|
29 | + * |
|
30 | + * @param string $reportName |
|
31 | + * @param array $conditions |
|
32 | + * @param integer $perPage |
|
33 | + * @param boolean $skipPermission |
|
34 | + * @return object |
|
35 | + */ |
|
36 | + public function getReport($reportName, $conditions = [], $perPage = 0, $skipPermission = false) |
|
37 | + { |
|
38 | + /** |
|
39 | + * Fetch the report from db. |
|
40 | + */ |
|
41 | + $report = $this->repo->first(['report_name' => $reportName]); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Check report existance and permission. |
|
45 | - */ |
|
46 | - if (! $report) { |
|
47 | - \ErrorHandler::notFound('report'); |
|
48 | - } elseif (! $skipPermission && ! $this->userService->can($report->view_name, 'report')) { |
|
49 | - \ErrorHandler::noPermissions(); |
|
50 | - } |
|
43 | + /** |
|
44 | + * Check report existance and permission. |
|
45 | + */ |
|
46 | + if (! $report) { |
|
47 | + \ErrorHandler::notFound('report'); |
|
48 | + } elseif (! $skipPermission && ! $this->userService->can($report->view_name, 'report')) { |
|
49 | + \ErrorHandler::noPermissions(); |
|
50 | + } |
|
51 | 51 | |
52 | - return $this->repo->renderReport($report, $conditions, $perPage); |
|
53 | - } |
|
52 | + return $this->repo->renderReport($report, $conditions, $perPage); |
|
53 | + } |
|
54 | 54 | } |
@@ -43,9 +43,9 @@ |
||
43 | 43 | /** |
44 | 44 | * Check report existance and permission. |
45 | 45 | */ |
46 | - if (! $report) { |
|
46 | + if ( ! $report) { |
|
47 | 47 | \ErrorHandler::notFound('report'); |
48 | - } elseif (! $skipPermission && ! $this->userService->can($report->view_name, 'report')) { |
|
48 | + } elseif ( ! $skipPermission && ! $this->userService->can($report->view_name, 'report')) { |
|
49 | 49 | \ErrorHandler::noPermissions(); |
50 | 50 | } |
51 | 51 |