mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
gamify reputation added
This commit is contained in:
39
app/Console/Commands/Database/SetReputation.php
Normal file
39
app/Console/Commands/Database/SetReputation.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Database;
|
||||||
|
|
||||||
|
use App\Gamify\Points\BookCaseOrangePilled;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class SetReputation extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'reputation:set';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Command description';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
foreach (User::query()
|
||||||
|
->with(['orangePills'])
|
||||||
|
->get() as $item) {
|
||||||
|
foreach ($item->orangePills as $orangePill) {
|
||||||
|
$orangePill->user->givePoint(new BookCaseOrangePilled($orangePill));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Gamify/Points/BookCaseOrangePilled.php
Normal file
37
app/Gamify/Points/BookCaseOrangePilled.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Gamify\Points;
|
||||||
|
|
||||||
|
use QCod\Gamify\PointType;
|
||||||
|
|
||||||
|
class BookCaseOrangePilled extends PointType
|
||||||
|
{
|
||||||
|
public $allowDuplicates = false;
|
||||||
|
|
||||||
|
protected $payee = 'user';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of points
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $points = 210;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Point constructor
|
||||||
|
*
|
||||||
|
* @param $subject
|
||||||
|
*/
|
||||||
|
public function __construct($subject)
|
||||||
|
{
|
||||||
|
$this->subject = $subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User who will be receive points
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function payee()
|
||||||
|
{
|
||||||
|
return $this->getSubject()->user;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Gamify/Points/LoggedIn.php
Normal file
35
app/Gamify/Points/LoggedIn.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Gamify\Points;
|
||||||
|
|
||||||
|
use QCod\Gamify\PointType;
|
||||||
|
|
||||||
|
class LoggedIn extends PointType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Number of points
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $points = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Point constructor
|
||||||
|
*
|
||||||
|
* @param $subject
|
||||||
|
*/
|
||||||
|
public function __construct($subject)
|
||||||
|
{
|
||||||
|
$this->subject = $subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User who will be receive points
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function payee()
|
||||||
|
{
|
||||||
|
return $this->getSubject();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Livewire\Auth;
|
namespace App\Http\Livewire\Auth;
|
||||||
|
|
||||||
|
use App\Gamify\Points\LoggedIn;
|
||||||
use App\Models\LoginKey;
|
use App\Models\LoginKey;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\ModelCreatedNotification;
|
use App\Notifications\ModelCreatedNotification;
|
||||||
|
|||||||
29
app/Listeners/AddLoginReputation.php
Normal file
29
app/Listeners/AddLoginReputation.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Gamify\Points\LoggedIn;
|
||||||
|
|
||||||
|
class AddLoginReputation
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param object $event
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
$event->user->givePoint(new LoggedIn($event->user));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Gamify\Points\BookCaseOrangePilled;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@@ -27,6 +28,13 @@ class OrangePill extends Model
|
|||||||
'date' => 'datetime',
|
'date' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected static function booted()
|
||||||
|
{
|
||||||
|
static::creating(function ($model) {
|
||||||
|
$model->user->givePoint(new BookCaseOrangePilled($model));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function user(): BelongsTo
|
public function user(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Listeners\AddLoginReputation;
|
||||||
use App\Observers\EpisodeObserver;
|
use App\Observers\EpisodeObserver;
|
||||||
|
use Illuminate\Auth\Events\Login;
|
||||||
use Illuminate\Auth\Events\Registered;
|
use Illuminate\Auth\Events\Registered;
|
||||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
@@ -14,6 +16,9 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
* @var array<class-string, array<int, class-string>>
|
* @var array<class-string, array<int, class-string>>
|
||||||
*/
|
*/
|
||||||
protected $listen = [
|
protected $listen = [
|
||||||
|
Login::class => [
|
||||||
|
AddLoginReputation::class,
|
||||||
|
],
|
||||||
Registered::class => [
|
Registered::class => [
|
||||||
SendEmailVerificationNotification::class,
|
SendEmailVerificationNotification::class,
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user