mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-01 08:16:55 -04:00
199 lines
6.7 KiB
PHP
199 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\JobPortalCandidate\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\JobPortal\Entities\Candidate;
|
|
use Modules\JobPortal\Entities\CandidateCategories;
|
|
use Modules\JobPortal\Entities\CandidateCvs;
|
|
use Modules\JobPortal\Entities\CandidateSkills;
|
|
use Modules\JobPortal\Entities\Category;
|
|
use Modules\JobPortal\Http\Controllers\JobPortalFrontendController;
|
|
use Modules\JobPortal\Entities\Location;
|
|
use Modules\JobPortal\Entities\Skill;
|
|
use Modules\JobPortal\Entities\Badge;
|
|
use App\Traits\ImageStore;
|
|
use File;
|
|
|
|
class ProfileController extends JobPortalFrontendController
|
|
{
|
|
use ImageStore;
|
|
/**
|
|
* @var Candidate
|
|
*/
|
|
private $candidate;
|
|
|
|
public function __construct(Candidate $candidate)
|
|
{
|
|
parent::__construct();
|
|
$this->candidate = $candidate;
|
|
}
|
|
|
|
public function index(){
|
|
$user = auth()->user();
|
|
|
|
$candidate = $user->candidate ?? $this->candidate;
|
|
$candidate->id = $user->id;
|
|
$candidate->save();
|
|
|
|
$data = [
|
|
'row'=> $user->candidate ?? $this->candidate,
|
|
'page_title'=>__("Candidate Profile"),
|
|
'user'=>$user,
|
|
'is_user_page' => true,
|
|
'locations' => Location::query()->where('status', 'publish')->get()->toTree(),
|
|
'categories' => Category::get()->toTree(),
|
|
'skills' => Skill::query()->where('status', 'publish')->get(),
|
|
'cvs' => CandidateCvs::query()->where('origin_id', $user->id)->with('media')->get(),
|
|
'badges' => Badge::query()->where('status', 'publish')->get(),
|
|
|
|
];
|
|
return view('jobportalcandidate::frontend.profile.edit',$data);
|
|
}
|
|
|
|
public function store(Request $request){
|
|
|
|
|
|
if (isModuleActive('StaffPortal')) {
|
|
app(\Modules\StaffPortal\Services\CommonService::class)->validateCandidateStoreRequest($request);
|
|
}
|
|
$request->validate([
|
|
'first_name' => 'required|max:255',
|
|
'last_name' => 'required|max:255',
|
|
//'title' => 'required|max:255',
|
|
]);
|
|
|
|
$user = auth()->user();
|
|
$candidate = $user->candidate ?? $this->candidate;
|
|
$candidate->id = $user->id;
|
|
|
|
|
|
$user->first_name = $request->first_name;
|
|
$user->last_name = $request->last_name;
|
|
$user->avatar_id = $request->avatar_id;
|
|
$user->bio = $request->bio;
|
|
if (isModuleActive('StaffPortal')) {
|
|
$user->username = $request->username;
|
|
}
|
|
|
|
$file = $request->file('avatar');
|
|
if ($request->hasFile('avatar')) {
|
|
if ($user->avatar) {
|
|
if (File::exists($user->avatar)) {
|
|
File::delete($user->avatar);
|
|
}
|
|
}
|
|
$user->avatar = $this->saveImage($file,200,200);
|
|
}
|
|
|
|
$user->save();
|
|
|
|
$candidate->fillByAttr([
|
|
//'title',
|
|
'gallery',
|
|
'video',
|
|
'gender',
|
|
'expected_salary',
|
|
'salary_type',
|
|
//'website',
|
|
//'education_level',
|
|
'experience_year',
|
|
'languages',
|
|
'allow_search',
|
|
|
|
'address',
|
|
'city',
|
|
'country',
|
|
'location_id',
|
|
'map_lat',
|
|
'map_lng',
|
|
'map_zoom',
|
|
|
|
'education',
|
|
'experience',
|
|
'award',
|
|
'social_media',
|
|
'video_cover_id',
|
|
'badge_id'
|
|
|
|
], $request->input());
|
|
|
|
$candidate->save();
|
|
|
|
if(!empty($request->input('languages')))
|
|
{
|
|
$candidate->languages = implode(',',$request->input('languages'));
|
|
}else{
|
|
$candidate->languages = '';
|
|
}
|
|
|
|
$candidate->saveOriginOrTranslation($request->query('lang'),true);
|
|
|
|
|
|
$uploadedCandidate = CandidateCvs::query()->where('origin_id', $user->id)->pluck('file_id')->toArray();
|
|
$cvUpload = $request->input('cvs', []);
|
|
if(!empty($cvUpload)) {
|
|
CandidateCvs::query()->where('origin_id', $user->id)->whereNotIn('file_id', $cvUpload)->delete();
|
|
foreach ($cvUpload as $oneCv) {
|
|
if (in_array($oneCv, $uploadedCandidate)) {
|
|
continue;
|
|
}
|
|
$cv = new CandidateCvs();
|
|
$cv->file_id = $oneCv;
|
|
$cv->origin_id = $user->id;
|
|
$cv->is_default = 0;
|
|
$cv->create_user = Auth::id();
|
|
$cv->save();
|
|
}
|
|
|
|
//Update Default CV
|
|
CandidateCvs::query()->where("origin_id", $user->id)->update(['is_default' => 0]);
|
|
CandidateCvs::query()->where("origin_id", $user->id)->where('file_id', @$request->csv_default)->update(['is_default' => 1]);
|
|
}
|
|
|
|
if(!empty($request->skills)){
|
|
$cSkills = CandidateSkills::query()->where('origin_id', $user->id)->pluck('skill_id')->toArray();
|
|
foreach($request->skills as $skill){
|
|
$pos = array_search(intval($skill), $cSkills);
|
|
if($pos !== false){
|
|
unset($cSkills[$pos]);
|
|
}else{
|
|
DB::table('jp_candidate_skills')->insert([
|
|
'origin_id' => $user->id,
|
|
'skill_id' => $skill
|
|
]);
|
|
}
|
|
}
|
|
if(!empty($cSkills)){
|
|
CandidateSkills::query()->where('origin_id', $user->id)->whereIn('skill_id', $cSkills)->delete();
|
|
}
|
|
}else{
|
|
CandidateSkills::query()->where('origin_id', $user->id)->delete();
|
|
}
|
|
|
|
if(!empty($request->categories)){
|
|
$cCats = CandidateCategories::query()->where('origin_id', $user->id)->pluck('cat_id')->toArray();
|
|
foreach($request->categories as $category){
|
|
$pos = array_search(intval($category), $cCats);
|
|
if($pos !== false){
|
|
unset($cCats[$pos]);
|
|
}else{
|
|
DB::table('jp_candidate_categories')->insert([
|
|
'origin_id' => $user->id,
|
|
'cat_id' => $category
|
|
]);
|
|
}
|
|
}
|
|
if(!empty($cCats)){
|
|
CandidateCategories::query()->where('origin_id', $user->id)->whereIn('cat_id', $cCats)->delete();
|
|
}
|
|
}else{
|
|
CandidateCategories::query()->where('origin_id', $user->id)->delete();
|
|
}
|
|
|
|
return back()->with('success',__("Candidate profile saved"));
|
|
}
|
|
}
|