@@ -26,10 +26,17 @@ final class InvestmentGeography
|
||||
});
|
||||
}
|
||||
|
||||
public function references(bool $management = false): Builder
|
||||
{
|
||||
return $management
|
||||
? DB::table('geo_locations')->whereNull('deleted_at')->whereIn('data_classification', ['public', 'internal'])
|
||||
: $this->publicReferences();
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $input
|
||||
* @return list<\stdClass>
|
||||
*/
|
||||
public function selection(array $input): array
|
||||
public function selection(array $input, bool $management = false): array
|
||||
{
|
||||
$path = [];
|
||||
$parent = null;
|
||||
@@ -40,7 +47,7 @@ final class InvestmentGeography
|
||||
|
||||
continue;
|
||||
}
|
||||
$node = $this->publicReferences()->where('id', $input[$field])->where('location_type', $type)->first(['id', 'name', 'parent_id', 'location_type']);
|
||||
$node = $this->references($management)->where('id', $input[$field])->where('location_type', $type)->first(['id', 'name', 'parent_id', 'location_type']);
|
||||
if ($gap || ! $node || ($parent && $node->parent_id !== $parent)) {
|
||||
throw ValidationException::withMessages([$field => 'Seleccione a localização dentro da hierarquia indicada.']);
|
||||
}
|
||||
@@ -64,11 +71,12 @@ final class InvestmentGeography
|
||||
}
|
||||
|
||||
/** @return list<\stdClass> */
|
||||
public function path(?string $id): array
|
||||
public function path(?string $id, bool $management = false): array
|
||||
{
|
||||
$path = [];
|
||||
for ($i = 0; $id && $i < 5; $i++) {
|
||||
$node = $this->publicReferences()->where('id', $id)->first(['id', 'name', 'parent_id', 'location_type']);
|
||||
$query = $management ? DB::table('geo_locations') : $this->publicReferences();
|
||||
$node = $query->where('id', $id)->first(['id', 'name', 'parent_id', 'location_type', 'deleted_at']);
|
||||
if (! $node) {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user