EditPollHandler.php
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace FootyRoom\App\Poll;
use FootyRoom\Repositories\UserRepository;
use FootyRoom\Repositories\Poll\PollRepository;
use FootyRoom\Core\Poll\Choice;
class EditPollHandler
{
/**
* @var \FootyRoom\Repositories\UserRepository
*/
protected $userRepo;
/**
* @var \FootyRoom\Repositories\Poll\PollRepository
*/
protected $pollRepo;
/**
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;
/**
* Constructor.
*
* @param \FootyRoom\Repositories\UserRepository $userRepo
* @param \FootyRoom\Repositories\Poll\PollRepository $pollRepo
*/
public function __construct(UserRepository $userRepo, PollRepository $pollRepo)
{
$this->userRepo = $userRepo;
$this->pollRepo = $pollRepo;
}
/**
* Handler.
*
* @param \FootyRoom\App\Poll\EditPollCommand $command
*/
public function handle(EditPollCommand $command)
{
$poll = $this->pollRepo->findById($command->pollId);
$choices = [];
foreach ($command->choices as $key => $choice) {
$choices[] = new Choice($key, $choice->text, $choice->image);
}
$poll->edit($choices);
$this->pollRepo->update($poll);
}
}