]> _ Git - psq.git/commitdiff
unique addresse for organsiations
authorLouis Jeckel <louis.jeckel@outlook.com>
Wed, 28 Jul 2021 21:45:27 +0000 (23:45 +0200)
committerLouis Jeckel <louis.jeckel@outlook.com>
Wed, 28 Jul 2021 21:45:27 +0000 (23:45 +0200)
app/HasPlace.php
app/Helpers/Helpers.php
app/Nova/Actions/ExportUsersToExcel.php
app/Nova/User.php
app/User.php

index 91a9d4d4954dc849ace90cc22fa0c250f60e059d..450aab9f4e7271a22ed27ee56b1cb4f783101e94 100644 (file)
@@ -16,10 +16,10 @@ trait HasPlace
     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,
         ];
     }
 }
index da3be1f7c1f82b6a6f8be53e80d2dece2701c26e..315c1a4f14dde2e540d9967be448f394014743b5 100644 (file)
@@ -26,4 +26,17 @@ class Helpers
         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']}";
+    }
+
 }
index 07d74b772773427b0b404cd060d19d10c05d033f..597cae15af0f6338200af79955b47b6773ce6759 100644 (file)
@@ -27,15 +27,12 @@ class ExportUsersToExcel extends DownloadExcel implements WithMapping, WithHeadi
      */
     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,
index 49b7336bdd600a46a125cb13d5534d9e08cb4d04..974ee7fb8f8c88e4ca407cf0cceb312531a1b61d 100644 (file)
@@ -92,8 +92,9 @@ class User extends Resource
             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é',
index 5d8b9dc37eb13010c807f2d445f97d84c94e4fed..139fdee5349c45ae934d247f102acf2fe6f7c043 100644 (file)
@@ -3,7 +3,7 @@
 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;
@@ -35,6 +35,8 @@ use Laravel\Scout\Searchable;
  * @property bool $unsubscribed
  * @property bool $reg_complete
  * @property bool $receives_pdf
+ * @property array $computed_place
+ * @property boolean $inherits_address
  *
  * @property string $status
  */
@@ -652,10 +654,28 @@ class User extends Authenticatable implements MustVerifyEmail, SendsEmails
 
     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());
     }
 
     /**