]> _ Git - psq.git/commitdiff
models & migrations v1
authorLouis <louis.jeckel@her-tools.fr>
Fri, 3 Apr 2020 16:42:26 +0000 (18:42 +0200)
committerLouis <louis.jeckel@her-tools.fr>
Fri, 3 Apr 2020 16:42:26 +0000 (18:42 +0200)
20 files changed:
app/BelongsToPdfFile.php [new file with mode: 0644]
app/EmailBatch.php [new file with mode: 0644]
app/Http/Controllers/Admin/OrganizationController.php [deleted file]
app/Http/Requests/Admin/OrganizationRequest.php [deleted file]
app/Models/Organization.php [deleted file]
app/Models/Slugs/OrganizationSlug.php [deleted file]
app/Organization.php [new file with mode: 0644]
app/PdfFile.php [new file with mode: 0644]
app/SearchableText.php [new file with mode: 0644]
app/TrackedLink.php [new file with mode: 0644]
app/User.php
database/migrations/2020_04_03_132717_create_organizations_tables.php [deleted file]
database/migrations/2020_04_03_154715_create_organizations_table.php [new file with mode: 0644]
database/migrations/2020_04_03_154810_create_flow_paper_files_table.php [new file with mode: 0644]
database/migrations/2020_04_03_154911_create_searchable_texts_table.php [new file with mode: 0644]
database/migrations/2020_04_03_154939_create_email_batches_table.php [new file with mode: 0644]
database/migrations/2020_04_03_155151_create_tracked_links_table.php [new file with mode: 0644]
database/migrations/2020_04_03_162854_add_columns_to_users_table.php [new file with mode: 0644]
resources/views/admin/organizations/form.blade.php [deleted file]
routes/admin.php

