diff --git a/app/Console/Commands/UpdateUserBestRepliesPoints.php b/app/Console/Commands/UpdateUserBestRepliesPoints.php new file mode 100644 index 00000000..93e031f1 --- /dev/null +++ b/app/Console/Commands/UpdateUserBestRepliesPoints.php @@ -0,0 +1,27 @@ +info('Updating users bests replies reputations...'); + + $resolvedThread = Thread::with('solutionReply')->resolved()->get(); + + foreach ($resolvedThread as $thread) { + givePoint(new BestReply($thread->solutionReply)); + } + + $this->info('All done!'); + } +} diff --git a/app/Console/Commands/UpdateUserCommentsPoints.php b/app/Console/Commands/UpdateUserCommentsPoints.php deleted file mode 100644 index 5172be86..00000000 --- a/app/Console/Commands/UpdateUserCommentsPoints.php +++ /dev/null @@ -1,42 +0,0 @@ -info('Updating users bests replies reputations...'); + + foreach (Reply::all() as $reply) { + givePoint(new ReplyCreated($reply->replyAble)); + } + + $this->info('All done!'); } } diff --git a/app/Gamify/Points/AddPhone.php b/app/Gamify/Points/AddPhone.php index a0126921..1309ca99 100644 --- a/app/Gamify/Points/AddPhone.php +++ b/app/Gamify/Points/AddPhone.php @@ -6,28 +6,13 @@ class AddPhone extends PointType { - /** - * Number of points. - * - * @var int - */ - public $points = 20; + public int $points = 5; - /** - * 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; diff --git a/app/Gamify/Points/AddSocialLinks.php b/app/Gamify/Points/AddSocialLinks.php index dce28aaa..3e29744d 100644 --- a/app/Gamify/Points/AddSocialLinks.php +++ b/app/Gamify/Points/AddSocialLinks.php @@ -6,28 +6,13 @@ class AddSocialLinks extends PointType { - /** - * Number of points. - * - * @var int - */ - public $points = 20; + public int $points = 6; - /** - * 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; diff --git a/app/Gamify/Points/BestReply.php b/app/Gamify/Points/BestReply.php index 6ebb3948..a9c729fd 100644 --- a/app/Gamify/Points/BestReply.php +++ b/app/Gamify/Points/BestReply.php @@ -6,30 +6,12 @@ class BestReply extends PointType { - /** - * Number of points. - * - * @var int - */ - public $points = 20; + public int $points = 10; + + protected string $payee = 'author'; - /** - * 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; - } } diff --git a/app/Gamify/Points/CommentCreated.php b/app/Gamify/Points/CommentCreated.php deleted file mode 100644 index a2b38899..00000000 --- a/app/Gamify/Points/CommentCreated.php +++ /dev/null @@ -1,35 +0,0 @@ -subject = $subject; - } - - /** - * User who will be receive points. - * - * @return mixed - */ - public function payee() - { - return $this->getSubject()->user; - } -} diff --git a/app/Gamify/Points/ReplyCreated.php b/app/Gamify/Points/ReplyCreated.php index 48809921..cabdb51c 100644 --- a/app/Gamify/Points/ReplyCreated.php +++ b/app/Gamify/Points/ReplyCreated.php @@ -6,30 +6,15 @@ class ReplyCreated extends PointType { - /** - * Number of points. - * - * @var int - */ - public $points = 20; + public int $points = 2; - /** - * 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; + return $this->getSubject()->author; } } diff --git a/app/Gamify/Points/UndoBestReply.php b/app/Gamify/Points/UndoBestReply.php deleted file mode 100644 index 2c9ee709..00000000 --- a/app/Gamify/Points/UndoBestReply.php +++ /dev/null @@ -1,35 +0,0 @@ -subject = $subject; - } - - /** - * User who will be receive points. - * - * @return mixed - */ - public function payee() - { - return $this->getSubject()->user; - } -} diff --git a/app/Http/Controllers/Api/ReplyController.php b/app/Http/Controllers/Api/ReplyController.php index ed6b17e9..a7abb789 100644 --- a/app/Http/Controllers/Api/ReplyController.php +++ b/app/Http/Controllers/Api/ReplyController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Events\CommentWasAdded; +use App\Gamify\Points\ReplyCreated; use App\Http\Controllers\Controller; use App\Http\Requests\Api\CreateReplyRequest; use App\Http\Requests\Api\UpdateReplyRequest; @@ -38,8 +39,6 @@ public function all(int $target): AnonymousResourceCollection public function store(CreateReplyRequest $request): ReplyResource { - // dd($request->all()); - // if ($request->parent) {} $reply = new Reply(['body' => $request->body]); $author = User::find($request->user_id); @@ -51,6 +50,8 @@ public function store(CreateReplyRequest $request): ReplyResource // On envoie un event pour une nouvelle réponse à tous les abonnés de la discussion event(new CommentWasAdded($reply, $target)); + givePoint(new ReplyCreated($target)); + return new ReplyResource($reply); } diff --git a/app/Http/Livewire/Articles/Create.php b/app/Http/Livewire/Articles/Create.php index ad468beb..fdeb6350 100644 --- a/app/Http/Livewire/Articles/Create.php +++ b/app/Http/Livewire/Articles/Create.php @@ -61,8 +61,6 @@ public function store() 'user_id' => $user->id, ]); - givePoint(new PostCreated($article)); - if (collect($this->associateTags)->isNotEmpty()) { $article->syncTags($this->associateTags); } @@ -76,6 +74,10 @@ public function store() session()->flash('status', 'Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.'); } + if ($user->hasAnyRole(['admin', 'moderator'])) { + givePoint(new PostCreated($article)); + } + $user->hasRole('user') ? $this->redirectRoute('dashboard') : $this->redirectRoute('articles.show', $article); diff --git a/app/Http/Livewire/Forum/CreateReply.php b/app/Http/Livewire/Forum/CreateReply.php index 2bf536a3..2ee4f8c0 100644 --- a/app/Http/Livewire/Forum/CreateReply.php +++ b/app/Http/Livewire/Forum/CreateReply.php @@ -3,6 +3,7 @@ namespace App\Http\Livewire\Forum; use App\Events\ReplyWasCreated; +use App\Gamify\Points\ReplyCreated; use App\Models\Reply; use App\Models\Thread; use App\Policies\ReplyPolicy; @@ -41,6 +42,8 @@ public function save() event(new ReplyWasCreated($reply)); + givePoint(new ReplyCreated($this->thread)); + session()->flash('status', 'Réponse ajoutée avec succès!'); $this->redirectRoute('forum.show', $this->thread); diff --git a/app/Http/Livewire/Forum/Reply.php b/app/Http/Livewire/Forum/Reply.php index 4f937a0a..614049d3 100644 --- a/app/Http/Livewire/Forum/Reply.php +++ b/app/Http/Livewire/Forum/Reply.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire\Forum; +use App\Gamify\Points\BestReply; use App\Models\Reply as ReplyModel; use App\Models\Thread; use App\Policies\ReplyPolicy; @@ -63,6 +64,8 @@ public function UnMarkAsSolution(): void { $this->authorize(ThreadPolicy::UPDATE, $this->thread); + undoPoint(new BestReply($this->reply)); + $this->thread->unmarkSolution(); $this->emitSelf('refresh'); @@ -77,8 +80,14 @@ public function markAsSolution(): void { $this->authorize(ThreadPolicy::UPDATE, $this->thread); + if ($this->thread->isSolved()) { + undoPoint(new BestReply($this->thread->solutionReply)); + } + $this->thread->markSolution($this->reply, Auth::user()); + givePoint(new BestReply($this->reply)); + $this->emitSelf('refresh'); $this->notification()->success( diff --git a/resources/views/components/user/points.blade.php b/resources/views/components/user/points.blade.php new file mode 100644 index 00000000..92019a8a --- /dev/null +++ b/resources/views/components/user/points.blade.php @@ -0,0 +1,5 @@ +@props(['author']) + + + {{ $author->getPoints() }} XP + diff --git a/resources/views/forum/thread.blade.php b/resources/views/forum/thread.blade.php index 98d72557..0d1893a2 100644 --- a/resources/views/forum/thread.blade.php +++ b/resources/views/forum/thread.blade.php @@ -36,9 +36,7 @@ Avatar de {{ $thread->author->username }} {{ '@' . $thread->author->username }} - - {{ $thread->author->getPoints() }} XP - + a posé diff --git a/resources/views/livewire/forum/reply.blade.php b/resources/views/livewire/forum/reply.blade.php index 7c21025b..85ae363c 100644 --- a/resources/views/livewire/forum/reply.blade.php +++ b/resources/views/livewire/forum/reply.blade.php @@ -19,11 +19,12 @@ {{ $reply->author->name }} {{ '@' . $reply->author->username }} - - {{ $reply->author->getPoints() }} XP - + + + · + @can(App\Policies\ReplyPolicy::UPDATE, $reply) ·
@@ -33,6 +34,7 @@ @endif
@endcan + @can(App\Policies\ThreadPolicy::UPDATE, $thread) @if ($isSolution) diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index bc5be330..5336e5df 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -18,9 +18,9 @@

{{ $user->name }} - - {{ $user->getPoints() }} XP - + + + @if($user->hasAnyRole('admin', 'moderator')) @endif