Skip to content

Badges reputations #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/Console/Commands/UpdateUserBestRepliesPoints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Console\Commands;

use App\Gamify\Points\BestReply;
use App\Models\Thread;
use Illuminate\Console\Command;

class UpdateUserBestRepliesPoints extends Command
{
protected $signature = 'lcm:update-users-bests-replies-points';

protected $description = 'Updating users bests replies reputation points';

public function handle()
{
$this->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!');
}
}
42 changes: 0 additions & 42 deletions app/Console/Commands/UpdateUserCommentsPoints.php

This file was deleted.

39 changes: 11 additions & 28 deletions app/Console/Commands/UpdateUserRepliesPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,24 @@

namespace App\Console\Commands;

use App\Gamify\Points\ReplyCreated;
use App\Models\Reply;
use Illuminate\Console\Command;

class UpdateUserRepliesPoints extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:name';
protected $signature = 'lcm:update-users-replies-points';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
protected $description = 'Updating users replies reputation points';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
return 0;
$this->info('Updating users bests replies reputations...');

foreach (Reply::all() as $reply) {
givePoint(new ReplyCreated($reply->replyAble));
}

$this->info('All done!');
}
}
17 changes: 1 addition & 16 deletions app/Gamify/Points/AddPhone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 1 addition & 16 deletions app/Gamify/Points/AddSocialLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 3 additions & 21 deletions app/Gamify/Points/BestReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
35 changes: 0 additions & 35 deletions app/Gamify/Points/CommentCreated.php

This file was deleted.

19 changes: 2 additions & 17 deletions app/Gamify/Points/ReplyCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
35 changes: 0 additions & 35 deletions app/Gamify/Points/UndoBestReply.php

This file was deleted.

5 changes: 3 additions & 2 deletions app/Http/Controllers/Api/ReplyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions app/Http/Livewire/Articles/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public function store()
'user_id' => $user->id,
]);

givePoint(new PostCreated($article));

if (collect($this->associateTags)->isNotEmpty()) {
$article->syncTags($this->associateTags);
}
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Livewire/Forum/CreateReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading