Completed
Push — master ( dd814f...b87df0 )
by Dominik
14s
created

AzineEmailController::emailsDashboardAction()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 16
nc 2
nop 1
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());
0 ignored issues
show
Documentation introduced by
new \Azine\EmailBundle\Form\SentEmailType() is of type object<Azine\EmailBundle\Form\SentEmailType>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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), $request->query->get('limit', 10));
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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        $email = $this->getDoctrine()->getManager()->getRepository(SentEmail::class)
0 ignored issues
show
Bug introduced by
The method findOneByToken() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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