]> _ Git - psq.git/commitdiff
unique addresse for organsiations
authorLouis Jeckel <louis.jeckel@outlook.com>
Wed, 14 Jul 2021 16:33:17 +0000 (18:33 +0200)
committerLouis Jeckel <louis.jeckel@outlook.com>
Wed, 14 Jul 2021 16:33:17 +0000 (18:33 +0200)
app/HasPlace.php [new file with mode: 0644]
app/Nova/Actions/ExportUsersToExcel.php
app/Nova/Organization.php
app/Organization.php
app/User.php
database/migrations/2021_07_14_161651_add_unqiue_address_to_organizations.php [new file with mode: 0644]

diff --git a/app/HasPlace.php b/app/HasPlace.php
new file mode 100644 (file)
index 0000000..91a9d4d
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+
+namespace App;
+
+/**
+ * Trait HasPlace
+ * @package App
+ * @property string address_line_1
+ * @property string city
+ * @property string postal_code
+ * @property string country
+ */
+trait HasPlace
+{
+    public function place(): array
+    {
+        return [
+            $this->address_line_1,
+            $this->city,
+            $this->postal_code,
+            $this->country,
+        ];
+    }
+}
index 8da02ca2ab45ee8aaa2052810a96ea389a779e3f..07d74b772773427b0b404cd060d19d10c05d033f 100644 (file)
@@ -27,21 +27,19 @@ class ExportUsersToExcel extends DownloadExcel implements WithMapping, WithHeadi
      */
     public function map($user): array
     {
-        return [
+        $place = $user->organization !== null && $user->organization->unique_address ?
+            $user->organization->place() :
+            $user->place();
+
+        return array_merge([
             $user->first_name,
             $user->last_name,
-            $user->email,
-            $user->address_line_1,
-            $user->city,
-            $user->postal_code,
-            $user->country,
+            $user->email
+        ], $place, [
             $user->phone,
-            (string) $user->organization,
+            $user->organization_str ?? (string) $user->organization,
             $user->position,
-
-
-
-        ];
+        ]);
     }
 
     public function headings(): array
index 93f48eb0bb1c19a12173911b529fbaf892c73554..dd0cf07b897331ee3660dd5da1a43d34b1221a80 100644 (file)
@@ -11,10 +11,13 @@ use App\Nova\Filters\TypeFilter;
 use Illuminate\Http\Request;
 use Laravel\Nova\Fields\BelongsTo;
 use Laravel\Nova\Fields\Boolean;
+use Laravel\Nova\Fields\Country;
 use Laravel\Nova\Fields\HasMany;
 use Laravel\Nova\Fields\ID;
+use Laravel\Nova\Fields\Place;
 use Laravel\Nova\Fields\Text;
 use Laravel\Nova\Http\Requests\NovaRequest;
+use Laravel\Nova\Panel;
 
 class Organization extends Resource
 {
@@ -59,14 +62,31 @@ class Organization extends Resource
     public function fields(Request $request)
     {
         return [
-//            ID::make()->sortable(),
             Text::make('Nom', 'name'),
+            new Panel('Adresse', $this->addressFields()),
             HasMany::make('Membres', 'members', User::class),
             BelongsTo::make('Type', 'type', OrganizationType::class),
+            Boolean::make('Adresse unique', 'unique_address'),
 
         ];
     }
 
+
+        /**
+     * Get the address fields for the resource.
+     *
+     *
+     */
+    protected function addressFields()
+    {
+        return [
+            Place::make('Adresse', 'address_line_1')->hideFromIndex(),
+            Text::make('Ville', 'city')->hideFromIndex(),
+            Text::make('Code Postal', 'postal_code')->hideFromIndex(),
+            Country::make('Pays', 'country')->hideFromIndex(),
+        ];
+    }
+
     /**
      * Get the cards available for the request.
      *
index 51035adee41e49d9b07947bf4762f214b8b3c9f5..0ca58a79a36693dad843286e3b8d7ebc24c5475f 100644 (file)
@@ -13,11 +13,13 @@ use Laravel\Scout\Searchable;
  * @package App
  * @property string name
  * @property boolean $subscription_active
+ * @property boolean $unique_address
  */
 class Organization extends Model implements SendsEmails
 {
 
     use Searchable;
+    use HasPlace;
 
     protected $casts = [
     ];
index 1f93c6efc3cb686bd781c135caa29be64eef59a2..5d8b9dc37eb13010c807f2d445f97d84c94e4fed 100644 (file)
@@ -44,6 +44,7 @@ class User extends Authenticatable implements MustVerifyEmail, SendsEmails
     use Searchable;
     use Billable;
     use TemplateVariables;
+    use HasPlace;
 
     /**
      * The attributes that are mass assignable.
diff --git a/database/migrations/2021_07_14_161651_add_unqiue_address_to_organizations.php b/database/migrations/2021_07_14_161651_add_unqiue_address_to_organizations.php
new file mode 100644 (file)
index 0000000..5fd5a22
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddUnqiueAddressToOrganizations extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('organizations', function (Blueprint $table) {
+            $table->boolean('unique_address')->default(0);
+            $table->string('address_line_1')->nullable();
+            $table->string('city')->nullable();
+            $table->string('postal_code')->nullable();
+            $table->string('country')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('organizations', function (Blueprint $table) {
+            $table->dropColumn('unique_address');
+            $table->dropColumn('address_line_1');
+            $table->dropColumn('city');
+            $table->dropColumn('postal_code');
+            $table->dropColumn('country');
+        });
+    }
+}