diff --git a/app/BelongsToPdfFile.php b/app/BelongsToPdfFile.php
new file mode 100644 (file)
index 0000000..3d47fd3
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+
+
+namespace App;
+
+/**
+ * Trait BelongsToPdfFile
+ * @package App
+ * @property-read PdfFile $file
+ */
+trait BelongsToPdfFile
+{
+
+    /**
+     * @return mixed
+     */
+    public function file()
+    {
+        return $this->belongsTo(PdfFile::class, 'file_id');
+    }
+
+}
diff --git a/app/EmailBatch.php b/app/EmailBatch.php
new file mode 100644 (file)
index 0000000..64ce5ad
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class EmailBatch
+ * @package App
+ * @property string $subject
+ * @property array $content
+ * @property array $sent_to
+ */
+class EmailBatch extends Model
+{
+    use BelongsToPdfFile;
+
+    protected $casts = [
+        'content' => 'array',
+        'sent_to' => 'array'
+    ];
+
+
+}
diff --git a/app/Http/Controllers/Admin/OrganizationController.php b/app/Http/Controllers/Admin/OrganizationController.php
deleted file mode 100644 (file)
index 1223539..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Admin;
-
-use A17\Twill\Http\Controllers\Admin\ModuleController;
-
-class OrganizationController extends ModuleController
-{
-    protected $moduleName = 'organizations';
-
-    protected $titleColumnKey = 'name';
-
-    protected $indexColumns = [
-        'name' => [
-            'title' => 'Nom',
-            'field' => 'name',
-        ],
-        'subscription_active' => [
-            'title' => 'Abonnement actif',
-            'field' => 'subscription_active'
-        ]
-    ];
-
-
-    protected $defaultOrders = ['created_at' => 'desc'];
-
-}
diff --git a/app/Http/Requests/Admin/OrganizationRequest.php b/app/Http/Requests/Admin/OrganizationRequest.php
deleted file mode 100644 (file)
index d5f1d4a..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-namespace App\Http\Requests\Admin;
-
-use A17\Twill\Http\Requests\Admin\Request;
-
-class OrganizationRequest extends Request
-{
-    public function rulesForCreate()
-    {
-        return [];
-    }
-
-    public function rulesForUpdate()
-    {
-        return [];
-    }
-}
diff --git a/app/Models/Organization.php b/app/Models/Organization.php
deleted file mode 100644 (file)
index 46b1b0a..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
-namespace App\Models;
-
-use A17\Twill\Models\Behaviors\HasSlug;
-use A17\Twill\Models\Model;
-
-class Organization extends Model
-{
-    use HasSlug;
-
-    protected $fillable = ['name', 'subscription_active'];
-
-    public $slugAttributes = [
-        'name',
-    ];
-
-    protected $casts = [
-        'subscription_active' => 'boolean',
-    ];
-
-}
diff --git a/app/Models/Slugs/OrganizationSlug.php b/app/Models/Slugs/OrganizationSlug.php
deleted file mode 100644 (file)
index 5cd1507..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-namespace App\Models\Slugs;
-
-use A17\Twill\Models\Model;
-
-class OrganizationSlug extends Model
-{
-    protected $table = "organization_slugs";
-}
diff --git a/app/Organization.php b/app/Organization.php
new file mode 100644 (file)
index 0000000..82b39f2
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\HasMany;
+
+/**
+ * Class Organization
+ * @package App
+ * @property string name
+ * @property boolean $subscription_active
+ */
+class Organization extends Model
+{
+    protected $casts = [
+        'subscription_active' => 'boolean'
+    ];
+
+
+    /**
+     * @return boolean
+     */
+    public function isSubscribed(): bool
+    {
+        return $this->subscription_active;
+    }
+
+    /**
+     * @param Builder $builder
+     * @return Builder
+     */
+    public function scopeSubscribed(Builder $builder): Builder
+    {
+        return $builder->where('subscription_active', 1);
+    }
+
+    /**
+     * @return HasMany
+     */
+    public function members(): HasMany
+    {
+        return $this->hasMany(User::class);
+    }
+
+}
diff --git a/app/PdfFile.php b/app/PdfFile.php
new file mode 100644 (file)
index 0000000..9811ef4
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\HasMany;
+use Illuminate\Database\Eloquent\Relations\HasOne;
+
+/**
+ * Class PdfFile
+ * @package App
+ * @property SearchableText $searchableTexts
+ * @property EmailBatch $emailBatch
+ * @property TrackedLink $trackedLinks
+ */
+class PdfFile extends Model
+{
+
+    /**
+     * @return HasMany
+     */
+    public function searchableTexts(): HasMany
+    {
+        return $this->hasMany(SearchableText::class, 'file_id');
+    }
+
+    /**
+     * @return HasOne
+     */
+    public function emailBatch(): HasOne
+    {
+        return $this->hasOne(EmailBatch::class, 'file_id');
+    }
+
+    /**
+     * @return HasMany
+     */
+    public function trackedLinks(): HasMany
+    {
+        return $this->hasMany(TrackedLink::class, 'file_id');
+    }
+}
+
+
diff --git a/app/SearchableText.php b/app/SearchableText.php
new file mode 100644 (file)
index 0000000..7496321
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class SearchableText extends Model
+{
+    use BelongsToPdfFile;
+}
diff --git a/app/TrackedLink.php b/app/TrackedLink.php
new file mode 100644 (file)
index 0000000..c27fefe
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class TrackedLink extends Model
+{
+    use BelongsToPdfFile;
+}
index e79dab7fea8f6601eaf07072ee6b12fbe20bdbe1..734876c8d4e07434fbfdc7c22917d7de77a65274 100644 (file)
@@ -3,6 +3,7 @@
 namespace App;
 
 use Illuminate\Contracts\Auth\MustVerifyEmail;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Foundation\Auth\User as Authenticatable;
 use Illuminate\Notifications\Notifiable;
 
@@ -36,4 +37,15 @@ class User extends Authenticatable
     protected $casts = [
         'email_verified_at' => 'datetime',
     ];
+
+
+    /**
+     * @return BelongsTo
+     */
+    public function organization(): BelongsTo
+    {
+        return $this->belongsTo(Organization::class);
+    }
+
+
 }
diff --git a/database/migrations/2020_04_03_132717_create_organizations_tables.php b/database/migrations/2020_04_03_132717_create_organizations_tables.php
deleted file mode 100644 (file)
index f204dab..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-
-class CreateOrganizationsTables extends Migration
-{
-    public function up()
-    {
-        Schema::create('organizations', function (Blueprint $table) {
-            // this will create an id, a "published" column, and soft delete and timestamps columns
-            createDefaultTableFields($table);
-
-            // feel free to modify the name of this column, but title is supported by default (you would need to specify the name of the column Twill should consider as your "title" column in your module controller if you change it)
-            $table->string('name', 200);
-
-            // your generated model and form include a description field, to get you started, but feel free to get rid of it if you don't need it
-            $table->text('description')->nullable();
-
-            $table->boolean('subscription_active');
-
-            // add those 2 columns to enable publication timeframe fields (you can use publish_start_date only if you don't need to provide the ability to specify an end date)
-            // $table->timestamp('publish_start_date')->nullable();
-            // $table->timestamp('publish_end_date')->nullable();
-        });
-
-        Schema::create('organization_slugs', function (Blueprint $table) {
-            createDefaultSlugsTableFields($table, 'organization');
-        });
-
-
-    }
-
-    public function down()
-    {
-
-        Schema::dropIfExists('organization_slugs');
-        Schema::dropIfExists('organizations');
-    }
-}
diff --git a/database/migrations/2020_04_03_154715_create_organizations_table.php b/database/migrations/2020_04_03_154715_create_organizations_table.php
new file mode 100644 (file)
index 0000000..92fe86a
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateOrganizationsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('organizations', function (Blueprint $table) {
+            $table->id();
+            $table->string('name');
+            $table->boolean('subscription_active');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('organizations');
+    }
+}
diff --git a/database/migrations/2020_04_03_154810_create_flow_paper_files_table.php b/database/migrations/2020_04_03_154810_create_flow_paper_files_table.php
new file mode 100644 (file)
index 0000000..ddf64b1
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateFlowPaperFilesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('pdf_files', function (Blueprint $table) {
+            $table->id();
+            $table->string('slug')->unique();
+            $table->string('title');
+            $table->string('file_name');
+            $table->json('tags');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('pdf_files');
+    }
+}
diff --git a/database/migrations/2020_04_03_154911_create_searchable_texts_table.php b/database/migrations/2020_04_03_154911_create_searchable_texts_table.php
new file mode 100644 (file)
index 0000000..531dde7
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateSearchableTextsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('searchable_texts', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedBigInteger('file_id');
+            $table->text('content');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('searchable_texts');
+    }
+}
diff --git a/database/migrations/2020_04_03_154939_create_email_batches_table.php b/database/migrations/2020_04_03_154939_create_email_batches_table.php
new file mode 100644 (file)
index 0000000..7def44a
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateEmailBatchesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('email_batches', function (Blueprint $table) {
+            $table->id();
+            $table->string('subject');
+            $table->json('content');
+            $table->unsignedBigInteger('file_id');
+            $table->json('sent_to');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('email_batches');
+    }
+}
diff --git a/database/migrations/2020_04_03_155151_create_tracked_links_table.php b/database/migrations/2020_04_03_155151_create_tracked_links_table.php
new file mode 100644 (file)
index 0000000..fbbb79c
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateTrackedLinksTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('tracked_links', function (Blueprint $table) {
+            $table->id();
+            $table->string('slug');
+            $table->text('target');
+            $table->unsignedBigInteger('file_id')->nullable();
+            $table->unsignedBigInteger('clicks')->default(0);
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('tracked_links');
+    }
+}
diff --git a/database/migrations/2020_04_03_162854_add_columns_to_users_table.php b/database/migrations/2020_04_03_162854_add_columns_to_users_table.php
new file mode 100644 (file)
index 0000000..ac3ff1d
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddColumnsToUsersTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('users', function (Blueprint $table) {
+            $table->unsignedBigInteger('organization_id')->nullable();
+            $table->unsignedInteger('credits')->default(0);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('users', function (Blueprint $table) {
+            //
+        });
+    }
+}
diff --git a/resources/views/admin/organizations/form.blade.php b/resources/views/admin/organizations/form.blade.php
deleted file mode 100644 (file)
index 4eb6835..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-@extends('twill::layouts.form')
-
-@section('contentFields')
-
-    @formField('input', [
-        'name' => 'name',
-        'label' => 'Nom',
-        'maxlength' => 100
-    ])
-
-    @formField('radios', [
-        'name' => 'subscription_active',
-        'label' => 'Abonnement actif',
-        'default' => '1',
-        'inline' => true,
-        'options' => [
-            [
-                'value' => '0',
-                'label' => 'Non'
-            ],
-            [
-                'value' => '1',
-                'label' => 'Oui'
-            ],
-
-        ]
-    ])
-@stop
index ba7b53ec4a4d73cac8f3baa48dd23706f0c0d0a8..42d66a81f387c6da04ea5652913db68ed51b0706 100644 (file)
@@ -2,4 +2,3 @@
 
 
 Route::module('users');
-Route::module('organizations');