@@ -6,15 +6,15 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ReportingDatabaseSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - $this->call(ClearDataSeeder::class); |
|
| 17 | - $this->call(ReportsTableSeeder::class); |
|
| 18 | - $this->call(AssignRelationsSeeder::class); |
|
| 19 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + $this->call(ClearDataSeeder::class); |
|
| 17 | + $this->call(ReportsTableSeeder::class); |
|
| 18 | + $this->call(AssignRelationsSeeder::class); |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $factory->define(App\Modules\Reporting\Report::class, function (Faker\Generator $faker) { |
| 4 | - return [ |
|
| 4 | + return [ |
|
| 5 | 5 | 'report_name' => $faker->randomElement(['Users Count', 'Low Stock Products', 'Active Users']), |
| 6 | 6 | 'view_name' => $faker->word(), |
| 7 | 7 | 'created_at' => $faker->dateTimeBetween('-1 years', 'now'), |
| 8 | 8 | 'updated_at' => $faker->dateTimeBetween('-1 years', 'now') |
| 9 | - ]; |
|
| 9 | + ]; |
|
| 10 | 10 | }); |
| 11 | 11 | \ No newline at end of file |
@@ -7,30 +7,30 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ReportsController extends BaseApiController |
| 9 | 9 | { |
| 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'; |
|
| 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'; |
|
| 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 = ['getReport']; |
|
| 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 = ['getReport']; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Render the given report name with the given conditions. |
|
| 26 | - * |
|
| 27 | - * @param \Illuminate\Http\Request $request |
|
| 28 | - * @param string $reportName Name of the requested report |
|
| 29 | - * @param integer $perPage Number of rows per page default all data. |
|
| 30 | - * @return \Illuminate\Http\Response |
|
| 31 | - */ |
|
| 32 | - public function getReport(Request $request, $reportName, $perPage = 0) |
|
| 33 | - { |
|
| 34 | - return \Response::json($this->repo->getReport($reportName, $request->all(), $perPage), 200); |
|
| 35 | - } |
|
| 24 | + /** |
|
| 25 | + * Render the given report name with the given conditions. |
|
| 26 | + * |
|
| 27 | + * @param \Illuminate\Http\Request $request |
|
| 28 | + * @param string $reportName Name of the requested report |
|
| 29 | + * @param integer $perPage Number of rows per page default all data. |
|
| 30 | + * @return \Illuminate\Http\Response |
|
| 31 | + */ |
|
| 32 | + public function getReport(Request $request, $reportName, $perPage = 0) |
|
| 33 | + { |
|
| 34 | + return \Response::json($this->repo->getReport($reportName, $request->all(), $perPage), 200); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -5,53 +5,53 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class ReprotObserver { |
| 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 | - } |
|
| 47 | - |
|
| 48 | - public function restoring($model) |
|
| 49 | - { |
|
| 50 | - // |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function restored($model) |
|
| 54 | - { |
|
| 55 | - // |
|
| 56 | - } |
|
| 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 | + |
|
| 48 | + public function restoring($model) |
|
| 49 | + { |
|
| 50 | + // |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function restored($model) |
|
| 54 | + { |
|
| 55 | + // |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | \ No newline at end of file |
@@ -4,67 +4,67 @@ |
||
| 4 | 4 | |
| 5 | 5 | class ReportRepository extends AbstractRepository |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Return the model full namespace. |
|
| 9 | - * |
|
| 10 | - * @return string |
|
| 11 | - */ |
|
| 12 | - protected function getModel() |
|
| 13 | - { |
|
| 14 | - return 'App\Modules\Reporting\Report'; |
|
| 15 | - } |
|
| 7 | + /** |
|
| 8 | + * Return the model full namespace. |
|
| 9 | + * |
|
| 10 | + * @return string |
|
| 11 | + */ |
|
| 12 | + protected function getModel() |
|
| 13 | + { |
|
| 14 | + return 'App\Modules\Reporting\Report'; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Render the given report db view based on the given |
|
| 19 | - * condition. |
|
| 20 | - * |
|
| 21 | - * @param string $reportName |
|
| 22 | - * @param array $conditions array of conditions |
|
| 23 | - * @param integer $perPage |
|
| 24 | - * @param array $relations |
|
| 25 | - * @param boolean $skipPermission |
|
| 26 | - * @return object |
|
| 27 | - */ |
|
| 28 | - public function getReport($reportName, $conditions = false, $perPage = 0, $relations = [], $skipPermission = false) |
|
| 29 | - { |
|
| 30 | - /** |
|
| 31 | - * Fetch the report from db. |
|
| 32 | - */ |
|
| 33 | - $reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model); |
|
| 34 | - $report = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($reportConditions['conditionString'], $reportConditions['conditionValues'])->first(); |
|
| 17 | + /** |
|
| 18 | + * Render the given report db view based on the given |
|
| 19 | + * condition. |
|
| 20 | + * |
|
| 21 | + * @param string $reportName |
|
| 22 | + * @param array $conditions array of conditions |
|
| 23 | + * @param integer $perPage |
|
| 24 | + * @param array $relations |
|
| 25 | + * @param boolean $skipPermission |
|
| 26 | + * @return object |
|
| 27 | + */ |
|
| 28 | + public function getReport($reportName, $conditions = false, $perPage = 0, $relations = [], $skipPermission = false) |
|
| 29 | + { |
|
| 30 | + /** |
|
| 31 | + * Fetch the report from db. |
|
| 32 | + */ |
|
| 33 | + $reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model); |
|
| 34 | + $report = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($reportConditions['conditionString'], $reportConditions['conditionValues'])->first(); |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Check report existance and permission. |
|
| 38 | - */ |
|
| 39 | - if ( ! $report) |
|
| 40 | - { |
|
| 41 | - \ErrorHandler::notFound('report'); |
|
| 42 | - } |
|
| 43 | - else if (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) |
|
| 44 | - { |
|
| 45 | - \ErrorHandler::noPermissions(); |
|
| 46 | - } |
|
| 36 | + /** |
|
| 37 | + * Check report existance and permission. |
|
| 38 | + */ |
|
| 39 | + if ( ! $report) |
|
| 40 | + { |
|
| 41 | + \ErrorHandler::notFound('report'); |
|
| 42 | + } |
|
| 43 | + else if (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) |
|
| 44 | + { |
|
| 45 | + \ErrorHandler::noPermissions(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Fetch data from the report based on the given conditions. |
|
| 50 | - */ |
|
| 51 | - $report = \DB::table($report->view_name); |
|
| 52 | - unset($conditions['page']); |
|
| 53 | - if (count($conditions)) |
|
| 54 | - { |
|
| 55 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
| 56 | - $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
| 57 | - } |
|
| 58 | - /** |
|
| 59 | - * Paginate or all data. |
|
| 60 | - */ |
|
| 61 | - if ($perPage) |
|
| 62 | - { |
|
| 63 | - return $report->paginate($perPage); |
|
| 64 | - } |
|
| 65 | - else |
|
| 66 | - { |
|
| 67 | - return $report->get(); |
|
| 68 | - } |
|
| 69 | - } |
|
| 48 | + /** |
|
| 49 | + * Fetch data from the report based on the given conditions. |
|
| 50 | + */ |
|
| 51 | + $report = \DB::table($report->view_name); |
|
| 52 | + unset($conditions['page']); |
|
| 53 | + if (count($conditions)) |
|
| 54 | + { |
|
| 55 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
| 56 | + $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
| 57 | + } |
|
| 58 | + /** |
|
| 59 | + * Paginate or all data. |
|
| 60 | + */ |
|
| 61 | + if ($perPage) |
|
| 62 | + { |
|
| 63 | + return $report->paginate($perPage); |
|
| 64 | + } |
|
| 65 | + else |
|
| 66 | + { |
|
| 67 | + return $report->get(); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -8,72 +8,72 @@ |
||
| 8 | 8 | class RouteServiceProvider extends ServiceProvider |
| 9 | 9 | { |
| 10 | 10 | /** |
| 11 | - * This namespace is applied to your controller routes. |
|
| 12 | - * |
|
| 13 | - * In addition, it is set as the URL generator's root namespace. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $namespace = 'App\Modules\Notifications\Http\Controllers'; |
|
| 11 | + * This namespace is applied to your controller routes. |
|
| 12 | + * |
|
| 13 | + * In addition, it is set as the URL generator's root namespace. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $namespace = 'App\Modules\Notifications\Http\Controllers'; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Define your route model bindings, pattern filters, etc. |
|
| 21 | - * |
|
| 22 | - * @return void |
|
| 23 | - */ |
|
| 24 | - public function boot() |
|
| 25 | - { |
|
| 26 | - // |
|
| 19 | + /** |
|
| 20 | + * Define your route model bindings, pattern filters, etc. |
|
| 21 | + * |
|
| 22 | + * @return void |
|
| 23 | + */ |
|
| 24 | + public function boot() |
|
| 25 | + { |
|
| 26 | + // |
|
| 27 | 27 | |
| 28 | - parent::boot(); |
|
| 29 | - } |
|
| 28 | + parent::boot(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Define the routes for the module. |
|
| 33 | - * |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public function map() |
|
| 37 | - { |
|
| 38 | - $this->mapWebRoutes(); |
|
| 31 | + /** |
|
| 32 | + * Define the routes for the module. |
|
| 33 | + * |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public function map() |
|
| 37 | + { |
|
| 38 | + $this->mapWebRoutes(); |
|
| 39 | 39 | |
| 40 | - $this->mapApiRoutes(); |
|
| 40 | + $this->mapApiRoutes(); |
|
| 41 | 41 | |
| 42 | - // |
|
| 43 | - } |
|
| 42 | + // |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Define the "web" routes for the module. |
|
| 47 | - * |
|
| 48 | - * These routes all receive session state, CSRF protection, etc. |
|
| 49 | - * |
|
| 50 | - * @return void |
|
| 51 | - */ |
|
| 52 | - protected function mapWebRoutes() |
|
| 53 | - { |
|
| 54 | - Route::group([ |
|
| 55 | - 'middleware' => 'web', |
|
| 56 | - 'namespace' => $this->namespace, |
|
| 57 | - ], function ($router) { |
|
| 58 | - require module_path('notifications', 'Routes/web.php'); |
|
| 59 | - }); |
|
| 60 | - } |
|
| 45 | + /** |
|
| 46 | + * Define the "web" routes for the module. |
|
| 47 | + * |
|
| 48 | + * These routes all receive session state, CSRF protection, etc. |
|
| 49 | + * |
|
| 50 | + * @return void |
|
| 51 | + */ |
|
| 52 | + protected function mapWebRoutes() |
|
| 53 | + { |
|
| 54 | + Route::group([ |
|
| 55 | + 'middleware' => 'web', |
|
| 56 | + 'namespace' => $this->namespace, |
|
| 57 | + ], function ($router) { |
|
| 58 | + require module_path('notifications', 'Routes/web.php'); |
|
| 59 | + }); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Define the "api" routes for the module. |
|
| 64 | - * |
|
| 65 | - * These routes are typically stateless. |
|
| 66 | - * |
|
| 67 | - * @return void |
|
| 68 | - */ |
|
| 69 | - protected function mapApiRoutes() |
|
| 70 | - { |
|
| 71 | - Route::group([ |
|
| 72 | - 'middleware' => 'api', |
|
| 73 | - 'namespace' => $this->namespace, |
|
| 74 | - 'prefix' => 'api', |
|
| 75 | - ], function ($router) { |
|
| 76 | - require module_path('notifications', 'Routes/api.php'); |
|
| 77 | - }); |
|
| 78 | - } |
|
| 62 | + /** |
|
| 63 | + * Define the "api" routes for the module. |
|
| 64 | + * |
|
| 65 | + * These routes are typically stateless. |
|
| 66 | + * |
|
| 67 | + * @return void |
|
| 68 | + */ |
|
| 69 | + protected function mapApiRoutes() |
|
| 70 | + { |
|
| 71 | + Route::group([ |
|
| 72 | + 'middleware' => 'api', |
|
| 73 | + 'namespace' => $this->namespace, |
|
| 74 | + 'prefix' => 'api', |
|
| 75 | + ], function ($router) { |
|
| 76 | + require module_path('notifications', 'Routes/api.php'); |
|
| 77 | + }); |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -7,26 +7,26 @@ |
||
| 7 | 7 | class ModuleServiceProvider extends ServiceProvider |
| 8 | 8 | { |
| 9 | 9 | /** |
| 10 | - * Bootstrap the module services. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function boot() |
|
| 15 | - { |
|
| 16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'notification'); |
|
| 17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'notification'); |
|
| 10 | + * Bootstrap the module services. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function boot() |
|
| 15 | + { |
|
| 16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'notification'); |
|
| 17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'notification'); |
|
| 18 | 18 | |
| 19 | - $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
| 20 | - $factory->load(__DIR__.'/../Database/Factories'); |
|
| 21 | - } |
|
| 19 | + $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
| 20 | + $factory->load(__DIR__.'/../Database/Factories'); |
|
| 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,20 +6,20 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | class AssignRelationsSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id; |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Assign the permissions to the admin group. |
|
| 20 | - */ |
|
| 21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notifications', 'pushNotificationDevices'])->each(function ($permission) use ($adminGroupId) { |
|
| 22 | - \DB::table('groups_permissions')->insert( |
|
| 18 | + /** |
|
| 19 | + * Assign the permissions to the admin group. |
|
| 20 | + */ |
|
| 21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notifications', 'pushNotificationDevices'])->each(function ($permission) use ($adminGroupId) { |
|
| 22 | + \DB::table('groups_permissions')->insert( |
|
| 23 | 23 | [ |
| 24 | 24 | 'permission_id' => $permission->id, |
| 25 | 25 | 'group_id' => $adminGroupId, |
@@ -27,6 +27,6 @@ discard block |
||
| 27 | 27 | 'updated_at' => \DB::raw('NOW()') |
| 28 | 28 | ] |
| 29 | 29 | ); |
| 30 | - }); |
|
| 31 | - } |
|
| 30 | + }); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -6,15 +6,15 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ClearDataSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - $permissions = \DB::table('permissions')->whereIn('model', ['notifications', 'pushNotificationDevices']); |
|
| 17 | - \DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
| 18 | - $permissions->delete(); |
|
| 19 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + $permissions = \DB::table('permissions')->whereIn('model', ['notifications', 'pushNotificationDevices']); |
|
| 17 | + \DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
| 18 | + $permissions->delete(); |
|
| 19 | + } |
|
| 20 | 20 | } |