From c75b3b56271d0715c587b49304bfa7589746bb35 Mon Sep 17 00:00:00 2001 From: Chris H Date: Thu, 4 Feb 2021 15:53:42 -0600 Subject: [PATCH 1/7] Add model class references. --- config/feedback.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config/feedback.php b/config/feedback.php index ca5d8ed..ea4703c 100644 --- a/config/feedback.php +++ b/config/feedback.php @@ -2,4 +2,13 @@ return [ + /** + * Model class references + */ + 'model_class' => [ + 'participant' => \App\Models\Participant::class, + + 'location' => \App\Models\Location::class, + ] + ]; From 1ea448348d3f68c63a4e33d69fb134556aec47d5 Mon Sep 17 00:00:00 2001 From: Chris H Date: Thu, 4 Feb 2021 16:01:04 -0600 Subject: [PATCH 2/7] Add migration & service provider hook. --- ..._11_130000_create_feedbacks_table.php.stub | 38 +++++++++++++++++++ src/FeedbackServiceProvider.php | 17 ++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2020_05_11_130000_create_feedbacks_table.php.stub diff --git a/database/migrations/2020_05_11_130000_create_feedbacks_table.php.stub b/database/migrations/2020_05_11_130000_create_feedbacks_table.php.stub new file mode 100644 index 0000000..7b28f72 --- /dev/null +++ b/database/migrations/2020_05_11_130000_create_feedbacks_table.php.stub @@ -0,0 +1,38 @@ +getTable(); + + $locationModel = config('feedback.model_class.location'); + $locationTable = (new $locationModel)->getTable(); + + $table->id(); + $table->string('token')->index()->unique(); // unique hash for the feedback so can use in links instead of the id + $table->foreignId('participant_id')->index()->references('id')->on($participantTable); + $table->foreignId('location_id')->index()->references('id')->on($locationTable); + $table->date('date')->index(); // date the escape room game was played + $table->dateTime('emailed_at')->nullable(); + $table->string('email_identifier')->nullable()->unique(); // "MessageID" from Postmark or email service needed to track opens since multiple feedbacks could exist and can't track opens to the participant + $table->dateTime('opened_at')->nullable(); + $table->dateTime('clicked_negative_at')->nullable(); + $table->dateTime('clicked_semi_negative_at')->nullable(); + $table->dateTime('clicked_semi_positive_at')->nullable(); + $table->dateTime('clicked_positive_at')->nullable(); + $table->dateTime('clicked_review_at')->nullable(); + $table->dateTime('redirected_at')->nullable(); + $table->text('message')->nullable(); + $table->dateTime('submitted_at')->nullable(); // message submitted datetime + $table->softDeletes(); // Soft delete if email bounces. Also need to soft delete the Participant & update the waiver signature. + $table->timestamps(); + }); + } +} diff --git a/src/FeedbackServiceProvider.php b/src/FeedbackServiceProvider.php index 6812cda..21c5b3a 100644 --- a/src/FeedbackServiceProvider.php +++ b/src/FeedbackServiceProvider.php @@ -19,7 +19,22 @@ public function configurePackage(Package $package): void ->name('feedback') ->hasConfigFile() ->hasViews() - ->hasMigration('create_feedback_table') + ->hasMigration('2020_05_11_130000_create_feedbacks_table') ->hasCommand(FeedbackCommand::class); } + + /** + * Using packageBooted lifecycle hooks to override the migration file name. + * We want to keep the old filename for now. + */ + public function packageBooted() + { + foreach ($this->package->migrationFileNames as $migrationFileName) { + if (! $this->migrationFileExists($migrationFileName)) { + $this->publishes([ + $this->package->basePath("/../database/migrations/{$migrationFileName}.php.stub") => database_path('migrations/' . Str::finish($migrationFileName, '.php')), + ], "{$this->package->name}-migrations"); + } + } + } } From cd1b263af1d356d2dfb236565c12349b92163224 Mon Sep 17 00:00:00 2001 From: Chris H Date: Thu, 4 Feb 2021 16:16:41 -0600 Subject: [PATCH 3/7] Add Feedback model & Feedback Factory. --- database/factories/FeedbackFactory.php | 125 +++++++++++++++++++++++++ src/Models/Feedback.php | 54 +++++++++++ 2 files changed, 179 insertions(+) create mode 100644 database/factories/FeedbackFactory.php create mode 100644 src/Models/Feedback.php diff --git a/database/factories/FeedbackFactory.php b/database/factories/FeedbackFactory.php new file mode 100644 index 0000000..bf6493f --- /dev/null +++ b/database/factories/FeedbackFactory.php @@ -0,0 +1,125 @@ +faker->dateTimeBetween('-1 months', 'now'); + if ($this->faker->boolean) { + $messagetext = $this->faker->sentences(5, true); + $submitted = $actiondate; + } else { + $messagetext = null; + $submitted = null; + } + + if ($this->faker->boolean) { + // Opened Email + $opened_at = $actiondate; + $clicked_negative_at = null; + $clicked_semi_negative_at = null; + $clicked_positive_at = null; + $clicked_semi_positive_at = null; + $clicked_review_at = null; + $redirected_at = null; + $message = null; + if ($this->faker->boolean) { + // Positive + if ($this->faker->boolean) { + // Positive + $opened_at = $actiondate; + $clicked_negative_at = null; + $clicked_semi_negative_at = null; + $clicked_positive_at = $actiondate; + $clicked_semi_positive_at = null; + $clicked_review_at = $actiondate; + $redirected_at = $actiondate; + $message = null; + $submitted_at = null; + } else { + // Semi Positive + $opened_at = $actiondate; + $clicked_negative_at = null; + $clicked_semi_negative_at = null; + $clicked_positive_at = null; + $clicked_semi_positive_at = $actiondate; + $clicked_review_at = null; + $redirected_at = null; + $message = $messagetext; + $submitted_at = $submitted; + } + } else { + // Negative + if ($this->faker->boolean) { + // Negative + $opened_at = $actiondate; + $clicked_negative_at = $actiondate; + $clicked_semi_negative_at = null; + $clicked_positive_at = null; + $clicked_semi_positive_at = null; + $clicked_review_at = null; + $redirected_at = null; + $message = $messagetext; + $submitted_at = $submitted; + } else { + // Semi Negative + $opened_at = $actiondate; + $clicked_negative_at = null; + $clicked_semi_negative_at = $actiondate; + $clicked_positive_at = null; + $clicked_semi_positive_at = null; + $clicked_review_at = null; + $redirected_at = null; + $message = $messagetext; + $submitted_at = $submitted; + } + } + } else { + // Not responded + $opened_at = null; + $clicked_negative_at = null; + $clicked_semi_negative_at = null; + $clicked_positive_at = null; + $clicked_semi_positive_at = null; + $clicked_review_at = null; + $redirected_at = null; + $message = null; + $submitted_at = null; + } + + return [ + 'participant_id' => randomOrCreate(config('waivers.model_class.participant'), 'participant_id'), + 'location_id' => randomOrCreate(config('waivers.model_class.location'), 'location_id'), + 'date' => $this->faker->date(), // Should be a day less than emailed_at + 'emailed_at' => $this->faker->dateTimeBetween('-3 months', '-1 months'), + 'email_identifier' => Str::random(100), + 'opened_at' => $opened_at, + 'clicked_negative_at' => $clicked_negative_at, + 'clicked_semi_negative_at' => $clicked_semi_negative_at, + 'clicked_semi_positive_at' => $clicked_semi_positive_at, + 'clicked_positive_at' => $clicked_positive_at, + 'clicked_review_at' => $clicked_review_at, + 'redirected_at' => $redirected_at, + 'message' => $message, + 'submitted_at' => $submitted_at, + ]; + } +} diff --git a/src/Models/Feedback.php b/src/Models/Feedback.php new file mode 100644 index 0000000..9815d26 --- /dev/null +++ b/src/Models/Feedback.php @@ -0,0 +1,54 @@ + 'datetime', + 'opened_at' => 'datetime', + 'clicked_negative_at' => 'datetime', + 'clicked_semi_negative_at' => 'datetime', + 'clicked_semi_positive_at' => 'datetime', + 'clicked_positive_at' => 'datetime', + 'redirected_at' => 'datetime', + 'clicked_review_at' => 'datetime', + 'submitted_at' => 'datetime', + 'date' => 'date', + ]; + + protected static function boot() + { + parent::boot(); + + static::creating(function ($feedback) { + if (empty($feedback->token)) { + $feedback->token = $feedback->location_id . 'L' . mt_rand(1000, 9999) . 'TGER' . mt_rand(1, 999999); + } + }); + } + + public function getRouteKeyName() + { + return 'token'; + } + + public function participant() + { + return $this->belongsTo(config('waivers.model_class.participant'), 'participant_id'); + } + + public function location() + { + return $this->belongsTo(config('waivers.model_class.location'), 'location_id'); + } +} From 580e654bef7e967dd065ee86904ba1ce769f37f6 Mon Sep 17 00:00:00 2001 From: chx2 Date: Thu, 4 Feb 2021 22:17:15 +0000 Subject: [PATCH 4/7] Fix styling --- src/Models/Feedback.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Models/Feedback.php b/src/Models/Feedback.php index 9815d26..998d1ad 100644 --- a/src/Models/Feedback.php +++ b/src/Models/Feedback.php @@ -4,7 +4,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; -use Tipoff\Support\Models\BaseModel; class Feedback extends Model { From 6997c63d57c37503aa0b79a5a27278fc34fc5cae Mon Sep 17 00:00:00 2001 From: Chris H Date: Thu, 4 Feb 2021 16:18:34 -0600 Subject: [PATCH 5/7] Add down method for feedback table. --- .../2020_05_11_130000_create_feedbacks_table.php.stub | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/database/migrations/2020_05_11_130000_create_feedbacks_table.php.stub b/database/migrations/2020_05_11_130000_create_feedbacks_table.php.stub index 7b28f72..d56151a 100644 --- a/database/migrations/2020_05_11_130000_create_feedbacks_table.php.stub +++ b/database/migrations/2020_05_11_130000_create_feedbacks_table.php.stub @@ -35,4 +35,9 @@ class CreateFeedbacksTable extends Migration $table->timestamps(); }); } + + public function down() + { + Schema::dropIfExists('feedbacks'); + } } From 544fc8a01c5c8ef06ebd8b34dda085f34c83420c Mon Sep 17 00:00:00 2001 From: Chris H Date: Thu, 4 Feb 2021 16:19:46 -0600 Subject: [PATCH 6/7] Extend use of the BaseModel class. --- src/Models/Feedback.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Models/Feedback.php b/src/Models/Feedback.php index 998d1ad..4e7a97e 100644 --- a/src/Models/Feedback.php +++ b/src/Models/Feedback.php @@ -4,8 +4,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; +use Tipoff\Support\Models\BaseModel; -class Feedback extends Model +class Feedback extends BaseModel { use HasFactory; use SoftDeletes; From 3e569a4a978f455295078b8369d992550b0cb40b Mon Sep 17 00:00:00 2001 From: Chris H Date: Thu, 4 Feb 2021 16:30:08 -0600 Subject: [PATCH 7/7] Call correct config file. --- database/factories/FeedbackFactory.php | 4 ++-- src/Models/Feedback.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/database/factories/FeedbackFactory.php b/database/factories/FeedbackFactory.php index bf6493f..a2669ce 100644 --- a/database/factories/FeedbackFactory.php +++ b/database/factories/FeedbackFactory.php @@ -106,8 +106,8 @@ public function definition() } return [ - 'participant_id' => randomOrCreate(config('waivers.model_class.participant'), 'participant_id'), - 'location_id' => randomOrCreate(config('waivers.model_class.location'), 'location_id'), + 'participant_id' => randomOrCreate(config('feedback.model_class.participant'), 'participant_id'), + 'location_id' => randomOrCreate(config('feedback.model_class.location'), 'location_id'), 'date' => $this->faker->date(), // Should be a day less than emailed_at 'emailed_at' => $this->faker->dateTimeBetween('-3 months', '-1 months'), 'email_identifier' => Str::random(100), diff --git a/src/Models/Feedback.php b/src/Models/Feedback.php index 4e7a97e..19a9e9d 100644 --- a/src/Models/Feedback.php +++ b/src/Models/Feedback.php @@ -44,11 +44,11 @@ public function getRouteKeyName() public function participant() { - return $this->belongsTo(config('waivers.model_class.participant'), 'participant_id'); + return $this->belongsTo(config('feedback.model_class.participant'), 'participant_id'); } public function location() { - return $this->belongsTo(config('waivers.model_class.location'), 'location_id'); + return $this->belongsTo(config('feedback.model_class.location'), 'location_id'); } }