]> _ Git - psq.git/commitdiff
downloadable url
authorLouis Jeckel <louis.jeckel@outlook.cm>
Fri, 18 Sep 2020 09:45:28 +0000 (11:45 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Fri, 18 Sep 2020 09:45:28 +0000 (11:45 +0200)
app/Nova/User.php
app/PdfFile.php
app/User.php
database/migrations/2020_09_18_093346_add_receives_pdf_col_to_users.php [new file with mode: 0644]

index b6d0bf6f5405cb3dbfead8e9fa0b281e910cc8b4..c89f575387912188fd7f9c9b666a3360276cd225 100644 (file)
@@ -80,17 +80,21 @@ class User extends Resource
             Text::make('Position'),
             Text::make('Téléphone', 'phone'),
             new Panel('Adresse', $this->addressFields()),
+            new Panel('Réglages', [
+                Select::make('Type')->options([
+                    AppUser::TYPE_SUBSCRIBER => 'Abonné',
+                    AppUser::TYPE_PROSPECT => 'Prospect',
+                    AppUser::TYPE_SPECIAL => 'Autre',
+                    AppUser::TYPE_DISCOVER => 'Découverte',
+                ])->hideFromIndex()->required()->withMeta(['value' => $this->type ?? static::$type ?? AppUser::TYPE_SUBSCRIBER]),
+                Boolean::make('Compte activé', 'reg_complete')->hideWhenCreating()->hideWhenUpdating()->readonly(),
+                Boolean::make('Reçoit fichier PDF', 'receives_pdf')->hideFromIndex(),
+
+            ]),
             new Panel('Affiliation', [
                 BelongsTo::make('Organisation', 'organization', Organization::class)->searchable()->nullable(),
             ]),
-            ], $this->extraFields(), [
-            Boolean::make('Compte activé', 'reg_complete')->hideWhenCreating(),
-            Select::make('Type')->options([
-                AppUser::TYPE_SUBSCRIBER => 'Abonné',
-                AppUser::TYPE_PROSPECT => 'Prospect',
-                AppUser::TYPE_SPECIAL => 'Autre',
-                AppUser::TYPE_DISCOVER => 'Découverte',
-            ])->hideFromIndex()->required()->withMeta(['value' => $this->type ?? static::$type ?? AppUser::TYPE_SUBSCRIBER]),
+        ], $this->extraFields(), [
             Badge::make('Etat', fn() => AppUser::STATUSES[$this->status]['label'])
                 ->map(Arr::pluck(AppUser::STATUSES, 'badge', 'label')),
         ]);
index 34487654ff895d71b2f36564fcfe9d4cb80bdcd3..22135c9b74b8d205e6b6f909ebd3fbbae01ecc3f 100644 (file)
@@ -368,12 +368,28 @@ class PdfFile extends TwillModel implements Sortable
         );
     }
 
+    /**
+     * @return string
+     * Returns download link.
+     */
+    public function getDownloadUrl(): string
+    {
+        return \URL::temporarySignedRoute(
+            'pdf.download',
+            now()->addDays(3),
+            ['file' => $this->slug]
+        );
+    }
+
     /**
      * @param User $user
      * @return string
      */
     public function getMailableUrl(User $user): string
     {
+        if($user->receives_pdf) {
+            return $this->getDownloadUrl();
+        }
         return ($user->type === User::TYPE_DISCOVER && !$user->self_registered) ?
             $this->getSignedUrl($user) :
             $this->getUrlWithToken($user);
index c9f0d26584cd81e0630fb19c930250c2329e3e1a..21df16fe85c20781774f60ec831bdaa8bee19e8f 100644 (file)
@@ -36,6 +36,7 @@ use Laravel\Scout\Searchable;
  * @property int $type
  * @property bool $unsubscribed
  * @property bool $reg_complete
+ * @property bool $receives_pdf
  *
  * @property string $status
  */
@@ -90,6 +91,7 @@ class User extends Authenticatable implements MustVerifyEmail
         'self_registered' => 'bool',
         'early_access' => 'bool',
         'unsubscribed' => 'bool',
+        'receives_pdf' => 'bool',
     ];
 
 
diff --git a/database/migrations/2020_09_18_093346_add_receives_pdf_col_to_users.php b/database/migrations/2020_09_18_093346_add_receives_pdf_col_to_users.php
new file mode 100644 (file)
index 0000000..b7b80c1
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddReceivesPdfColToUsers extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('users', function (Blueprint $table) {
+            $table->boolean('receives_pdf')->default(0);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('users', function (Blueprint $table) {
+            $table->dropColumn('receives_pdf');
+        });
+    }
+}