Skip to content

Commit 14d1645

Browse files
authored
Merge pull request #36 from laravelcm/badges-reputations
Badges reputations
2 parents 5ab24b3 + 6edf967 commit 14d1645

File tree

17 files changed

+78
-223
lines changed

17 files changed

+78
-223
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Gamify\Points\BestReply;
6+
use App\Models\Thread;
7+
use Illuminate\Console\Command;
8+
9+
class UpdateUserBestRepliesPoints extends Command
10+
{
11+
protected $signature = 'lcm:update-users-bests-replies-points';
12+
13+
protected $description = 'Updating users bests replies reputation points';
14+
15+
public function handle()
16+
{
17+
$this->info('Updating users bests replies reputations...');
18+
19+
$resolvedThread = Thread::with('solutionReply')->resolved()->get();
20+
21+
foreach ($resolvedThread as $thread) {
22+
givePoint(new BestReply($thread->solutionReply));
23+
}
24+
25+
$this->info('All done!');
26+
}
27+
}

app/Console/Commands/UpdateUserCommentsPoints.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/Console/Commands/UpdateUserRepliesPoints.php

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,24 @@
22

33
namespace App\Console\Commands;
44

5+
use App\Gamify\Points\ReplyCreated;
6+
use App\Models\Reply;
57
use Illuminate\Console\Command;
68

79
class UpdateUserRepliesPoints extends Command
810
{
9-
/**
10-
* The name and signature of the console command.
11-
*
12-
* @var string
13-
*/
14-
protected $signature = 'command:name';
11+
protected $signature = 'lcm:update-users-replies-points';
1512

16-
/**
17-
* The console command description.
18-
*
19-
* @var string
20-
*/
21-
protected $description = 'Command description';
13+
protected $description = 'Updating users replies reputation points';
2214

23-
/**
24-
* Create a new command instance.
25-
*
26-
* @return void
27-
*/
28-
public function __construct()
29-
{
30-
parent::__construct();
31-
}
32-
33-
/**
34-
* Execute the console command.
35-
*
36-
* @return int
37-
*/
3815
public function handle()
3916
{
40-
return 0;
17+
$this->info('Updating users bests replies reputations...');
18+
19+
foreach (Reply::all() as $reply) {
20+
givePoint(new ReplyCreated($reply->replyAble));
21+
}
22+
23+
$this->info('All done!');
4124
}
4225
}

app/Gamify/Points/AddPhone.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,13 @@
66

77
class AddPhone extends PointType
88
{
9-
/**
10-
* Number of points.
11-
*
12-
* @var int
13-
*/
14-
public $points = 20;
9+
public int $points = 5;
1510

16-
/**
17-
* Point constructor.
18-
*
19-
* @param $subject
20-
*/
2111
public function __construct($subject)
2212
{
2313
$this->subject = $subject;
2414
}
2515

26-
/**
27-
* User who will be receive points.
28-
*
29-
* @return mixed
30-
*/
3116
public function payee()
3217
{
3318
return $this->getSubject()->user;

app/Gamify/Points/AddSocialLinks.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,13 @@
66

77
class AddSocialLinks extends PointType
88
{
9-
/**
10-
* Number of points.
11-
*
12-
* @var int
13-
*/
14-
public $points = 20;
9+
public int $points = 6;
1510

16-
/**
17-
* Point constructor.
18-
*
19-
* @param $subject
20-
*/
2111
public function __construct($subject)
2212
{
2313
$this->subject = $subject;
2414
}
2515

26-
/**
27-
* User who will be receive points.
28-
*
29-
* @return mixed
30-
*/
3116
public function payee()
3217
{
3318
return $this->getSubject()->user;

app/Gamify/Points/BestReply.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,12 @@
66

77
class BestReply extends PointType
88
{
9-
/**
10-
* Number of points.
11-
*
12-
* @var int
13-
*/
14-
public $points = 20;
9+
public int $points = 10;
10+
11+
protected string $payee = 'author';
1512

16-
/**
17-
* Point constructor.
18-
*
19-
* @param $subject
20-
*/
2113
public function __construct($subject)
2214
{
2315
$this->subject = $subject;
2416
}
25-
26-
/**
27-
* User who will be receive points.
28-
*
29-
* @return mixed
30-
*/
31-
public function payee()
32-
{
33-
return $this->getSubject()->user;
34-
}
3517
}

app/Gamify/Points/CommentCreated.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

app/Gamify/Points/ReplyCreated.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,15 @@
66

77
class ReplyCreated extends PointType
88
{
9-
/**
10-
* Number of points.
11-
*
12-
* @var int
13-
*/
14-
public $points = 20;
9+
public int $points = 2;
1510

16-
/**
17-
* Point constructor.
18-
*
19-
* @param $subject
20-
*/
2111
public function __construct($subject)
2212
{
2313
$this->subject = $subject;
2414
}
2515

26-
/**
27-
* User who will be receive points.
28-
*
29-
* @return mixed
30-
*/
3116
public function payee()
3217
{
33-
return $this->getSubject()->user;
18+
return $this->getSubject()->author;
3419
}
3520
}

app/Gamify/Points/UndoBestReply.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

app/Http/Controllers/Api/ReplyController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers\Api;
44

55
use App\Events\CommentWasAdded;
6+
use App\Gamify\Points\ReplyCreated;
67
use App\Http\Controllers\Controller;
78
use App\Http\Requests\Api\CreateReplyRequest;
89
use App\Http\Requests\Api\UpdateReplyRequest;
@@ -38,8 +39,6 @@ public function all(int $target): AnonymousResourceCollection
3839

3940
public function store(CreateReplyRequest $request): ReplyResource
4041
{
41-
// dd($request->all());
42-
// if ($request->parent) {}
4342
$reply = new Reply(['body' => $request->body]);
4443
$author = User::find($request->user_id);
4544

@@ -51,6 +50,8 @@ public function store(CreateReplyRequest $request): ReplyResource
5150
// On envoie un event pour une nouvelle réponse à tous les abonnés de la discussion
5251
event(new CommentWasAdded($reply, $target));
5352

53+
givePoint(new ReplyCreated($target));
54+
5455
return new ReplyResource($reply);
5556
}
5657

app/Http/Livewire/Articles/Create.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ public function store()
6161
'user_id' => $user->id,
6262
]);
6363

64-
givePoint(new PostCreated($article));
65-
6664
if (collect($this->associateTags)->isNotEmpty()) {
6765
$article->syncTags($this->associateTags);
6866
}
@@ -76,6 +74,10 @@ public function store()
7674
session()->flash('status', 'Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.');
7775
}
7876

77+
if ($user->hasAnyRole(['admin', 'moderator'])) {
78+
givePoint(new PostCreated($article));
79+
}
80+
7981
$user->hasRole('user') ?
8082
$this->redirectRoute('dashboard') :
8183
$this->redirectRoute('articles.show', $article);

app/Http/Livewire/Forum/CreateReply.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Livewire\Forum;
44

55
use App\Events\ReplyWasCreated;
6+
use App\Gamify\Points\ReplyCreated;
67
use App\Models\Reply;
78
use App\Models\Thread;
89
use App\Policies\ReplyPolicy;
@@ -41,6 +42,8 @@ public function save()
4142

4243
event(new ReplyWasCreated($reply));
4344

45+
givePoint(new ReplyCreated($this->thread));
46+
4447
session()->flash('status', 'Réponse ajoutée avec succès!');
4548

4649
$this->redirectRoute('forum.show', $this->thread);

0 commit comments

Comments
 (0)