Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 134 |
| UserProfileController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
1190 | |
0.00% |
0 / 134 |
| index | |
0.00% |
0 / 1 |
380 | |
0.00% |
0 / 84 |
|||
| create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| store | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| show | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| edit | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| update | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 24 |
|||
| destroy | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| storeProfilePic | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 21 |
|||
| <?php | |
| namespace App\Http\Controllers\Userprofile; | |
| use App\Http\Controllers\Controller; | |
| use Illuminate\Http\Request; | |
| use Illuminate\Support\Facades\Auth; | |
| use App\Models\Auth\User; | |
| use Illuminate\Support\Facades\Hash; | |
| use Session; | |
| use App\Notifications\AppNotifications; | |
| use Illuminate\Support\Facades\Storage; | |
| use Intervention\Image\Facades\Image; | |
| use Illuminate\Support\Facades\Validator; | |
| use App\Helpers\AttendanceHelper; | |
| use App\Models\Admin\attendanceRequest; | |
| use App\Models\Admin\UserDetail; | |
| use App\Models\Admin\Department; | |
| use App\Models\Admin\Organisation; | |
| use App\Models\Admin\Team; | |
| use App\Models\Admin\Shift; | |
| use App\Models\Admin\UserAddress; | |
| use App\Models\Admin\UserBankDetail; | |
| use App\Models\Admin\UserDocumentDetail; | |
| use Spatie\Permission\Models\Role; | |
| use Illuminate\Support\Facades\Crypt; | |
| use DB; | |
| use Carbon\Carbon; | |
| use App\Models\Leave\LeaveEntitlement; | |
| use App\Helpers\GetShiftDetailHelper; | |
| use App\Models\Admin\UserDetailUser; | |
| use App\Models\Admin\UserDetailTeam; | |
| use App\Models\Auth\UserWeeklyOff; | |
| class UserProfileController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index(Request $request) | |
| { | |
| $title = '/My Profile'; | |
| $backurl = route('home'); | |
| $user = Auth::user(); | |
| $userPassword = $user->password; | |
| $userdetail = $user->userdetail; | |
| //dd($userdetail); | |
| $user_addresses = $userdetail->userAddress; | |
| $user_bank_details = $userdetail->userBankdetail; | |
| $user_document_details = $userdetail->userDocumentdetail; | |
| //$departments = Department::all(); | |
| // $departmentArr = $userdetail->departments; | |
| $departmentArr[0] = $userdetail->departments; | |
| $dname=""; | |
| // Check if the collection is not empty before accessing its elements | |
| if (!$departmentArr[0]->isEmpty()) { | |
| $dname= $departmentArr[0]->first()->department; | |
| } | |
| //dd($departmentArr); | |
| //$teams = Team::all(); | |
| $teamArr =$userdetail->teams; | |
| //$roles = Role::all(); | |
| // $roleArr = $userdetail->roles; | |
| //$shifts= Shift::all(); | |
| $selectShift = $userdetail->shifts; | |
| //$attendances = attendanceRequest::all(); | |
| $attendanceArr = $userdetail->attendanceRequests; | |
| //$organisations = Organisation::all(); | |
| $editUserdetail = true; | |
| $users = User::all(); | |
| $secondaryManagerArr = $userdetail->secondaryManager; | |
| //$employeeTeam = $user->userdetailWithTeam()->first() != null ? (count($user->userdetailWithTeam()->first()->teams) > 0 ? $user->userdetailWithTeam()->first()->teams[0]['team'] : ''): '-' ; | |
| $employeeTeam = !empty($user->userdetail->primaryTeamName->team) ? $user->userdetail->primaryTeamName->team : '-'; | |
| $leaves = DB::table('leaves')->whereNull('deleted_at')->get(); | |
| $leaveBalances = []; | |
| foreach ($leaves as $leave) { | |
| $leaveEntitlementQuery = array( | |
| 'user_id' => $user->id, | |
| 'year' => Carbon::now()->year, | |
| 'leave_id' => $leave->id | |
| ); | |
| $leaveEntitlementArr = LeaveEntitlement::where($leaveEntitlementQuery)->get(); | |
| $leaveBalance = null; | |
| foreach ($leaveEntitlementArr as $leaveEntitlement) { | |
| $leaveBalance = $leaveEntitlement->leave_balance; | |
| } | |
| if ($leaveBalance == null) { | |
| $leaveBalance = 0; | |
| } | |
| $leaveBalances[] = array( | |
| 'id' => $leave->id, | |
| 'name' => $leave->name, | |
| 'abbr' => $leave->abbr, | |
| 'leave_balance' => $leaveBalance | |
| ); | |
| } | |
| $employee_id = ''; | |
| if(config('settings.default_employee_id') == 'automatic') | |
| { | |
| $startId = config('settings.id_starts_from'); | |
| $prefix = config('settings.default_id'); | |
| for ($i=$startId; $employee_id == '' ; $i++) { | |
| if (UserDetail::where('employee_id', '=', $prefix.$i)->exists()) | |
| { | |
| } | |
| else | |
| { | |
| $employee_id = $prefix.$i; | |
| break; | |
| } | |
| } | |
| } | |
| $organisations = Organisation::where('id','=',$userdetail->organisation_id)->first(); | |
| $orgname = ''; | |
| if(!empty($organisations)){ | |
| $orgname = $organisations->organisation; | |
| } | |
| // $teamname = array(); | |
| // foreach($teamArr as $teamselect) | |
| // { | |
| // $team = Team::where('id','=',$teamselect->id)->first(); | |
| // array_push($teamname, $team->team); | |
| // } | |
| // $teamname = implode(',', $teamname); | |
| $teamname = ''; | |
| if(!empty($userdetail->primary_team_id)){ | |
| $teamname = $userdetail->primaryTeamName->team; | |
| } | |
| $rolename = ''; | |
| if(!empty($user->getRoleNames()->first())){ | |
| $rolename = $user->getRoleNames()->first(); | |
| } | |
| $shiftname = array(); | |
| foreach($selectShift as $shiftelect) | |
| { | |
| $shift = Shift::where('id','=',$shiftelect->id)->first(); | |
| array_push($shiftname, $shiftelect->shift); | |
| } | |
| $teamId = $user->userdetail->primary_team_id; | |
| $team = Team::find($teamId); | |
| if($team->has_schedule==1){ | |
| $shiftname = "As per schedule"; | |
| } | |
| else | |
| { | |
| $shiftname = implode(',', $shiftname); | |
| } | |
| $attendancename = array(); | |
| foreach($attendanceArr as $sattendanceselect) | |
| { | |
| $attendance = attendanceRequest::where('id','=',$sattendanceselect->id)->first(); | |
| array_push($attendancename, $attendance->name); | |
| } | |
| $attendancename = implode(',', $attendancename); | |
| $reportingmanager = array(); | |
| $primaryManager = $userdetail->primary_reporting_manager_id; | |
| $primaryReportingManager = ''; | |
| if($primaryManager != 0 || $primaryManager != NULL){ | |
| $primaryReportingManager = $userdetail->primaryReportingManager->name.' '.$userdetail->primaryReportingManager->lastName; | |
| } | |
| foreach($secondaryManagerArr as $secondaryManager) | |
| { | |
| if($primaryManager != $secondaryManager->id){ | |
| $username = User::where('id','=',$secondaryManager->id)->first(); | |
| $name = $username->name.' '.$username->lastName; | |
| $reportingmanager = $name; | |
| // array_push($reportingmanager, $name); | |
| } | |
| } | |
| // $password = $user->password; | |
| // $user_id = $user->id; | |
| // $name = $user->name . ' ' . $user->lastName; | |
| // $profilePic = 0; | |
| // if( $user->profile_pic ){ | |
| $profilePic = $user->profile_pic; | |
| //} | |
| // For returning attendance marking for home controller | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| return view('userprofile.userProfile', compact('profilePic','title','backurl','val','valTeam','valUser','user','userdetail','user_addresses','user_bank_details','orgname','editUserdetail','shiftname','teamname','dname','rolename','attendancename','reportingmanager','user_document_details','leaveBalances','employee_id','employeeTeam','primaryReportingManager')); | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function create() | |
| { | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function store(Request $request) | |
| { | |
| } | |
| /** | |
| * Display the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function show($id) | |
| { | |
| // | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function edit($id) | |
| { | |
| } | |
| /** | |
| * Update the specified resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function update(Request $request, $id) | |
| { | |
| if($request->old_password){ | |
| $this->validate($request, [ | |
| 'old_password' => 'required', | |
| 'new_password' => 'required|min:6', | |
| 'confirm_password' => 'required_with:new_password|same:new_password|min:6', | |
| ]); | |
| $user = User::find($id); | |
| if (!Hash::check($request->old_password, $user->password)) { | |
| Session::flash('warning', 'Old password is wrong!'); | |
| } else { | |
| if (Hash::needsRehash($request->password)) { | |
| $user->password = Hash::make($request->new_password); | |
| } | |
| $user->save(); | |
| //notification to admin | |
| $title = "Password Changed"; | |
| $message = $user->name . ' ' . $user->lastName."'s account password changed by ".$user->name . ' ' . $user->lastName; | |
| $actionUrl = null; | |
| $arr = null; | |
| $arr = [$title, $message, $actionUrl]; | |
| $users = User::all(); | |
| foreach ($users as $user) { | |
| if($user->can('Administration Module')){ | |
| $user->notify(new AppNotifications($arr)); | |
| } | |
| } | |
| Session::flash('success', 'Password Changed Successfully!'); | |
| } | |
| return redirect()->route('edit-profile.index')->withErrors($this); | |
| }else{ | |
| $user = User::find($id); | |
| $this->storeProfilePic($request, $user->id); | |
| Session::flash('success', 'Profile Changed Successfully!'); | |
| return redirect()->route('edit-profile.index')->withErrors($this); | |
| } | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function destroy($id) | |
| { | |
| } | |
| private function storeProfilePic($request,$id) | |
| { | |
| if($request->file('profile_pic') && $request->profilePic == 1) //if image uploaded | |
| { | |
| $validator = Validator::make($request->all(), [ | |
| 'profile_pic' => 'sometimes|file|image|max:2048|mimes:jpeg,png,jpg' | |
| ]); | |
| if ($validator->fails()) | |
| { | |
| return "false"; | |
| } | |
| else | |
| { | |
| $todaydate = date('Y-m-d H:i:s'); | |
| $file_name =$request->file('profile_pic')->getClientOriginalName(); | |
| $file_name = $todaydate.'-'.$file_name; | |
| $custom_file_name = str_replace(" ", "-", $file_name); | |
| Storage::putFileAs(('public/profile'),$request->file('profile_pic'), $custom_file_name); | |
| $path = "profile/".$custom_file_name; | |
| $user = User::Where('id',$id)->first(); | |
| $user->profile_pic = $path; | |
| $user->save(); | |
| $img = Image::make('storage/'.$path); | |
| // resize the instance | |
| $img->resize(90,90); | |
| $img->save(); | |
| } | |
| } | |
| else{ | |
| $user = User::Where('id',$id)->first(); | |
| $user->profile_pic = ""; | |
| $user->save(); | |
| } | |
| } | |
| } |