From e31a9bae60aad45158da39fa8dc65f75a755ff28 Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 15 Jul 2025 11:30:07 +0530 Subject: [PATCH] FEAT_HR_AUDITLOG --- app/Config/Routes.php | 2 ++ .../RestAuthenticationController.php | 8 +++--- app/Controllers/UserController.php | 25 +++++++++++++++++ app/Models/UserActivityHistoryModel.php | 1 + app/Views/client_onboarding.php | 27 +++++++++++++++++++ app/Views/hr_access_controll.php | 3 ++- 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a6cef1ed..81dd611e 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -66,6 +66,7 @@ $routes->group("/user", ["filter" => "authMVC"], function ($routes) { $routes->get("getuser/(:hash)", "UserController::getuser/$1"); $routes->get("deactive/(:hash)", "UserController::deactive/$1"); $routes->get("rolesandteams", "UserController::getRolesAndTeams"); + $routes->get("getUserActivityHistory", "UserController::getUserActivityHistory"); }); $routes->group("/dashboard", ["filter" => "authMVC"], function ($routes) { @@ -489,6 +490,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->post("employeeRest/saveMpin", "RestAuthenticationController::saveMpin"); $routes->post("employeeRest/updateMpin", "RestAuthenticationController::updateMpin"); $routes->post("employeeRest/getPostEmployeeDataForAuth", "RestAuthenticationController::getPostEmployeeDataForAuth"); +$routes->post("logHrActivity", "RestAuthenticationController::logHrActivity"); $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 478d563b..b3b78b71 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -1236,9 +1236,11 @@ class RestAuthenticationController extends AdminController public function logHrActivity() { - $json = $this->request->getJSON(); - print_r($json);die(); - // $this->userActivityHistoryModel->insert(); + $log_data = $this->request->getJSON(); + // print_r($json);die(); + $this->userActivityHistoryModel->insert($log_data); + return $this->respond(['status' => 'success','code' => 200,'data' => "logged",],200); + } diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index cc23a148..c911fb8d 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -13,6 +13,8 @@ use App\Models\RoleModel; use App\Models\TeamModel; use App\Models\UserTeamsModel; use App\Helpers\BookStackUserHelper; +use App\Helpers\AuthHistoryModel; +use App\Models\UserActivityHistoryModel; class UserController extends AdminController @@ -34,6 +36,8 @@ class UserController extends AdminController $this->teamModel = new TeamModel(); $this->userTeamsModel = new UserTeamsModel(); $this->bookStack = new BookStackUserHelper(); + $this->authHistoryModel = new AuthHistoryModel(); + $this->userActivityHistoryModel = new UserActivityHistoryModel(); } public function list() @@ -256,4 +260,25 @@ class UserController extends AdminController $teamData = $this->teamModel->select('id, name')->findAll(); echo json_encode(array("status" => true , 'roleData' => $roleData, 'teamData' => $teamData,)); } + + + public function getUserActivityHistory() + { + $user_id = $this->request->getVar('user_id'); + $pre_hr_id = $this->request->getVar('pre_hr_id'); + // echo $user_id.' - '.$pre_hr_id; + $field_for_where_condition = 'user_id'; + if($user_id == 0 || $user_id == NULL) + { + $field_for_where_condition = 'pre_hr_id'; + $user_id = $pre_hr_id; + } + + //get login history + $auth_data = $this->authHistoryModel->where($field_for_where_condition,$user_id); + + //get activity history + $activity_data = $this->userActivityHistoryModel->where(); + + } } \ No newline at end of file diff --git a/app/Models/UserActivityHistoryModel.php b/app/Models/UserActivityHistoryModel.php index e56fcadd..d2f218f1 100644 --- a/app/Models/UserActivityHistoryModel.php +++ b/app/Models/UserActivityHistoryModel.php @@ -10,6 +10,7 @@ class UserActivityHistoryModel extends Model protected $primaryKey = 'id'; protected $allowedFields = [ 'user_id', + 'pre_hr_id', 'user_type', 'misc_data', 'activity' diff --git a/app/Views/client_onboarding.php b/app/Views/client_onboarding.php index 1949ced1..26966afb 100755 --- a/app/Views/client_onboarding.php +++ b/app/Views/client_onboarding.php @@ -495,6 +495,11 @@ body {