|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Scrumban\Manager; |
|
4
|
|
|
|
|
5
|
|
|
use Scrumban\Entity\UserStory; |
|
6
|
|
|
use Scrumban\Entity\Sprint; |
|
7
|
|
|
|
|
8
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
9
|
|
|
|
|
10
|
|
|
use Scrumban\Event\UserStoryCreationEvent; |
|
11
|
|
|
use Scrumban\Event\UserStoryUpdateEvent; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
14
|
|
|
|
|
15
|
|
|
final class UserStoryManager |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var ObjectManager **/ |
|
18
|
|
|
private $om; |
|
19
|
|
|
/** @var EventDispatcherInterface **/ |
|
20
|
|
|
private $eventDispatcher; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(ObjectManager $om, EventDispatcherInterface $eventDispatcher) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->om = $om; |
|
25
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function createUserStory(string $id, string $title, string $description, string $value, string $status, float $estimatedTime, float $spentTime, Sprint $sprint = null): UserStory |
|
29
|
|
|
{ |
|
30
|
|
|
$userStory = |
|
31
|
|
|
(new UserStory()) |
|
32
|
|
|
->setId($id) |
|
33
|
|
|
->setTitle($title) |
|
34
|
|
|
->setDescription($description) |
|
35
|
|
|
->setValue($value) |
|
|
|
|
|
|
36
|
|
|
->setStatus($status) |
|
37
|
|
|
->setEstimatedTime($estimatedTime) |
|
38
|
|
|
->setSpentTime($spentTime) |
|
39
|
|
|
; |
|
40
|
|
|
if ($sprint !== null) { |
|
41
|
|
|
$userStory->setSprint($sprint); |
|
42
|
|
|
} |
|
43
|
|
|
$this->om->persist($userStory); |
|
44
|
|
|
$this->om->flush(); |
|
45
|
|
|
$this->eventDispatcher->dispatch(UserStoryCreationEvent::NAME, new UserStoryCreationEvent($userStory)); |
|
46
|
|
|
return $userStory; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function updateUserStory(string $id, string $title, string $description, string $value, string $status, float $estimatedTime, float $spentTime, Sprint $sprint = null, UserStory $userStory = null) |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
$userStory |
|
52
|
|
|
->setTitle($title) |
|
|
|
|
|
|
53
|
|
|
->setDescription($description) |
|
54
|
|
|
->setValue($value) |
|
|
|
|
|
|
55
|
|
|
->setStatus($status) |
|
56
|
|
|
->setEstimatedTime($estimatedTime) |
|
57
|
|
|
->setSpentTime($spentTime) |
|
58
|
|
|
; |
|
59
|
|
|
if ($sprint !== null) { |
|
60
|
|
|
$userStory->setSprint($sprint); |
|
61
|
|
|
} |
|
62
|
|
|
$this->om->flush(); |
|
63
|
|
|
$this->eventDispatcher->dispatch(UserStoryUpdateEvent::NAME, new UserStoryUpdateEvent($userStory)); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getAll(): array |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->om->getRepository(UserStory::class)->findAll(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getSprintUserStories(Sprint $sprint, array $orderBy = null, int $page = null, int $limit = null): array |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->om->getRepository(UserStory::class)->findBy([ |
|
74
|
|
|
'sprint' => $sprint |
|
75
|
|
|
], $orderBy, $limit, $page * $limit); |
|
76
|
|
|
} |
|
77
|
|
|
} |