WorkerController.php
44.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
<?php
namespace App\Http\Controllers;
use App\Classes\RusDate;
use App\Classes\Tools;
use App\Http\Requests\DocumentsRequest;
use App\Http\Requests\PrevCompanyRequest;
use App\Http\Requests\SertificationRequest;
use App\Models\Ad_employer;
use App\Models\ad_response;
use App\Models\Chat;
use App\Models\Dop_info;
use App\Models\Employer;
use App\Models\EmployerAutoliftOption;
use App\Models\infobloks;
use App\Models\Job_title;
use App\Models\Like_vacancy;
use App\Models\Message;
use App\Models\place_works;
use App\Models\PrevCompany;
use App\Models\ResponseWork;
use App\Models\sertification;
use App\Models\Static_worker;
use App\Models\Title_worker;
use App\Models\User;
use App\Models\User as User_Model;
use App\Models\Worker;
use App\Models\WorkerAutoliftOption;
use Barryvdh\DomPDF\Facade\Pdf;
use Carbon\Carbon;
use Illuminate\Auth\Events\Registered;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Illuminate\View\View;
use JsonException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Symfony\Component\HttpFoundation\StreamedResponse;
use App\Enums\DbExportColumns;
use App\Enums\WorkerStatuses;
use DateTime;
class WorkerController extends Controller
{
//профиль
public function profile(Worker $worker)
{
$get_date = date('Y.m');
$c = Static_worker::query()->where('year_month', '=', $get_date)
->where('user_id', '=', $worker->users->id)
->get();
if ($c->count() > 0) {
$upd = Static_worker::find($c[0]->id);
$upd->lookin = $upd->lookin + 1;
$upd->save();
} else {
$crt = new Static_worker();
$crt->lookin = 1;
$crt->year_month = $get_date;
$crt->user_id = $worker->user_id;
$crt->save();
}
$stat = Static_worker::query()->where('year_month', '=', $get_date)
->where('user_id', '=', $worker->users->id)
->get();
return view('public.workers.profile', compact('worker', 'stat'));
}
// лист база резюме
public function bd_resume(Request $request)
{
if (isset(Auth()->user()->id)) {
if ((Auth()->user()->is_worker) || (!Auth()->user()->is_lookin))
return redirect()->route('index')->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]);
}
$status_work = WorkerStatuses::getWorkerStatuses();
$resumes = Worker::query()->with('users')->with('job_titles')->orderByDesc('updated_at');
$resumes = $resumes->whereHas('users', function (Builder $query) {
$query->Where('is_worker', '=', '1')
->Where('is_bd', '=', '0');
});
if (($request->has('job')) && ($request->get('job') > 0)) {
$resumes = $resumes->whereHas('job_titles', function (Builder $query) use ($request) {
$query->Where('job_titles.id', $request->get('job'));
});
}
$Job_title = Job_title::query()
->where('is_remove', '=', '0')
->where('is_bd', '=' , '1')
->orderByDesc('sort')
->get();
if ($request->get('sort')) {
$sort = $request->get('sort');
switch ($sort) {
case 'looking_for_work':
$resumes->where('status_work', '=', WorkerStatuses::LookingForWork->value);
break;
case 'considering_offers':
$resumes->where('status_work', '=', WorkerStatuses::ConsideringOffers->value);
break;
case 'not_looking_for_work':
$resumes->where('status_work', '=', WorkerStatuses::NotLookingForWork->value);
break;
}
}
$resumes = $resumes->get()->filter(function ($worker) {
return Tools::getWorkerProfilePercent($worker) >= 50;
});
$res_count = $resumes->count();
$currentPage = $_GET['page'] ?? 1;
$resumes = new LengthAwarePaginator(
items: $resumes->slice(4 * ($currentPage - 1), 4),
total: $res_count,
perPage: 4,
);
$resumes->setPath('bd-resume');
if ($request->ajax()) {
// Условия обставлены
if ($request->has('block') && ($request->get('block') == 1)) {
return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count'));
}
} else {
return view('resume', compact('resumes', 'status_work', 'res_count', 'Job_title'));
}
}
public function basic_information(){
if (!isset(Auth()->user()->id)) {
abort(404);
}
$user_id = Auth()->user()->id;
$user = User::query()
->with('workers')
->with(['jobtitles' => function ($query) {
$query->select('job_titles.id');
}])
->where('id', '=', $user_id)
->first();
$user->workers[0]->job_titles = $user->workers[0]->job_titles->pluck('id')->toArray();
$job_titles = Job_title::query()
->where('is_remove', '=', 0)
->where('is_bd', '=', 1)
->orderByDesc('sort')
->get()
;
return view('workers.form_basic_information', compact('user', 'job_titles'));
}
public function additional_documents(){
if (!isset(Auth()->user()->id)) {
abort(404);
}
$user_id = Auth()->user()->id;
$info_blocks = infobloks::query()->OrderBy('name')->get();
$additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует'];
$worker = Worker::query()
->with('users')
->with('infobloks')
->WhereHas('users', function (Builder $query) use ($user_id) {
$query->Where('id', $user_id);
})
->first();
if ($worker->dop_info->count()){
$worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray();
}
return view('workers.form_additional_documents', compact('worker', 'info_blocks', 'additional_document_statuses'));
}
//Лайк резюме
public function like_controller() {
}
// анкета соискателя
public function resume_profile(Worker $worker)
{
if (isset(Auth()->user()->id)) {
$idiot = Auth()->user()->id;
} else {
$idiot = 0;
}
$status_work = WorkerStatuses::getWorkerStatuses();
$Query = Worker::query()->with('users')->with('job_titles')
->with('place_worker')->with('sertificate')->with('prev_company')
->with('infobloks')->with('response');
$Query = $Query->where('id', '=', $worker->id);
$Query = $Query->get();
$get_date = date('Y.m');
$infoblocks = infobloks::query()->get();
$c = Static_worker::query()->where('year_month', '=', $get_date)
->where('user_id', '=', $worker->user_id)
->get();
if ($c->count() > 0) {
$upd = Static_worker::find($c[0]->id);
$upd->lookin = $upd->lookin + 1;
$upd->save();
} else {
$crt = new Static_worker();
$crt->lookin = 1;
$crt->year_month = $get_date;
$crt->user_id = $worker->user_id;
$status = $crt->save();
}
$stat = Static_worker::query()->where('year_month', '=', $get_date)
->where('user_id', '=', $worker->user_id)
->get();
return view('worker', compact('Query', 'infoblocks', 'status_work', 'idiot', 'stat'));
}
// скачать анкету соискателя
public function resume_download(Worker $worker)
{
$status_work = WorkerStatuses::getWorkerStatuses();
$Query = Worker::query()->with('users')->with('job_titles')
->with('place_worker')->with('sertificate')->with('prev_company')
->with('infobloks');
$Query = $Query->where('id', '=', $worker->id);
$Query = $Query->get();
view()->share('Query',$Query);
$status_work = WorkerStatuses::getWorkerStatuses();
$infoblocks = infobloks::query()->get();
//return view('layout.pdf', compact('Query', 'status_work', 'infoblocks'));
$pdf = PDF::loadView('layout.pdf', [
'Query' => $Query,
'status_work' => $status_work,
'infoblocks' => $infoblocks
])->setPaper('a4', 'landscape');
return $pdf->download();
}
public function resume_download_all(Request $request) {
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$columnMap = range('A', 'Z');
$columns = [];
foreach (DbExportColumns::toArray() as $key => $value){
if ($request->input($key, 0)){
$sheet->setCellValue("{$columnMap[count($columns)]}1", ucfirst($value));
$columns[] = str_replace('__', '.', $key);
}
}
if (empty($columns)) {
return redirect()->back()->with('error', 'Пожалуйста выберите хотя бы 1 колонку для экспорта.');
}
$jobIds = $request->input('job_title_list', []);
/* //query for mysql ver 8.0 or higher
$users = DB::select(
"select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone`
from users
join workers on `users`.`id` = `workers`.`user_id`
join `job_titles`
where `users`.`is_bd` = 1
and (`workers`.`position_work` = `job_titles`.`id`
or exists (select 1
from JSON_TABLE(
workers.positions_work,
'$[*]' COLUMNS (id INT PATH '$')) pw
where pw.id = job_titles.id)
)". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '')
);*/
/*$users = DB::select(
"select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone`
from users
join workers on `users`.`id` = `workers`.`user_id`
join `job_titles`
where `users`.`is_bd` = 2
and (`workers`.`position_work` = `job_titles`.`id`
or `workers`.`positions_work`
)". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '')
);*/
/*$users = DB::select("select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`,
`users`.`surname2`, `users`.`email`, `users`.`telephone`, `users`.`id`, `job_titles`.`id`
FROM `users`
JOIN `job_titles`
JOIN workers ON `users`.id = `workers`.user_id
JOIN worker_jobs ON `users`.`id` = `worker_jobs`.user_id AND
`job_titles`.`id` = `worker_jobs`.job_id");
*/
$first_part = "SELECT
w.user_id, u.`name`, u.`surname`, u.`surname2`,
GROUP_CONCAT(j.`name` SEPARATOR ', ') AS job_titles_names,
u.`email`, u.`telephone`, w.`positions_work`
FROM
users u
INNER JOIN
Workers w ON u.id = w.user_id
INNER JOIN
JSON_TABLE(w.positions_work, '$[*]' COLUMNS (pos INT PATH '$')) AS extracted_positions
INNER JOIN
job_titles j ON j.id = extracted_positions.pos";
$second_part = " ";
if (!is_null($jobIds))
if (is_array($jobIds))
if (count($jobIds) > 0)
{
$second_part = " WHERE ";
foreach ($jobIds as $key => $it) {
if ($key == 0)
$second_part .= "(j.id = ".$it.") ";
elseif ($key > 0)
$second_part .= "OR (j.id = ".$it.") ";
}
}
$three_part = "GROUP BY w.user_id, w.positions_work, u.`name`
HAVING COUNT(DISTINCT j.id) = JSON_LENGTH(w.positions_work)";
$users = DB::select($first_part.$second_part.$three_part);
$users = collect($users);
if ($users->count()) {
$i = 2;
foreach ($users->toArray() as $user){
$j = 0;
foreach ($user as $field){
$sheet->setCellValue("{$columnMap[$j++]}$i", $field);
}
$i++;
}
}
$writer = new Xlsx($spreadsheet);
$fileName = 'DB.xlsx';
$response = new StreamedResponse(function() use ($writer) {
$writer->save('php://output');
});
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$response->headers->set('Content-Disposition', 'attachment;filename="' . $fileName . '"');
$response->headers->set('Cache-Control', 'max-age=0');
return $response;
}
// Кабинет работника
public function cabinet(Request $request)
{
// дата год и месяц
$get_date = date('Y.m');
$id = Auth()->user()->id;
$Infobloks = infobloks::query()->get();
$Worker = Worker::query()
->with(['users', 'sertificate', 'prev_company', 'infobloks', 'place_worker'])
->WhereHas('users', function (Builder $query) use ($id) {
$query->Where('id', $id);
})->first();
$Job_titles = Job_title::query()->where('is_remove', '=', '0')
->where('is_bd', '=' , '1')
->OrderByDesc('sort')->OrderBy('name')
->get();
$stat = Static_worker::query()->where('year_month', '=', $get_date)
->where('user_id', '=', $id)
->get();
$persent = Tools::getWorkerProfilePercent($Worker);
$status_work = WorkerStatuses::getWorkerStatuses();
$additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует'];
$info_blocks = infobloks::query()->OrderBy('name')->get();
$worker = Worker::query()
->with('users')
->with('sertificate')
->with('prev_company')
->with('infobloks')
->with('place_worker')
->with('job_titles')
->WhereHas('users', function (Builder $query) use ($id) {
$query->Where('id', $id);
})
->first();
if ($worker->dop_info->count()){
$worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray();
}
//dd($worker->dop_info);
if ($request->has('print')) {
dd($Worker);
} else {
return view('workers.cabinet', compact( 'persent', 'Job_titles', 'stat',
'worker', 'info_blocks', 'status_work', 'additional_document_statuses'
));
}
}
// Сохранение данных
public function cabinet_save(Worker $worker, Request $request)
{
$id = $worker->id;
$params = $request->all();
$job_title_id = $request->get('job_title_id');
$rules = [
'surname' => ['required', 'string', 'max:255'],
'name_man' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255'],
];
$messages = [
'required' => 'Укажите обязательное поле',
'min' => [
'string' => 'Поле «:attribute» должно быть не меньше :min символов',
'integer' => 'Поле «:attribute» должно быть :min или больше',
'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
],
'max' => [
'string' => 'Поле «:attribute» должно быть не больше :max символов',
'integer' => 'Поле «:attribute» должно быть :max или меньше',
'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
]
];
$validator = Validator::make($params, $rules, $messages);
if ($validator->fails()) {
return redirect()->route('worker.cabinet')->withErrors($validator);
} else {
if ($request->has('photo')) {
if (!empty($worker->photo)) {
Storage::delete($worker->photo);
}
$params['photo'] = $request->file('photo')->store("worker/$id", 'public');
}
if ($request->has('file')) {
if (!empty($worker->file)) {
Storage::delete($worker->file);
}
$params['file'] = $request->file('file')->store("worker/$id", 'public');
}
$worker->update($params);
$use = User::find($worker->user_id);
$use->surname = $request->get('surname');
$use->name_man = $request->get('name_man');
$use->surname2 = $request->get('surname2');
$use->save();
$worker->job_titles()->sync($job_title_id);
return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены');
}
}
public function cabinet_save_foto(Worker $worker, Request $request){
$params = ['photo' => null];
if ($request->has('photo')) {
if (!empty($worker->photo)) {
Storage::delete($worker->photo);
}
$params['photo'] = $request->file('photo')->store("worker/$worker->id", 'public');
}
if ($request->has('file')) {
if (!empty($worker->file)) {
Storage::delete($worker->file);
}
$params['file'] = $request->file('file')->store("worker/$worker->id", 'public');
}
$worker->update($params);
return redirect()->route('worker.cabinet');
}
// Сообщения данные
public function messages($type_message)
{
$user_id = Auth()->user()->id;
$chats = Chat::get_user_chats($user_id);
$admin_chat = Chat::get_user_admin_chat($user_id);
$user_type = 'worker';
return view('workers.messages', compact('chats', 'admin_chat','user_id', 'user_type'));
}
// Избранный
public function favorite()
{
return view('workers.favorite');
}
// Сменить пароль
public function new_password()
{
$email = Auth()->user()->email;
return view('workers.new_password', compact('email'));
}
// Обновление пароля
public function save_new_password(Request $request) {
$use = Auth()->user();
$request->validate([
'password' => 'required|string',
'new_password' => 'required|string',
'new_password2' => 'required|string'
]);
if ($request->get('new_password') == $request->get('new_password2'))
if ($request->get('password') !== $request->get('new_password')) {
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials, $request->has('save_me'))) {
if (!is_null($use->email_verified_at)){
$user_data = User_Model::find($use->id);
$user_data->update([
'password' => Hash::make($request->get('new_password')),
'pubpassword' => base64_encode($request->get('new_password')),
]);
return redirect()
->route('worker.new_password')
->with('success', 'Поздравляю! Вы обновили свой пароль!');
}
return redirect()
->route('worker.new_password')
->withError('Данная учетная запись не было верифицированна!');
}
}
return redirect()
->route('worker.new_password')
->withErrors('Не совпадение данных, обновите пароли!');
}
// Удаление профиля форма
public function delete_profile()
{
$login = Auth()->user()->email;
return view('workers.delete_profile', compact('login'));
}
// Удаление профиля код
public function delete_profile_result(Request $request) {
$Answer = $request->all();
$user_id = Auth()->user()->id;
$request->validate([
'password' => 'required|string',
]);
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
Auth::logout();
$it = User_Model::find($user_id);
$it->delete();
return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт');
} else {
return redirect()->route('worker.delete_profile')
->withErrors( 'Неверный пароль! Нужен корректный пароль');
}
}
// Регистрация соискателя
public function register_worker(Request $request)
{
$params = $request->all();
$params['is_worker'] = 1;
$rules = [
'surname' => ['required', 'string', 'max:255'],
'name_man' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:6']
];
$messages = [
'required' => 'Укажите обязательное поле',
'min' => [
'string' => 'Поле «:attribute» должно быть не меньше :min символов',
'integer' => 'Поле «:attribute» должно быть :min или больше',
'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
],
'max' => [
'string' => 'Поле «:attribute» должно быть не больше :max символов',
'integer' => 'Поле «:attribute» должно быть :max или меньше',
'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
]
];
$email = $request->get('email');
if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) {
return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл"));
}
if ($request->get('password') !== $request->get('confirmed')){
return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля"));
}
if (strlen($request->get('password')) < 6) {
return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!"));
}
if (($request->has('politik')) && ($request->get('politik') == 1)) {
$validator = Validator::make($params, $rules, $messages);
if ($validator->fails()) {
return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе."));
} else {
$user = $this->create($params);
event(new Registered($user));
Auth::guard()->login($user);
}
if ($user) {
return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));;
} else {
return json_encode(Array("ERROR" => "Error2: Данные были утеряны!"));
}
} else {
return json_encode(Array("ERROR" => "Error3: Вы не согласились с политикой конфидициальности!"));
}
}
// Звездная оценка и ответ
public function stars_answer(Request $request) {
$params = $request->all();
$rules = [
'message' => ['required', 'string', 'max:255'],
];
$messages = [
'required' => 'Укажите обязательное поле',
'min' => [
'string' => 'Поле «:attribute» должно быть не меньше :min символов',
'integer' => 'Поле «:attribute» должно быть :min или больше',
'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
],
'max' => [
'string' => 'Поле «:attribute» должно быть не больше :max символов',
'integer' => 'Поле «:attribute» должно быть :max или меньше',
'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
]
];
$response_worker = ResponseWork::create($params);
return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!');
}
public function TestWorker()
{
$Use = new User();
$Code_user = $Use->create([
'name' => 'surname name_man',
'name_man' => 'name_man',
'surname' => 'surname',
'surname2' => 'surname2',
'subscribe_email' => '1',
'email' => 'email@mail.com',
'telephone' => '1234567890',
'password' => Hash::make('password'),
'pubpassword' => base64_encode('password'),
'email_verified_at' => Carbon::now(),
'is_worker' => 1,
]);
if ($Code_user->id > 0) {
$Worker = new Worker();
$Worker->user_id = $Code_user->id;
$Worker->position_work = 1; //'job_titles';
$Worker->email = 'email@email.com';
$Worker->telephone = '1234567890';
$status = $Worker->save();
$Title_Worker = new Title_worker();
$Title_Worker->worker_id = $Worker->id;
$Title_Worker->job_title_id = 1;
$Title_Worker->save();
}
}
// Создание пользователя
protected function create(array $data)
{
$Use = new User();
$Code_user = $Use->create([
'name' => $data['surname']." ".$data['name_man'],
'name_man' => $data['name_man'],
'surname' => $data['surname'],
'surname2' => $data['surname2'],
'subscribe_email' => $data['email'],
'email' => $data['email'],
'telephone' => $data['telephone'],
'password' => Hash::make($data['password']),
'pubpassword' => base64_encode($data['password']),
'email_verified_at' => Carbon::now(),
'is_worker' => $data['is_worker'],
]);
if ($Code_user->id > 0) {
$Worker = new Worker();
$Worker->user_id = $Code_user->id;
$Worker->position_work = $data['job_titles'];
$Worker->email = $data['email'];
$Worker->telephone = $data['telephone'];
$Worker->save();
if (isset($Worker->id)) {
$Title_Worker = new Title_worker();
$Title_Worker->worker_id = $Worker->id;
$Title_Worker->job_title_id = $data['job_titles'];
$Title_Worker->save();
}
return $Code_user;
}
}
// Вакансии избранные
public function colorado(Request $request) {
$Arr = Like_vacancy::Query()
->select('code_record')
->where('user_id', Auth::user()->id)
->get();
if ($Arr->count()) {
$A = Array();
foreach ($Arr as $it) {
$A[] = $it->code_record;
}
$Query = Ad_employer::query()->whereIn('id', $A);
} else {
$Query = Ad_employer::query()->where('id', '=', '0');
}
$Query = $Query->with(['jobs', 'cat', 'employer'])
->whereHas('jobs_code', function ($query) use ($request) {
if ($request->ajax()) {
if (null !== ($request->get('job'))) {
$query->where('job_title_id', $request->get('job'));
}
}
})
->select('ad_employers.*');
if ($request->get('search') !== null) {
$search = $request->get('search');
$Query->where('name', 'LIKE', "%$search%");
}
//dd($Query->get());
$Job_title = Job_title::query()->OrderBy('name')->get();
$Query_count = $Query->count();
$Query = $Query->OrderBy('updated_at')->paginate(3);
return view('workers.favorite', compact('Query',
'Query_count',
'Job_title'));
}
//Переписка
public function dialog(Chat $chat, Request $request) {
// Получение параметров.
if ($request->has('ad_employer')){
$ad_employer = $request->get('ad_employer');
} else {
$ad_employer = 0;
}
$sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first();
$companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first();
$Messages = Chat::get_chat_messages($chat);
Message::where('chat_id_to', '=', $chat->id)->update(['flag_new' => 0]);
return view('workers.dialog', compact('companion', 'sender', 'chat', 'Messages', 'ad_employer'));
}
// Даунылоады
public function download(Worker $worker) {
$arr_house = ['0' => 'Проверка, проверка, проверка, проверка, проверка...'];
view()->share('house',$arr_house);
$pdf = PDF::loadView('layout.pdf', $arr_house)->setPaper('a4', 'landscape');
return $pdf->stream();
}
// Поднятие анкеты
public function up(Worker $worker) {
$worker->updated_at = Carbon::now();
$worker->save();
// 0
return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных');
}
// Форма сертификате
public function new_sertificate(Worker $worker) {
return view('workers.sertificate_add', compact('worker'));
}
// Добавление сертификата
public function add_serificate(SertificationRequest $request) {
$request->validate([
'name' => 'required|string|max:255',
'end_begin' => 'required|date|date_format:d.m.Y'
],
[
'name' => 'Навание сертификата обязательно для заполнения.',
'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг'
]);
$params = $request->all();
$end_begin = DateTime::createFromFormat('d.m.Y', $params['end_begin']);
$params['end_begin'] = $end_begin->format('Y-m-d');
$Sertificate = new sertification();
$Sertificate->create($params);
return response()->json([
'success' => true
]);
}
// Удалить сертификат
public function delete_sertificate(sertification $doc) {
$doc->delete();
return redirect()->route('worker.cabinet');
}
// Редактирование сертификата
public function edit_sertificate(Worker $worker, sertification $doc) {
return view('workers.sertificate_edit', compact('doc', 'worker'));
}
// Редактирование обновление сертификата
public function update_serificate(SertificationRequest $request, sertification $doc) {
$request->validate([
'name' => 'required|string|max:255',
'end_begin' => 'required|date|date_format:d.m.Y'
],
[
'name' => 'Навание сертификата обязательно для заполнения.',
'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг'
]);
$all = $request->all();
$end_begin = DateTime::createFromFormat('d.m.Y', $all['end_begin']);
$all['end_begin'] = $end_begin->format('Y-m-d');
$doc->worker_id = $all['worker_id'];
$doc->name = $all['name'];
$doc->end_begin = $all['end_begin'];
$doc->save();
return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!');
}
public function edit_diploms(Request $request, Worker $worker) {
$dop_info_data = $request->input('diploms');
if (empty($dop_info_data)) {
return redirect()->route('worker.additional_documents')->with('error', 'Данные не предоставлены!');
}
foreach ($dop_info_data as $infoblok_id => $status) {
Dop_info::updateOrCreate(
['worker_id' => $worker->id, 'infoblok_id' => $infoblok_id],
['status' => $status]
);
}
return redirect()->route('worker.additional_documents')->with('success', 'Успешно сохранено!');
}
public function delete_add_diplom(Request $request, Worker $worker) {
$infoblok_id = $request->get('infoblok_id');
if (Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->count() > 0)
$id = Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->delete();
else {
$params['infoblok_id'] = $infoblok_id;
$params['worker_id'] = $worker->id;
$params['status'] = $request->get('val');
$id = Dop_info::create($params);
//$id = $worker->infobloks()->sync([$infoblok_id]);
}
//$Infoblocks = infobloks::query()->get();
return $id; //redirect()->route('worker.cabinet')->getTargetUrl(); //view('workers.ajax.diploms_dop', compact('worker', 'Infoblocks'));
}
// Добавление диплома
public function add_diplom_ajax(Request $request) {
// конец
$params = $request->all();
$count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count();
if ($count == 0) $dop_info = Dop_info::create($params);
$Infoblocks = infobloks::query()->get();
$Worker = Worker::query()->where('id', $request->get('worker_id'))->get();
$data = Dop_info::query()->where('worker_id', $request->has('worker_id'));
return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker'));
}
// Добавление диплома без ajax
public function add_diplom(Worker $worker) {
$worker_id = $worker->id;
$Infoblocks = infobloks::query()->get();
return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks'));
}
// Сохранить
// Сохраняю диплом
public function add_diplom_save(Request $request) {
$params = $request->all();
$count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count();
if ($count == 0) $dop_info = Dop_info::create($params);
return redirect()->route('worker.cabinet');
}
// Добавление стандартного документа
public function add_document(Worker $worker) {
return view('workers.docs', compact('worker'));
}
//Сохранение стандартого документа
public function add_document_save(DocumentsRequest $request) {
$params = $request->all();
place_works::create($params);
return response()->json(['success' => true]);
}
// Редактирование документа
public function edit_document(place_works $doc, Worker $worker) {
return view('workers.docs-edit', compact('doc', 'worker'));
}
//Сохранение отредактированного документа
public function edit_document_save(DocumentsRequest $request, place_works $doc) {
$params = $request->all();
$doc->update($params);
return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!');
}
// Удаление документа
public function delete_document(place_works $doc) {
$doc->delete();
return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!');
}
//Отправка нового сообщения
public function new_message(Request $request)
{
$params = $request->all();
$id = $params['user_from'];
Message::add_message(
$request,
$params['user_from'],
$params['user_to'],
[
'text' => $params['comment'] ?? null,
'ad_employer_id' => $params['vacancy'],
'flag_new' => 1
],
file_store_path: "worker/$id"
);
if ($request->ajax()) {
return response([]);
}
return redirect()->back();
}
public function test123(Request $request) {
$params = $request->all();
$user1 = $params['user_id'];
$user2 = $params['to_user_id'];
$rules = [
'text' => 'nullable|required_without:file|min:1|max:150000',
'file' => 'nullable|file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000'
];
$messages = [
'required_without' => 'Поле «:attribute» обязательно, если файл не прикреплен',
'min' => [
'string' => 'Поле «:attribute» должно быть не меньше :min символов',
'integer' => 'Поле «:attribute» должно быть :min или больше',
'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
],
'max' => [
'string' => 'Поле «:attribute» должно быть не больше :max символов',
'integer' => 'Поле «:attribute» должно быть :max или меньше',
'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
]
];
$validator = Validator::make($request->all(), $rules, $messages);
if ($validator->fails()) {
$chat = Chat::where('user_id', $user1)
->where('to_user_id', $user2)
->where('is_removed', 0)
->first();
if ($chat->id){
return redirect()->route('worker.dialog', ['chat' => $chat->id])->withErrors($validator);
} else {
return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator);
}
} else {
$new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
//dd('new message', $new_message);
return redirect()->route('worker.dialog', ['chat' => $new_message->chat_id_from]);
}
}
// Информация о предыдущих компаниях
public function new_prev_company(Worker $worker) {
return view('workers.prev_company_form', compact('worker'));
}
// Добавление контакта компании
public function add_prev_company(PrevCompanyRequest $request) {
// Возвращение параметров
$all = $request->all();
PrevCompany::create($all);
return response()->json(['success' => true]);
}
// Редактирование контакта компании
public function edit_prev_company(PrevCompany $doc, Worker $worker) {
return view('workers.prev_company_edit_form', compact('doc', 'worker'));
}
//Сохранение редактирования контакта компании
public function update_prev_company(PrevCompany $doc, Request $request){
$all = $request->all();
$doc->update($all);
return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись');
}
// Удаление контакта предыдущей компании
public function delete_prev_company(PrevCompany $doc) {
$doc->delete();
return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!');
}
public function autoresponder()
{
$user = Auth::user();
return view('workers.autoresponder', compact('user'));
}
public function autoresponderSave(Request $request): RedirectResponse
{
/** @var Employer $employer */
$employer = Auth::user();
$employer->autoresponder = $request->get('autoresponder', false) === 'on';
$employer->autoresponder_message = $request->get('autoresponder_message');
$employer->save();
return redirect(route('worker.autoresponder'));
}
/**
* @throws JsonException
*/
public function resumeAutoLiftForm(): View
{
$worker = Auth::user()->workers[0];
$options = $worker->autoliftOptions ?? new WorkerAutoliftOption();
return view('workers.resume_autolift', compact('worker', 'options'));
}
/**
* @throws JsonException
*/
public function resumeAutoLiftSave(Request $request)
{
$worker = Auth::user()->workers[0];
$worker->autoliftOptions()->updateOrCreate(
[
'worker_id' => $worker->id,
],
[
'is_enabled' => $request->get('is_enabled') === 'true',
'times_per_day' => $request->get('times_per_day'),
'days_repeat' => $request->get('days_repeat'),
'time_send_first' => $request->get('time_send_first'),
'time_send_second' => $request->get('time_send_second'),
'time_send_third' => $request->get('time_send_third'),
'time_send_tg' => $request->get('time_send_tg'),
'autolift_site' => $request->get('autolift_site') === 'on',
]
);
return response()->json(['success' => true]);
}
}