Phase 4 work order profile depth
This commit is contained in:
@@ -71,8 +71,11 @@ class ProviderProfileController extends Controller
|
||||
'bio' => ['nullable', 'string'],
|
||||
'service_area' => ['nullable', 'string', 'max:255'],
|
||||
'skills' => ['nullable', 'string'],
|
||||
'services_text' => ['nullable', 'string'],
|
||||
'tools' => ['nullable', 'string'],
|
||||
'tool_inventory_text' => ['nullable', 'string'],
|
||||
'certifications' => ['nullable', 'string'],
|
||||
'certification_records_text' => ['nullable', 'string'],
|
||||
'insurance_status' => ['nullable', 'string', 'max:255'],
|
||||
'rate_card' => ['nullable', 'string'],
|
||||
'travel_policy' => ['nullable', 'string'],
|
||||
@@ -80,9 +83,19 @@ class ProviderProfileController extends Controller
|
||||
'website_url' => ['nullable', 'url', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:255'],
|
||||
'public_contact' => ['nullable', 'boolean'],
|
||||
'profile_visibility' => ['nullable', 'array'],
|
||||
'profile_visibility.*' => ['nullable', 'boolean'],
|
||||
'private_notes' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
$data['public_contact'] = $request->boolean('public_contact');
|
||||
$data['services'] = $this->linesToRecords($data['services_text'] ?? '', ['name', 'level']);
|
||||
$data['tool_inventory'] = $this->linesToRecords($data['tool_inventory_text'] ?? '', ['name', 'category']);
|
||||
$data['certification_records'] = $this->linesToRecords($data['certification_records_text'] ?? '', ['name', 'issuer']);
|
||||
$data['profile_visibility'] = $this->normalizeVisibility($request, [
|
||||
'bio', 'services', 'tools', 'certifications', 'rate_card', 'availability', 'imports',
|
||||
]);
|
||||
unset($data['services_text'], $data['tool_inventory_text'], $data['certification_records_text']);
|
||||
|
||||
$request->user()->providerProfile()->updateOrCreate(
|
||||
['user_id' => $request->user()->id],
|
||||
@@ -98,4 +111,21 @@ class ProviderProfileController extends Controller
|
||||
'profile' => $provider->load('user', 'externalImports.attachments', 'attachments', 'ratings.user'),
|
||||
]);
|
||||
}
|
||||
|
||||
private function linesToRecords(string $text, array $keys): array
|
||||
{
|
||||
return collect(preg_split('/\r\n|\r|\n/', $text))
|
||||
->map(fn (string $line): array => array_pad(array_map('trim', explode('|', $line, count($keys))), count($keys), null))
|
||||
->filter(fn (array $parts): bool => (bool) ($parts[0] ?? null))
|
||||
->map(fn (array $parts): array => collect($keys)->mapWithKeys(fn (string $key, int $index): array => [$key => $parts[$index] ?? null])->all())
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
private function normalizeVisibility(Request $request, array $fields): array
|
||||
{
|
||||
return collect($fields)
|
||||
->mapWithKeys(fn (string $field): array => [$field => $request->boolean("profile_visibility.$field")])
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user