Файловый менеджер - Редактировать - /home/clickysoft/public_html/somni.clickysoft.net/app/Repositories/UserRepository.php
Назад
<?php namespace App\Repositories; use App\Interfaces\UserRepositoryInterface; use App\Models\User; use App\Models\Setting; use App\Models\UserInfo; use App\Models\Role; use App\Models\Newsletter; use App\Models\PropertyUnitTenant; use Spatie\MediaLibrary\MediaCollections\Models\Media; use App\Http\Controllers\Traits\MediaUploadingTrait; use DB; use Illuminate\Support\Facades\Hash; use Carbon\Carbon; class UserRepository implements UserRepositoryInterface { use MediaUploadingTrait; public function createUser($user, $role_id = null) { try { $new_user = User::create($user->all()); if ($role_id != null) { $new_user->roles()->sync($role_id); } if ($user->input('profile_image', false)) { $new_user->addMedia(storage_path('tmp/uploads/' . basename($user->input('profile_image'))))->toMediaCollection('profile_image'); } if ($media = $user->input('ck-media', false)) { Media::whereIn('id', $media)->update(['model_id' => $new_user->id]); } return $new_user; } catch (\Throwable $th) { return $th; } } public function getLandlords() { try { $users = User::whereHas('roles', function ($query) { $query->where('title', '=', 'Landlord'); })->get(); return $users; } catch (\Throwable $th) { return $th; } } public function getTenants() { try { $users = User::whereHas('roles', function ($query) { $query->where('title', '=', 'Tenant'); })->get(); return $users; } catch (\Throwable $th) { return $th; } } public function getUserById($user_id) { try { $user = User::where('id', $user_id)->first(); return $user; } catch (\Throwable $th) { return $th; } } public function updateUser($data, $user, $role = null) { try { if ($data->hasFile('profile_image')) { $user->media()->delete(); $check = $user->addMedia($data->file('profile_image'))->toMediaCollection('profile_image'); } $user->name = $data->input('name'); $user->phone = $data->input('phone'); $user->save(); return true; } catch (\Throwable $th) { return $th; } } // TODO:Remove this code // public function updateUser($data,$user,$role = null){ // try { // $flag = $user->update($data->except(['_token','_method'])); // if($role != null){ // if($data->ajax()){ // $user->roles()->sync($role); // }else{ // $user->roles()->sync($data->input('roles', [])); // } // } // if($data->ajax()){ // if($data->hasFile('profile_image')){ // $user->media()->delete(); // $check = $user->addMedia($data->file('profile_image'))->toMediaCollection('profile_image'); // } // }else{ // if ($data->input('profile_image', false) ) { // if (! $user->profile_image || $data->input('profile_image') !== $user->profile_image->file_name) { // if ($user->profile_image) { // $user->profile_image->delete(); // } // $user->addMedia(storage_path('tmp/uploads/' . basename($data->input('profile_image'))))->toMediaCollection('profile_image'); // } // } // } // return $flag; // } catch (\Throwable $th) { // return $th; // } // } public function changeStatus($user, $status) { try { $flag = $user->update(['is_active' => $status]); return $flag; } catch (\Throwable $th) { return $th; } } public function checkEmailExistsInNewsletter($email) { $flag = Newsletter::where('email', $email)->first(); return $flag; } public function subscribeNewEmail($email) { $new = Newsletter::insert(['email' => $email]); return $new; } public function getUserByKey($key, $value) { try { $user = User::where($key, $value)->first(); if ($user) { return $user; } return false; } catch (\Throwable $th) { return $th; } } public function completeTour($user_id) { $flag = User::where('id', $user_id)->update(['has_completed_tour' => 1]); return $flag; } public function updateUserInfo($user, $data) { $update = []; if (isset($data->mailing_address)) { $update['mailing_address'] = $data->mailing_address; } if (isset($data->bio)) { $update['bio'] = $data->bio; } if (isset($data->company_phone)) { $update['company_phone'] = $data->company_phone; } if (!empty($update)) { if ($user->userInfos()->exists()) { return UserInfo::where('user_id', $user->id)->update($update); } else { $update['user_id'] = $user->id; return UserInfo::create($update); } } return false; } public function checkVerification($user) { if ($user->email_verified_at === null) { // Check if it's been 10 days since the user was created $createdAt = Carbon::parse($user->created_at); $currentDate = Carbon::now(); $days = $createdAt->diffInDays($currentDate); $roles = $user->roles; if($roles[0]->title == 'Tenant'){ if ($days < 3) { return ['days' => 3 - $days, 'flag' => true]; // return true; // Update the is_active column to 0 // $user->update(['is_active' => 0]); } }else{ if ($days < 10) { return ['days' => 10 - $days, 'flag' => true]; // return true; // Update the is_active column to 0 // $user->update(['is_active' => 0]); } } } return ['days' => '', 'flag' => false]; } public function getAssignedTenants(){ $assignedTenants = PropertyUnitTenant::with(['tenant','unit'])->where('status' , 'active')->get(); $tenants = []; if($assignedTenants->isNotEmpty()){ foreach ($assignedTenants as $tenant) { // Access tenant details array_push($tenants, $tenant); } } return $tenants; } public function storeToken($token, $user){ $user->device_token = $token; $user->save(); return $user; } public function storeOrUpdateEmailNotification($user, $setting){ $match_this = ['user_id' => $user->id, 'setting_key' => config('constants.notification.email_notification_key_name')]; $update = Setting::updateOrCreate($match_this,['setting_value'=> $setting]); return $update; } public function storeOrUpdateDesktopNotification($user, $setting){ $match_this = ['user_id' => $user->id, 'setting_key' => config('constants.notification.desktop_notification_key_name')]; $update = Setting::updateOrCreate($match_this,['setting_value'=> $setting]); return $update; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка