1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Azine\EmailBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Azine\EmailBundle\Entity\SentEmail; |
6
|
|
|
use Azine\EmailBundle\Form\SentEmailType; |
7
|
|
|
use FOS\UserBundle\Model\User; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This controller provides the following actions: |
13
|
|
|
* |
14
|
|
|
* emailsDashboard: a list of all SentEmail entities with ability to filter by each property. |
15
|
|
|
* emailDetailsByToken: extended view of SentEmail entity searched by a token property. |
16
|
|
|
*/ |
17
|
|
|
class AzineEmailController extends Controller |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Displays an Emails-Dashboard with filters for each property of SentEmails entity and links to |
21
|
|
|
* emailDetailsByToken & webView actions for each email |
22
|
|
|
*/ |
23
|
|
|
public function emailsDashboardAction(Request $request) |
24
|
|
|
{ |
25
|
|
|
$form = $this->createForm(new SentEmailType()); |
|
|
|
|
26
|
|
|
$form->handleRequest($request); |
27
|
|
|
$searchParams = $form->getData(); |
28
|
|
|
$repository = $this->getDoctrine()->getManager()->getRepository(SentEmail::class); |
29
|
|
|
|
30
|
|
|
$emails = $repository->search($searchParams); |
31
|
|
|
$emailsArray = []; |
32
|
|
|
|
33
|
|
|
foreach ($emails as $key => $email){ |
34
|
|
|
|
35
|
|
|
$emailsArray[$key]['recipients'] = substr(implode(', ', $email->getRecipients()), 0, 60); |
36
|
|
|
$emailsArray[$key]['template'] = $email->getTemplate(); |
37
|
|
|
$emailsArray[$key]['sent'] = $email->getSent()->format('Y-m-d H:i:s'); |
38
|
|
|
$emailsArray[$key]['variables'] = substr(json_encode($email->getVariables()), 0, 60); |
39
|
|
|
$emailsArray[$key]['token'] = $email->getToken(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$pagination = $this->get('knp_paginator')->paginate($emailsArray, $request->query->get('page', 1)); |
43
|
|
|
|
44
|
|
|
return $this->render('AzineEmailBundle::emailsDashboard.html.twig', |
45
|
|
|
['form' => $form->createView(), 'pagination' => $pagination ]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Displays an extended view of SentEmail entity searched by a token property |
50
|
|
|
* @param string $token |
51
|
|
|
* @return Response |
52
|
|
|
*/ |
53
|
|
|
public function emailDetailsByTokenAction(Request $request, $token) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$email = $this->getDoctrine()->getManager()->getRepository(SentEmail::class) |
56
|
|
|
->findOneByToken($token); |
57
|
|
|
|
58
|
|
|
if($email instanceof SentEmail){ |
59
|
|
|
|
60
|
|
|
$recipients = implode(', ', $email->getRecipients()); |
61
|
|
|
$variables = implode(', ', array_keys($email->getVariables())); |
62
|
|
|
|
63
|
|
|
return $this->render('AzineEmailBundle::sentEmailDetails.html.twig', |
64
|
|
|
['email' => $email, 'recipients' => $recipients, 'variables' => $variables]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// the parameters-array is null => the email is not available in webView |
68
|
|
|
$days = $this->getParameter("azine_email_web_view_retention"); |
69
|
|
|
$response = $this->render("AzineEmailBundle:Webview:mail.not.available.html.twig", array('days' => $days)); |
70
|
|
|
$response->setStatusCode(404); |
71
|
|
|
|
72
|
|
|
return $response; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: