|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coyote\Http\Forms\Job; |
|
4
|
|
|
|
|
5
|
|
|
use Coyote\Country; |
|
6
|
|
|
use Coyote\Currency; |
|
7
|
|
|
use Coyote\Job; |
|
8
|
|
|
use Coyote\Repositories\Contracts\FeatureRepositoryInterface as FeatureRepository; |
|
9
|
|
|
use Coyote\Services\FormBuilder\Form; |
|
10
|
|
|
use Coyote\Services\FormBuilder\FormEvents; |
|
11
|
|
|
use Coyote\Services\Geocoder\GeocoderInterface; |
|
12
|
|
|
use Coyote\Services\Parser\Helpers\City; |
|
13
|
|
|
use Coyote\Tag; |
|
14
|
|
|
use Illuminate\Validation\Rule; |
|
15
|
|
|
|
|
16
|
|
|
class JobForm extends Form |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $theme = self::THEME_INLINE; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Job |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $data; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* It's public so we can use use attr from twig |
|
30
|
|
|
* |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
public $attr = [ |
|
34
|
|
|
'method' => self::POST, |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var GeocoderInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
private $geocoder; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var FeatureRepository |
|
44
|
|
|
*/ |
|
45
|
|
|
private $feature; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param GeocoderInterface $geocoder |
|
49
|
|
|
* @param FeatureRepository $feature |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(GeocoderInterface $geocoder, FeatureRepository $feature) |
|
52
|
|
|
{ |
|
53
|
|
|
parent::__construct(); |
|
54
|
|
|
|
|
55
|
|
|
$this->geocoder = $geocoder; |
|
56
|
|
|
$this->feature = $feature; |
|
57
|
|
|
|
|
58
|
|
|
$this->addEventListener(FormEvents::POST_SUBMIT, function (JobForm $form) { |
|
59
|
|
|
// call macro and flush collection items |
|
60
|
|
|
$this->data->tags->flush(); |
|
61
|
|
|
$this->data->locations->flush(); |
|
|
|
|
|
|
62
|
|
|
$this->data->features->flush(); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
foreach ($form->get('tags')->getChildrenValues() as $tag) { |
|
|
|
|
|
|
65
|
|
|
$pivot = $this->data->tags()->newPivot(['priority' => $tag['priority']]); |
|
66
|
|
|
$model = (new Tag($tag))->setRelation('pivot', $pivot); |
|
67
|
|
|
|
|
68
|
|
|
$this->data->tags->add($model); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
foreach ($form->get('features')->getChildrenValues() as $feature) { |
|
|
|
|
|
|
72
|
|
|
$checked = (int) $feature['checked']; |
|
73
|
|
|
|
|
74
|
|
|
$pivot = $this->data->features()->newPivot([ |
|
75
|
|
|
'checked' => $checked, |
|
76
|
|
|
'value' => $checked ? ($feature['value'] ?? null) : null |
|
77
|
|
|
]); |
|
78
|
|
|
|
|
79
|
|
|
$model = $this->feature->find($feature['id'])->setRelation('pivot', $pivot); |
|
80
|
|
|
|
|
81
|
|
|
$this->data->features->add($model); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$cities = (new City())->grab($form->get('city')->getValue()); |
|
85
|
|
|
|
|
86
|
|
|
foreach ($cities as $city) { |
|
87
|
|
|
$this->data->locations->add(new Job\Location($this->geocode($city))); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$this->data->country()->associate((new Country())->find($form->get('country_id')->getValue())); |
|
|
|
|
|
|
91
|
|
|
}); |
|
92
|
|
|
|
|
93
|
|
|
$this->addEventListener(FormEvents::PRE_RENDER, function (JobForm $form) { |
|
94
|
|
|
$session = $form->getRequest()->session(); |
|
95
|
|
|
|
|
96
|
|
|
if ($session->hasOldInput('tags')) { |
|
|
|
|
|
|
97
|
|
|
$assoc = []; |
|
98
|
|
|
|
|
99
|
|
|
foreach ($form->get('tags')->getChildrenValues() as $tag) { |
|
|
|
|
|
|
100
|
|
|
$assoc[] = [ |
|
101
|
|
|
'name' => $tag['name'], |
|
102
|
|
|
'pivot' => [ |
|
103
|
|
|
'priority' => $tag['priority'] |
|
104
|
|
|
] |
|
105
|
|
|
]; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$form->get('tags')->setValue($assoc); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if ($session->hasOldInput('features')) { |
|
|
|
|
|
|
112
|
|
|
$assoc = []; |
|
113
|
|
|
|
|
114
|
|
|
foreach ($form->get('features')->getChildrenValues() as $feature) { |
|
|
|
|
|
|
115
|
|
|
$assoc[] = [ |
|
116
|
|
|
'id' => $feature['id'], |
|
117
|
|
|
'name' => $feature['name'], |
|
118
|
|
|
'default' => $feature['default'], |
|
119
|
|
|
'pivot' => [ |
|
120
|
|
|
'checked' => (int) $feature['checked'], |
|
121
|
|
|
'value' => $feature['value'] ?? '' |
|
122
|
|
|
] |
|
123
|
|
|
]; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
$form->get('features')->setValue($assoc); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
// tags as json (for vue.js) |
|
130
|
|
|
$form->get('tags')->setValue(collect($form->get('tags')->getChildrenValues())->toJson()); |
|
|
|
|
|
|
131
|
|
|
// features as json (for vue.js) |
|
132
|
|
|
$form->get('features')->setValue(collect($form->get('features')->getChildrenValues())->toJson()); |
|
133
|
|
|
}); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function buildForm() |
|
137
|
|
|
{ |
|
138
|
|
|
$this |
|
139
|
|
|
->setAttr(['class' => 'submit-form', 'v-cloak' => 'v-cloak']) |
|
140
|
|
|
->setUrl(route('job.submit')) |
|
141
|
|
|
->add('id', 'hidden') |
|
142
|
|
|
->add('slug', 'hidden') |
|
143
|
|
|
->add('firm_id', 'hidden') |
|
144
|
|
|
->add('title', 'text', [ |
|
145
|
|
|
'rules' => 'min:2|max:60', |
|
146
|
|
|
'label' => 'Tytuł oferty', |
|
147
|
|
|
'required' => true, |
|
148
|
|
|
'help' => 'Pozostało <strong>${ charCounter(\'job.title\', 60) }</strong> znaków', |
|
149
|
|
|
'attr' => [ |
|
150
|
|
|
'placeholder' => 'Np. Senior Java Developer', |
|
151
|
|
|
'maxlength' => 60, |
|
152
|
|
|
'v-model' => 'job.title' |
|
153
|
|
|
], |
|
154
|
|
|
'row_attr' => [ |
|
155
|
|
|
'class' => 'col-sm-9' |
|
156
|
|
|
] |
|
157
|
|
|
]) |
|
158
|
|
|
->add('seniority_id', 'select', [ |
|
159
|
|
|
'rules' => 'integer', |
|
160
|
|
|
'label' => 'Staż pracy', |
|
161
|
|
|
'choices' => Job::getSeniorityList(), |
|
162
|
|
|
'empty_value' => '--', |
|
163
|
|
|
'row_attr' => [ |
|
164
|
|
|
'class' => 'col-sm-2' |
|
165
|
|
|
] |
|
166
|
|
|
]) |
|
167
|
|
|
->add('country_id', 'select', [ |
|
168
|
|
|
'rules' => 'required|integer', |
|
169
|
|
|
'choices' => Country::getCountriesList() |
|
170
|
|
|
]) |
|
171
|
|
|
->add('city', 'text', [ |
|
172
|
|
|
'rules' => 'string|city', |
|
173
|
|
|
'attr' => [ |
|
174
|
|
|
'placeholder' => 'Np. Wrocław, Warszawa' |
|
175
|
|
|
] |
|
176
|
|
|
]) |
|
177
|
|
|
->add('is_remote', 'checkbox', [ |
|
178
|
|
|
'label' => 'Możliwa praca zdalna w zakresie', |
|
179
|
|
|
'rules' => 'bool', |
|
180
|
|
|
'attr' => [ |
|
181
|
|
|
'id' => 'remote' |
|
182
|
|
|
], |
|
183
|
|
|
'label_attr' => [ |
|
184
|
|
|
'for' => 'remote' |
|
185
|
|
|
] |
|
186
|
|
|
]) |
|
187
|
|
|
->add('remote_range', 'select', [ |
|
188
|
|
|
'rules' => 'integer|min:10|max:100', |
|
189
|
|
|
'choices' => Job::getRemoteRangeList(), |
|
190
|
|
|
'attr' => [ |
|
191
|
|
|
'placeholder' => '--', |
|
192
|
|
|
'class' => 'input-sm input-inline', |
|
193
|
|
|
'style' => 'width: 100px' |
|
194
|
|
|
] |
|
195
|
|
|
]) |
|
196
|
|
|
->add('salary_from', 'text', [ |
|
197
|
|
|
'rules' => 'integer', |
|
198
|
|
|
'help' => 'Podanie tych informacji nie jest obowiązkowe, ale dzięki temu Twoja oferta zainteresuje więcej osób. Obiecujemy!', |
|
199
|
|
|
'attr' => [ |
|
200
|
|
|
'class' => 'input-inline' |
|
201
|
|
|
] |
|
202
|
|
|
]) |
|
203
|
|
|
->add('salary_to', 'text', [ |
|
204
|
|
|
'rules' => 'integer', |
|
205
|
|
|
'attr' => [ |
|
206
|
|
|
'class' => 'input-inline' |
|
207
|
|
|
] |
|
208
|
|
|
]) |
|
209
|
|
|
->add('is_gross', 'select', [ |
|
210
|
|
|
'rules' => 'required|boolean', |
|
211
|
|
|
'choices' => Job::getTaxList(), |
|
212
|
|
|
'attr' => [ |
|
213
|
|
|
'class' => 'input-inline' |
|
214
|
|
|
] |
|
215
|
|
|
]) |
|
216
|
|
|
->add('currency_id', 'select', [ |
|
217
|
|
|
'rules' => 'required|integer', |
|
218
|
|
|
'choices' => Currency::getCurrenciesList(), |
|
219
|
|
|
'attr' => [ |
|
220
|
|
|
'class' => 'input-inline' |
|
221
|
|
|
] |
|
222
|
|
|
]) |
|
223
|
|
|
->add('rate_id', 'select', [ |
|
224
|
|
|
'rules' => 'required|integer', |
|
225
|
|
|
'choices' => Job::getRatesList(), |
|
226
|
|
|
'attr' => [ |
|
227
|
|
|
'class' => 'input-inline' |
|
228
|
|
|
] |
|
229
|
|
|
]) |
|
230
|
|
|
->add('employment_id', 'select', [ |
|
231
|
|
|
'rules' => 'required|integer', |
|
232
|
|
|
'choices' => Job::getEmploymentList(), |
|
233
|
|
|
'attr' => [ |
|
234
|
|
|
'class' => 'input-inline' |
|
235
|
|
|
] |
|
236
|
|
|
]) |
|
237
|
|
|
->add('deadline', 'number', [ |
|
238
|
|
|
'label' => 'Data ważnosci oferty', |
|
239
|
|
|
'rules' => 'integer|min:1|max:365', |
|
240
|
|
|
'help' => 'Oferta będzie widoczna na stronie do dnia <strong>${ deadlineDate }</strong>', |
|
241
|
|
|
'attr' => [ |
|
242
|
|
|
'min' => 1, |
|
243
|
|
|
'max' => 365, |
|
244
|
|
|
'class' => 'input-inline', |
|
245
|
|
|
'v-model' => 'job.deadline' |
|
246
|
|
|
] |
|
247
|
|
|
]) |
|
248
|
|
|
->add('tags', 'collection', [ |
|
249
|
|
|
'child_attr' => [ |
|
250
|
|
|
'type' => 'child_form', |
|
251
|
|
|
'class' => TagsForm::class |
|
252
|
|
|
] |
|
253
|
|
|
]) |
|
254
|
|
|
->add('features', 'collection', [ |
|
255
|
|
|
'label' => 'Narzędzia oraz metodologia pracy', |
|
256
|
|
|
'help' => 'Zaznaczenie tych pól nie jest obowiązkowe, jednak wpływaja one na pozycję oferty na liście wyszukiwania.', |
|
257
|
|
|
'child_attr' => [ |
|
258
|
|
|
'type' => 'child_form', |
|
259
|
|
|
'class' => FeaturesForm::class |
|
260
|
|
|
] |
|
261
|
|
|
]) |
|
262
|
|
|
->add('description', 'textarea', [ |
|
263
|
|
|
'label' => 'Opis oferty (opcjonalnie)', |
|
264
|
|
|
'help' => 'Miejsce na szczegółowy opis oferty. Pole to jednak nie jest wymagane.', |
|
265
|
|
|
'style' => 'height: 140px', |
|
266
|
|
|
'row_attr' => [ |
|
267
|
|
|
'class' => 'form-group-border' |
|
268
|
|
|
] |
|
269
|
|
|
]) |
|
270
|
|
|
->add('enable_apply', 'choice', [ |
|
271
|
|
|
'multiple' => false, |
|
272
|
|
|
'choices' => [ |
|
273
|
|
|
|
|
274
|
|
|
true => 'Zezwól na wysyłanie CV poprzez serwis 4programmers.net', |
|
275
|
|
|
false => '...lub podaj informacje w jaki sposób kandydaci mogą aplikować na to stanowisko', |
|
276
|
|
|
] |
|
277
|
|
|
]) |
|
278
|
|
|
->add('recruitment', 'textarea', [ |
|
279
|
|
|
'rules' => 'required_if:enable_apply,0|string', |
|
280
|
|
|
'style' => 'height: 40px' |
|
281
|
|
|
]) |
|
282
|
|
|
->add('email', 'email', [ |
|
283
|
|
|
'rules' => 'sometimes|required|email', |
|
284
|
|
|
'help' => 'Podaj adres e-mail na jaki wyślemy Ci informacje o kandydatach. Adres e-mail nie będzie widoczny dla osób postronnych.' |
|
285
|
|
|
]); |
|
286
|
|
|
|
|
287
|
|
|
$this->setupPlanFields(); |
|
288
|
|
|
$this->setupDefaultValues(); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
protected function setupDefaultValues() |
|
292
|
|
|
{ |
|
293
|
|
|
// default attributes only if model does not exist and wasn't filled before. |
|
294
|
|
|
if (!$this->data->exists && !$this->data->isDirty(['title']) && !$this->isSubmitted()) { |
|
295
|
|
|
$this->get('email')->setValue($this->request->user()->email); |
|
296
|
|
|
|
|
297
|
|
|
// @todo Uzyc mechanizmu geolokalizacji |
|
298
|
|
|
$this->get('country_id')->setValue(array_search('Polska', $this->get('country_id')->getChoices())); |
|
|
|
|
|
|
299
|
|
|
$this->get('remote_range')->setValue(100); |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
protected function setupPlanFields() |
|
304
|
|
|
{ |
|
305
|
|
|
// can't show that fields if plan is enabled |
|
306
|
|
|
if ($this->data->isPlanOngoing()) { |
|
307
|
|
|
return; |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
$this |
|
311
|
|
|
->add('plan_id', 'hidden', [ |
|
312
|
|
|
'rules' => [ |
|
313
|
|
|
'required', |
|
314
|
|
|
'int', |
|
315
|
|
|
Rule::exists('plans', 'id')->where('is_active', 1) |
|
316
|
|
|
], |
|
317
|
|
|
'attr' => [ |
|
318
|
|
|
'id' => 'plan_id', |
|
319
|
|
|
'v-model' => 'job.plan_id' |
|
320
|
|
|
] |
|
321
|
|
|
]); |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* @param string $city |
|
326
|
|
|
* @return array |
|
327
|
|
|
*/ |
|
328
|
|
|
private function geocode($city) |
|
329
|
|
|
{ |
|
330
|
|
|
$location = [ |
|
331
|
|
|
'city' => $city |
|
332
|
|
|
]; |
|
333
|
|
|
|
|
334
|
|
|
try { |
|
335
|
|
|
$location = $this->geocoder->geocode($city); |
|
336
|
|
|
|
|
337
|
|
|
if (!$location->city) { |
|
338
|
|
|
$location->city = $city; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
$location = $location->toArray(); |
|
342
|
|
|
} catch (\Exception $e) { |
|
343
|
|
|
logger()->error($e->getMessage()); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
return $location; |
|
347
|
|
|
} |
|
348
|
|
|
} |
|
349
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.