public function place(): array
{
return [
- $this->address_line_1,
- $this->city,
- $this->postal_code,
- $this->country,
+ 'address_line_1' => $this->address_line_1,
+ 'city' => $this->city,
+ 'postal_code' => $this->postal_code,
+ 'country' => $this->country,
];
}
}
return $line;
}
+
+ /**
+ * @param array $place
+ * @return string
+ */
+ public static function placeArrayToString(array $place): string
+ {
+ if(empty($place['address_line_1'])) {
+ return "";
+ }
+ return "{$place['address_line_1']}, {$place['postal_code']} {$place['city']} {$place['country']}";
+ }
+
}
*/
public function map($user): array
{
- $place = $user->organization !== null && $user->organization->unique_address ?
- $user->organization->place() :
- $user->place();
return array_merge([
$user->first_name,
$user->last_name,
$user->email
- ], $place, [
+ ], array_values($user->computed_place), [
$user->phone,
$user->organization_str ?? (string) $user->organization,
$user->position,
Text::make('Position'),
Text::make('Service'),
Text::make('Téléphone', 'phone'),
-
- new Panel('Adresse', $this->addressFields()),
+ Text::make('Adresse expédition', 'computedFullAddress')->readonly()->hideWhenCreating()->hideWhenUpdating(),
+ Boolean::make('Adresse héritée orga', 'inheritsAddress')->readonly()->hideWhenCreating()->hideWhenUpdating(),
+ new Panel('Adresse utilisateur', $this->addressFields()),
new Panel('Réglages', [
Select::make('Type')->options([
AppUser::TYPE_SUBSCRIBER => 'Abonné',
namespace App;
-use App\Notifications\EmailValidated;
+use App\Helpers\Helpers;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property bool $unsubscribed
* @property bool $reg_complete
* @property bool $receives_pdf
+ * @property array $computed_place
+ * @property boolean $inherits_address
*
* @property string $status
*/
public function getFullAddressAttribute(): string
{
- if(empty($this->address_line_1)) {
- return "";
- }
- return "$this->address_line_1, $this->postal_code $this->city $this->country";
+ return Helpers::placeArrayToString($this->place());
+ }
+
+ public function getInheritsAddressAttribute(): bool
+ {
+ return $this->organization !== null && $this->organization->unique_address;
+ }
+
+ /**
+ * @return array
+ * Returns either user or organization place array
+ */
+ public function getComputedPlaceAttribute(): array
+ {
+ return $this->inherits_address ?
+ $this->organization->place() :
+ $this->place();
+ }
+
+ public function getComputedFullAddressAttribute(): string
+ {
+ return Helpers::placeArrayToString($this->getComputedPlaceAttribute());
}
/**