Example #1
0
 public function getUsersList(Request $request)
 {
     $role_id = $request->input('ROLES_ID');
     $production_unit_id = $request->input('PRODUCTION_ID');
     $area_id = $request->input('AREA_ID');
     $facility_id = $request->input('FACILITY');
     $result = array();
     $listColumn = ['a.ID', 'a.USERNAME', 'a.PASSWORD_CHANGED', 'b.PU_ID', 'b.AREA_ID', 'b.FACILITY_ID', 'a.ID AS ROLE', 'pu.NAME AS PU_NAME', 'ar.NAME AS AREA_NAME', 'fa.NAME AS FACILITY_NAME', 'a.EXPIRE_DATE', 'a.ACTIVE', 'a.ACTIVE AS STATUS', 'a.expire_date AS expire_status'];
     $userDataScope = UserDataScope::getTableName();
     $loProductionUnit = LoProductionUnit::getTableName();
     $loArea = LoArea::getTableName();
     $facility = Facility::getTableName();
     $user = User::getTableName();
     $listData = DB::table($user . ' AS a')->leftJoin($userDataScope . ' AS b', 'a.id', '=', 'b.user_id')->leftJoin($loProductionUnit . ' AS pu', 'pu.id', '=', 'b.PU_ID')->leftJoin($loArea . ' AS ar', 'ar.id', '=', 'b.AREA_ID')->leftJoin($facility . ' AS fa', 'fa.id', '=', 'b.FACILITY_ID')->select($listColumn)->orderBy('a.id', 'asc')->get();
     foreach ($listData as $data) {
         $sRole = "";
         $userUserRole = UserUserRole::getTableName();
         $userRole = UserRole::getTableName();
         $subList = DB::table($userUserRole . ' AS x')->join($userRole . ' AS z', 'x.role_id', '=', 'z.id')->where(['x.user_id' => $data->ID])->where(function ($q) use($role_id) {
             $q->where(function ($query) use($role_id) {
                 if ($role_id != 0) {
                     $query->where(['x.role_id' => $role_id]);
                 }
             });
         })->select('z.name')->get();
         if (count($subList) > 0) {
             foreach ($subList as $sub) {
                 $sRole .= ($sRole == "" ? "" : "<br>") . $sub->name;
             }
         }
         if ($role_id > 0 && $sRole == "") {
             continue;
         }
         if ($sRole == "") {
             $sRole = "(No role)";
         }
         if ($production_unit_id != 0 && $production_unit_id != $data->PU_ID) {
             continue;
         }
         if ($area_id != 0 && $area_id != $data->AREA_ID) {
             continue;
         }
         if ($facility_id != 0 && $facility_id != $data->FACILITY_ID) {
             continue;
         }
         $data->ROLE = $sRole;
         if ($data->ACTIVE == 1) {
             $data->STATUS = 'Active';
         } else {
             $data->STATUS = 'Not Active';
         }
         $now = Carbon::now('Europe/London');
         if ($data->EXPIRE_DATE > $now) {
             $data->EXPIRE_STATUS = "";
         } else {
             $data->EXPIRE_STATUS = 'Expired';
         }
         $data->EXPIRE_DATE = date('m/d/Y', strtotime($data->EXPIRE_DATE));
         $data->PASSWORD_CHANGED = date('m/d/Y H:i:s', strtotime($data->PASSWORD_CHANGED));
         if ($data->EXPIRE_STATUS == '') {
             $data->EXPIRE_STATUS = '';
         } else {
             $data->EXPIRE_STATUS = ', ' . $data->EXPIRE_STATUS;
         }
         $data->STATUS = $data->STATUS . $data->EXPIRE_STATUS;
         array_push($result, $data);
     }
     return response()->json(array('result' => $result));
 }
Example #2
0
File: User.php Project: hunglmtb/eb
 public function hasRole($roleCode)
 {
     if ($this->ID) {
         $user_user_role = UserUserRole::getTableName();
         $user_role = UserRole::getTableName();
         $rows = UserUserRole::join($user_role, "{$user_user_role}.ROLE_ID", '=', "{$user_role}.ID")->where([$user_role . ".CODE" => $roleCode, $user_user_role . ".USER_ID" => $this->ID])->select($user_role . ".CODE")->distinct()->get();
         if (count($rows) > 0) {
             return true;
         } else {
             return false;
         }
     }
     return false;
 }