--- /dev/null
+<?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');
+ }
+
+}
--- /dev/null
+<?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'
+ ];
+
+
+}
+++ /dev/null
-<?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'];
-
-}
+++ /dev/null
-<?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 [];
- }
-}
+++ /dev/null
-<?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',
- ];
-
-}
+++ /dev/null
-<?php
-
-namespace App\Models\Slugs;
-
-use A17\Twill\Models\Model;
-
-class OrganizationSlug extends Model
-{
- protected $table = "organization_slugs";
-}
--- /dev/null
+<?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);
+ }
+
+}
--- /dev/null
+<?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');
+ }
+}
+
+
--- /dev/null
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class SearchableText extends Model
+{
+ use BelongsToPdfFile;
+}
--- /dev/null
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class TrackedLink extends Model
+{
+ use BelongsToPdfFile;
+}
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
protected $casts = [
'email_verified_at' => 'datetime',
];
+
+
+ /**
+ * @return BelongsTo
+ */
+ public function organization(): BelongsTo
+ {
+ return $this->belongsTo(Organization::class);
+ }
+
+
}
+++ /dev/null
-<?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');
- }
-}
--- /dev/null
+<?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');
+ }
+}
--- /dev/null
+<?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');
+ }
+}
--- /dev/null
+<?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');
+ }
+}
--- /dev/null
+<?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');
+ }
+}
--- /dev/null
+<?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');
+ }
+}
--- /dev/null
+<?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) {
+ //
+ });
+ }
+}
+++ /dev/null
-@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
Route::module('users');
-Route::module('organizations');