Completed
Push — 5.0 ( a48099...63af02 )
by
unknown
11:33
created

Controller/FormSubmissionsController.php (2 issues)

Checks whether return doc types can be made more specific.

Documentation Informational

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\FormBundle\Controller;
4
5
use Doctrine\ORM\EntityManager;
6
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMap;
7
use Kunstmaan\AdminListBundle\AdminList\AdminList;
8
use Kunstmaan\AdminListBundle\AdminList\ExportList;
9
use Kunstmaan\FormBundle\AdminList\FormPageAdminListConfigurator;
10
use Kunstmaan\FormBundle\AdminList\FormSubmissionAdminListConfigurator;
11
use Kunstmaan\FormBundle\AdminList\FormSubmissionExportListConfigurator;
12
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
13
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
14
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
15
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
16
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpFoundation\Response;
19
20
21
/**
22
 * The controller which will handle everything related with form pages and form submissions
23
 */
24
class FormSubmissionsController extends Controller
25
{
26
    /**
27
     * The index action will use an admin list to list all the form pages
28
     *
29
     * @Route("/", name="KunstmaanFormBundle_formsubmissions")
30
     * @Template("KunstmaanAdminListBundle:Default:list.html.twig")
31
     *
32
     * @return array
33
     */
34
    public function indexAction(Request $request)
35
    {
36
        /* @var EntityManager $em */
37
        $em        = $this->getDoctrine()->getManager();
38
        $aclHelper = $this->container->get('kunstmaan_admin.acl.helper');
39
40
        /* @var AdminList $adminList */
41
        $adminList = $this->get('kunstmaan_adminlist.factory')->createList(
42
            new FormPageAdminListConfigurator($em, $aclHelper, PermissionMap::PERMISSION_VIEW),
43
            $em
44
        );
45
        $adminList->bindRequest($request);
46
47
        return array('adminlist' => $adminList);
48
    }
49
50
    /**
51
     * The list action will use an admin list to list all the form submissions related to the given $nodeTranslationId
52
     *
53
     * @param int $nodeTranslationId
54
     *
55
     * @Route("/list/{nodeTranslationId}", requirements={"nodeTranslationId" = "\d+"},
56
     *                                     name="KunstmaanFormBundle_formsubmissions_list")
57
     * @Method({"GET", "POST"})
58
     * @Template()
59
     *
60
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,object>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
61
     */
62
    public function listAction(Request $request, $nodeTranslationId)
63
    {
64
        $em              = $this->getDoctrine()->getManager();
65
        $nodeTranslation = $em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslationId);
66
67
        /** @var AdminList $adminList */
68
        $adminList = $this->get('kunstmaan_adminlist.factory')->createList(
69
            new FormSubmissionAdminListConfigurator($em, $nodeTranslation),
70
            $em
71
        );
72
        $adminList->bindRequest($request);
73
74
        return array('nodetranslation' => $nodeTranslation, 'adminlist' => $adminList);
75
    }
76
77
    /**
78
     * The edit action will be used to edit a given submission
79
     *
80
     * @param int $nodeTranslationId The node translation id
81
     * @param int $submissionId      The submission id
82
     *
83
     * @Route("/list/{nodeTranslationId}/{submissionId}", requirements={"nodeTranslationId" = "\d+", "submissionId" =
84
     *                                                    "\d+"}, name="KunstmaanFormBundle_formsubmissions_list_edit")
85
     * @Method({"GET", "POST"})
86
     * @Template()
87
     *
88
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,object>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
89
     */
90
    public function editAction($nodeTranslationId, $submissionId)
91
    {
92
        $em                   = $this->getDoctrine()->getManager();
93
        $nodeTranslation      = $em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslationId);
94
        $formSubmission       = $em->getRepository('KunstmaanFormBundle:FormSubmission')->find($submissionId);
95
96
        return array(
97
            'nodetranslation' => $nodeTranslation,
98
            'formsubmission' => $formSubmission
99
        );
100
    }
101
102
    /**
103
     * Export as CSV of all the form submissions for the given $nodeTranslationId
104
     *
105
     * @param int $nodeTranslationId
106
     *
107
     * @Route("/export/{nodeTranslationId}.{_format}", requirements={"nodeTranslationId" = "\d+","_format" =
108
     *                                                 "csv|xlsx|ods"}, name="KunstmaanFormBundle_formsubmissions_export")
109
     * @Method({"GET"})
110
     *
111
     * @return Response
112
     */
113
    public function exportAction($nodeTranslationId, $_format)
114
    {
115
        $em = $this->getDoctrine()->getManager();
116
        /** @var NodeTranslation $nodeTranslation */
117
        $nodeTranslation = $em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslationId);
118
        $translator      = $this->get('translator');
119
120
        /** @var ExportList $exportList */
121
        $configurator = new FormSubmissionExportListConfigurator($em, $nodeTranslation, $translator);
122
        $exportList   = $this->get('kunstmaan_adminlist.factory')->createExportList($configurator);
123
124
        return $this->get('kunstmaan_adminlist.service.export')->getDownloadableResponse($exportList, $_format);
125
    }
126
}
127