|
1
|
|
|
<?php |
|
2
|
|
|
namespace AppBundle\Controller\Mail; |
|
3
|
|
|
|
|
4
|
|
|
use AppBundle\Form\Type\SendMailFormType; |
|
5
|
|
|
use AppBundle\Service\MailService; |
|
6
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
|
|
11
|
|
|
class MailController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @return MailService |
|
15
|
|
|
*/ |
|
16
|
|
|
private function getMailService() |
|
17
|
|
|
{ |
|
18
|
|
|
return $this->get('app.mail'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @Route("/", name="mail.index") |
|
23
|
|
|
* @Method({"GET"}) |
|
24
|
|
|
*/ |
|
25
|
|
|
public function indexAction(Request $request) |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
$mails = $this->getMailService()->getConversationList(); |
|
28
|
|
|
|
|
29
|
|
|
return $this->render('mail/index.html.twig', [ |
|
30
|
|
|
'mails' => $mails, |
|
31
|
|
|
]); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @Route("/{userId}", name="mail.view", requirements={"userId": "\d+"}) |
|
36
|
|
|
* @Method({"GET", "POST"}) |
|
37
|
|
|
*/ |
|
38
|
|
|
public function viewAction(Request $request, $userId) |
|
39
|
|
|
{ |
|
40
|
|
|
$mails = $this->getMailService()->getMessagesByRecipientUserId($userId); |
|
41
|
|
|
|
|
42
|
|
|
$form = $this->createForm(SendMailFormType::class, null, []); |
|
43
|
|
|
|
|
44
|
|
|
$form->handleRequest($request); |
|
45
|
|
|
if ($form->isSubmitted()) { |
|
46
|
|
|
$this->getMailService()->sendMessage($userId, $form->get('text')->getData()); |
|
47
|
|
|
|
|
48
|
|
|
return $this->redirectToRoute('mail.view', ['userId' => $userId]); |
|
49
|
|
|
} |
|
50
|
|
|
else { |
|
51
|
|
|
$this->getMailService()->markConversationAsRead($userId); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $this->render('mail/view.html.twig', [ |
|
55
|
|
|
'mails' => $mails, |
|
56
|
|
|
'form' => $form->createView(), |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.