EmployersController.php
10.5 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
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\FlotRequest;
use App\Models\Ad_employer;
use App\Models\Answer;
use App\Models\CategoryEmp;
use App\Models\Employer;
use App\Models\Flot;
use App\Models\Static_ad;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
class EmployersController extends Controller
{
public function index(Request $request) {
if ($request->ajax()) {
$user = User::find($request->id);
$request->offsetUnset('id');
$user->update($request->all());
}
$users = User::with('employers')->select(['users.*','users.id as usr_id', 'emp.id as emp_id',
'emp.code as code_id', 'emp.logo as emp_logo', 'emp.name_company as name_company', 'emp.*'
])
->join('employers as emp','emp.user_id','users.id')
->where('users.is_worker', '0')
->orderByDesc('emp.id')
->Realuser();
$all_employer = Employer::all()->count();
$all_public = Employer::where('status_hidden', '=', '0')->
count();
$all_status = Employer::where(function($query) {
$query->Where('category', '=', 'Не оплачен')
->orWhere('category', '=', 'Не определен')
->orWhere('category', '=', 'Согласование');
})->count();
$find_cat = "";
if (isset($request->category)) {
if ($request->category != 'Все категории') {
$users = $users->where('category', '=', $request->category);
$find_cat = $request->category;
}
}
$find_key = "";
if (isset($request->find)) {
$find_key = $request->find;
$users = $users->where(function($query) use($find_key) {
$query->where('users.name', 'LIKE', "%$find_key%")
->orWhere('emp.email', 'LIKE', "%$find_key%")
->orWhere('emp.telephone', 'LIKE', "%$find_key%")
->orWhere('emp.name_company', 'LIKE', "%$find_key%")
;
});
}
$all_current = $users->count();
$users = $users->paginate(15);
$select_category = CategoryEmp::query()->active()->get();
if ($request->ajax()) {
return view('admin.employer.index_ajax', compact('users'));
} else {
return view('admin.employer.index', compact('users', 'find_key', 'find_cat', 'all_employer',
'all_public', 'all_status', 'all_current', 'select_category'
));
}
}
public function comment_read(Employer $employer) {
return view('admin.employer.comment', compact('employer'));
}
// Форма обновления
public function form_update_employer(Employer $employer) {
// данные
$select_category = CategoryEmp::query()->active()->get();
$flots = Flot::query()->where('employer_id', '=', $employer->id)->get();
return view('admin.employer.edit', compact('employer', 'select_category', 'flots'));
}
public function edit_flot(Flot $flot, Employer $employer) {
return view('admin.flot.edit', compact('flot', 'employer'));
}
public function add_flot(Employer $employer) {
return view('admin.flot.add', compact('employer'));
}
public function save_add_flot(FlotRequest $request) {
$params = $request->all();
$params['image'] = $request->file('image')->store("flot", 'public');
Flot::create($params);
return redirect()->route('admin.employer-profile', ['employer' => $params['employer_id']])
->with('success', 'Данные были успешно сохранены');
}
public function delete_flot(Flot $flot, $employer_id) {
$flot->delete();
return redirect()->route('admin.employer-profile', ['employer' => $employer_id])
->with('success', 'Данные были успешно сохранены');
}
public function edit_save_flot(Flot $flot, FlotRequest $request) {
$params = $request->all();
if ($request->has('image')) {
if (!empty($flot->image)) {
Storage::delete($flot->image);
}
$params['image'] = $request->file('image')->store("flot", 'public');
} else {
if (!empty($flot->image)) $params['image'] = $flot->image;
}
$flot->update($params);
return redirect()->route('admin.employer-profile', ['employer' => $params['employer_id']])
->with('success', 'Данные были успешно сохранены');
}
public function update_employer(Employer $employer, Request $request)
{
$params = $request->all();
unset($params['logo']);
unset($params['telephone']);
unset($params['email']);
unset($params['address']);
unset($params['site']);
unset($params['is_lookin']);
unset($params['show_database']);
unset($params['can_autolift']);
unset($params['status_hidden']);
unset($params['oficial_status']);
unset($params['social_is']);
unset($params['sending_is']);
unset($params['category']);
unset($params['comment_admin']);
$rules = [
'name' => 'required|string|max:255',
];
$messages = [
'required' => 'Укажите обязательное поле «:attribute»',
'confirmed' => 'Пароли не совпадают',
'email' => 'Введите корректный email',
'min' => [
'string' => 'Поле «:attribute» должно быть не меньше :min символов',
'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
],
'max' => [
'string' => 'Поле «:attribute» должно быть не больше :max символов',
'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
],
];
$validator = Validator::make($params, $rules, $messages);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput(); //->route('admin.register')
} else {
//$user = User::find($employer->user_id);
$user_id = $employer->user_id;
$employer->name_company = $request->name;
$employer->telephone = $request->telephone;
$employer->telephone_2 = $request->telephone_2;
$employer->email = $request->email;
$employer->email_2 = $request->email_2;
$employer->address = $request->address;
$employer->site = $request->site;
$employer->text = $request->text;
$employer->status_hidden = $request->status_hidden;
$employer->oficial_status = $request->oficial_status;
$employer->social_is = $request->social_is;
$employer->sending_is = $request->sending_is;
$employer->category = $request->category;
$employer->comment_admin = $request->comment_admin;
if ($request->has('logo')) {
if (!empty($employer->logo)) {
Storage::delete($employer->logo);
}
$employer->logo = $request->file('logo')->store("employer/$user_id", 'public');
}
$employer->save();
$employer->users()->update([
'is_lookin' => $request->is_lookin,
'show_database' => $request->show_database,
'can_autolift' => $request->can_autolift,
]);
return redirect()->route('admin.employer-profile', ['employer' => $employer->id])
->with('success', 'Данные были успешно сохранены');
}
}
// Удаление работодателя, вакансий и профиля юзера
public function delete_employer(Employer $employer, User $user) {
try {
if (!empty($employer)) {
if (!empty($employer->logo)) {
Storage::delete($employer->logo);
}
foreach($employer->ads as $ad) {
$ads = Ad_employer::find($ad->id);
$ads->employer_id = 2;
$ads->is_remove = 1;
$ads->save();
}
$employer->delete();
}
} finally {
$user->delete();
}
return redirect()->route('admin.employers')->with('success', 'Данные были удалены о работодателе');
}
// кабинет - отзывы о работодателе для модерации
public function answers(Request $request) {
if ($request->ajax()) {
$user = Answer::find($request->id);
$request->offsetUnset('id');
$user->update($request->all());
}
$answers = Answer::query()->orderByDesc('id')->paginate(15);
if ($request->ajax()) {
return view('admin.answers.index_ajax', compact('answers'));
} else {
return view('admin.answers.index', compact('answers'));
}
}
// кабинет - статистика вакансий работодателя
public function static_ads(Request $request) {
$stat = Static_ad::with('ads');
$ads = Ad_employer::query()->active()->OrderBy('id')->get();
$periods = Static_ad::query()->distinct('year_month')->select('year_month')->get();
if ($request->ajax()) {
if (isset($request->ad_employer_id))
if (!$request->ad_employer_id == "0")
$stat = $stat->Where('ad_employer_id', '=', $request->ad_employer_id);
if (isset($request->year_month)) {
if (!$request->year_month == "0")
$stat = $stat->Where('year_month', '=', $request->year_month);
}
}
$stat = $stat->OrderByDesc('year_month');
$stat = $stat->paginate(15);
if ($request->ajax())
return view('admin.static.index_ads_ajax', compact('stat'));
else
return view('admin.static.index_ads', compact('stat', 'ads', 'periods'));
}
}