diff --git a/app/Console/Commands/Database/SetReputation.php b/app/Console/Commands/Database/SetReputation.php new file mode 100644 index 00000000..da8855f4 --- /dev/null +++ b/app/Console/Commands/Database/SetReputation.php @@ -0,0 +1,39 @@ +with(['orangePills']) + ->get() as $item) { + foreach ($item->orangePills as $orangePill) { + $orangePill->user->givePoint(new BookCaseOrangePilled($orangePill)); + } + } + + return Command::SUCCESS; + } +} diff --git a/app/Gamify/Points/BookCaseOrangePilled.php b/app/Gamify/Points/BookCaseOrangePilled.php new file mode 100644 index 00000000..729e7b5c --- /dev/null +++ b/app/Gamify/Points/BookCaseOrangePilled.php @@ -0,0 +1,37 @@ +subject = $subject; + } + + /** + * User who will be receive points + * @return mixed + */ + public function payee() + { + return $this->getSubject()->user; + } +} diff --git a/app/Gamify/Points/LoggedIn.php b/app/Gamify/Points/LoggedIn.php new file mode 100644 index 00000000..4ab31f17 --- /dev/null +++ b/app/Gamify/Points/LoggedIn.php @@ -0,0 +1,35 @@ +subject = $subject; + } + + /** + * User who will be receive points + * + * @return mixed + */ + public function payee() + { + return $this->getSubject(); + } +} diff --git a/app/Http/Livewire/Auth/LNUrlAuth.php b/app/Http/Livewire/Auth/LNUrlAuth.php index b745282c..f949feb5 100644 --- a/app/Http/Livewire/Auth/LNUrlAuth.php +++ b/app/Http/Livewire/Auth/LNUrlAuth.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire\Auth; +use App\Gamify\Points\LoggedIn; use App\Models\LoginKey; use App\Models\User; use App\Notifications\ModelCreatedNotification; diff --git a/app/Listeners/AddLoginReputation.php b/app/Listeners/AddLoginReputation.php new file mode 100644 index 00000000..3a477e1e --- /dev/null +++ b/app/Listeners/AddLoginReputation.php @@ -0,0 +1,29 @@ +user->givePoint(new LoggedIn($event->user)); + } +} diff --git a/app/Models/OrangePill.php b/app/Models/OrangePill.php index 12085e66..d25468d4 100644 --- a/app/Models/OrangePill.php +++ b/app/Models/OrangePill.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Gamify\Points\BookCaseOrangePilled; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -27,6 +28,13 @@ class OrangePill extends Model 'date' => 'datetime', ]; + protected static function booted() + { + static::creating(function ($model) { + $model->user->givePoint(new BookCaseOrangePilled($model)); + }); + } + public function user(): BelongsTo { return $this->belongsTo(User::class); diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 388536dc..66920a3e 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,7 +2,9 @@ namespace App\Providers; +use App\Listeners\AddLoginReputation; use App\Observers\EpisodeObserver; +use Illuminate\Auth\Events\Login; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -14,6 +16,9 @@ class EventServiceProvider extends ServiceProvider * @var array> */ protected $listen = [ + Login::class => [ + AddLoginReputation::class, + ], Registered::class => [ SendEmailVerificationNotification::class, ],