|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Matks\Bundle\CustomerSupportBundle\Manager; |
|
4
|
|
|
|
|
5
|
|
|
use Matks\Bundle\CustomerSupportBundle\Model\TicketInterface; |
|
6
|
|
|
use Matks\Bundle\CustomerSupportBundle\Model\MessageInterface; |
|
7
|
|
|
use Matks\Bundle\CustomerSupportBundle\Model\CategoryInterface; |
|
8
|
|
|
|
|
9
|
|
|
use Matks\Bundle\CustomerSupportBundle\Reference\ReferenceGeneratorInterface; |
|
10
|
|
|
|
|
11
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Ticket Manager |
|
15
|
|
|
* |
|
16
|
|
|
* @author Mathieu Ferment <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class TicketManager implements TicketManagerInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var ManagerRegistry |
|
22
|
|
|
*/ |
|
23
|
|
|
private $doctrine; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var ReferenceGeneratorInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $referenceGenerator; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string Ticket FQDN |
|
32
|
|
|
*/ |
|
33
|
|
|
private $ticketClass; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Constructor |
|
37
|
|
|
* |
|
38
|
|
|
* @param ManagerRegistry $doctrine |
|
39
|
|
|
* @param ReferenceGeneratorInterface $referenceGenerator |
|
40
|
|
|
* @param string $ticketClass |
|
41
|
|
|
*/ |
|
42
|
6 |
|
public function __construct(ManagerRegistry $doctrine, ReferenceGeneratorInterface $referenceGenerator, $ticketClass) |
|
43
|
|
|
{ |
|
44
|
6 |
|
$this->referenceGenerator = $referenceGenerator; |
|
45
|
6 |
|
$this->doctrine = $doctrine; |
|
46
|
6 |
|
$this->ticketClass = $ticketClass; |
|
47
|
6 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create a new ticket |
|
51
|
|
|
* |
|
52
|
|
|
* @param CategoryInterface $category |
|
53
|
|
|
* @param MessageInterface $message |
|
54
|
|
|
* |
|
55
|
|
|
* @return TicketInterface |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function create(CategoryInterface $category, MessageInterface $message) |
|
58
|
|
|
{ |
|
59
|
1 |
|
$reference = $this->referenceGenerator->generate([]); |
|
60
|
|
|
|
|
61
|
1 |
|
$ticket = new $this->ticketClass($reference, $category, $message); |
|
62
|
1 |
|
$this->doctrine->getManager()->persist($ticket); |
|
63
|
1 |
|
$this->doctrine->getManager()->flush(); |
|
64
|
|
|
|
|
65
|
1 |
|
return $ticket; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Answer to a ticket |
|
70
|
|
|
* |
|
71
|
|
|
* @param TicketInterface $ticket |
|
72
|
|
|
* @param MessageInterface $message |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function answer(TicketInterface $ticket, MessageInterface $message) |
|
75
|
|
|
{ |
|
76
|
1 |
|
$ticket->answer($message); |
|
77
|
1 |
|
$this->doctrine->getManager()->flush(); |
|
78
|
1 |
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Reopen an answered ticket |
|
82
|
|
|
* |
|
83
|
|
|
* @param TicketInterface $ticket |
|
84
|
|
|
* @param MessageInterface $message |
|
85
|
|
|
*/ |
|
86
|
1 |
|
public function reopen(TicketInterface $ticket, MessageInterface $message) |
|
87
|
|
|
{ |
|
88
|
1 |
|
$ticket->reopen($message); |
|
89
|
1 |
|
$this->doctrine->getManager()->flush(); |
|
90
|
1 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Close a ticket |
|
94
|
|
|
* |
|
95
|
|
|
* @param TicketInterface $ticket |
|
96
|
|
|
*/ |
|
97
|
1 |
|
public function close(TicketInterface $ticket) |
|
98
|
|
|
{ |
|
99
|
1 |
|
$ticket->close(); |
|
100
|
1 |
|
$this->doctrine->getManager()->flush(); |
|
101
|
1 |
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Shift a ticket category |
|
105
|
|
|
* |
|
106
|
|
|
* @param TicketInterface $ticket |
|
107
|
|
|
* @param CategoryInterface $category |
|
108
|
|
|
*/ |
|
109
|
1 |
|
public function changeCategory(TicketInterface $ticket, CategoryInterface $category) |
|
110
|
|
|
{ |
|
111
|
1 |
|
$ticket->changeCategory($category); |
|
112
|
1 |
|
$this->doctrine->getManager()->flush(); |
|
113
|
1 |
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|