GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CompanyController::workcenterFormAction()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 24

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
dl 24
loc 24
rs 9.536
c 0
b 0
f 0
cc 4
nc 3
nop 3
1
<?php
2
/*
3
  ÁTICA - Aplicación web para la gestión documental de centros educativos
4
5
  Copyright (C) 2015-2016: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Controller;
22
23
use AppBundle\Entity\Company;
24
use AppBundle\Entity\Workcenter;
25
use Doctrine\ORM\EntityManager;
26
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
27
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
28
use Symfony\Component\HttpFoundation\Request;
29
30
/**
31
 * @Route("/empresas")
32
 * @Security("is_granted('ROLE_DEPARTMENT_HEAD')")
33
 */
34
class CompanyController extends BaseController
35
{
36
    /**
37
     * @Route("", name="company_index", methods={"GET"})
38
     */
39 View Code Duplication
    public function companyIndexAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        /** @var EntityManager $em */
42
        $em = $this->getDoctrine()->getManager();
43
44
        $query = $em->createQuery('SELECT c FROM AppBundle:Company c JOIN AppBundle:User u WITH c.manager = u');
45
46
        $paginator  = $this->get('knp_paginator');
47
        $pagination = $paginator->paginate(
48
            $query,
49
            $request->query->getInt('page', 1),
50
            $this->getParameter('page.size'),
51
            [
52
                'defaultSortFieldName' => 'c.name',
53
                'defaultSortDirection' => 'asc'
54
            ]
55
        );
56
57
        return $this->render('company/company_index.html.twig', [
58
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
59
            'title' => null,
60
            'elements' => $pagination
61
        ]);
62
    }
63
64
    /**
65
     * @Route("/eliminar/{id}", name="company_delete", methods={"GET", "POST"})
66
     */
67
    public function companyDeleteAction(Company $company, Request $request)
68
    {
69
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
70
71
            $em = $this->getDoctrine()->getManager();
72
73
            // Eliminar el desplazamiento de la base de datos
74
            $em->remove($company);
75
            try {
76
                $em->flush();
77
                $this->addFlash('success', $this->get('translator')->trans('alert.deleted', [], 'company'));
78
            } catch (\Exception $e) {
79
                $this->addFlash('error', $this->get('translator')->trans('alert.not_deleted', [], 'company'));
80
            }
81
            return $this->redirectToRoute('company_index');
82
        }
83
84
        $title = (string) $company;
85
86
        return $this->render('company/delete_company.html.twig', [
87
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
88
            'breadcrumb' => [
89
                ['fixed' => $title, 'path' => 'company_form', 'options' => ['id' => $company->getId()]],
90
                ['fixed' => $this->get('translator')->trans('form.delete', [], 'company')]
91
            ],
92
            'title' => $title,
93
            'company' => $company
94
        ]);
95
    }
96
97
    /**
98
     * @Route("/nueva", name="company_new", methods={"GET", "POST"})
99
     * @Route("/{id}", name="company_form", methods={"GET", "POST"})
100
     */
101
    public function companyFormAction(Request $request, Company $company = null)
102
    {
103
        if (null === $company) {
104
            $company = new Company();
105
            $this->getDoctrine()->getManager()->persist($company);
106
        }
107
        $form = $this->createForm('AppBundle\Form\Type\CompanyType', $company);
108
        $form->handleRequest($request);
109
110
        if ($form->isSubmitted() && $form->isValid()) {
111
            if (null === $company->getId()) {
112
                $workcenter = new Workcenter();
113
                $workcenter
114
                    ->setName($this->get('translator')->trans('default.workcenter', [], 'company'))
115
                    ->setCompany($company)
116
                    ->setAddress($company->getAddress())
117
                    ->setCity($company->getCity())
118
                    ->setProvince($company->getProvince())
119
                    ->setZipCode($company->getZipCode())
120
                    ->setPhoneNumber($company->getPhoneNumber())
121
                    ->setEmail($company->getEmail())
122
                    ->setManager($company->getManager());
123
                $this->getDoctrine()->getManager()->persist($workcenter);
124
            }
125
            $this->getDoctrine()->getManager()->flush();
126
            $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'company'));
127
            return $this->redirectToRoute('company_index');
128
        }
129
        $title = $company->getId() ? (string) $company : $this->get('translator')->trans('form.new', [], 'company');
130
131
        return $this->render('company/form_company.html.twig', [
132
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
133
            'breadcrumb' => [
134
                ['fixed' => $title]
135
            ],
136
            'title' => $title,
137
            'form' => $form->createView(),
138
            'company' => $company
139
        ]);
140
    }
141
142
    /**
143
     * @Route("/{id}/sedes", name="workcenter_index", methods={"GET"})
144
     */
145
    public function workcenterIndexAction(Company $company)
146
    {
147
        $items = $company->getWorkcenters();
148
149
        $title = $this->get('translator')->trans('browse.workcenter', ['%company%' => (string) $company], 'company');
150
151
        return $this->render('company/workcenter_index.html.twig',
152
            [
153
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
154
                'breadcrumb' => [
155
                    ['fixed' => (string) $company],
156
                    ['fixed' => $this->get('translator')->trans('form.workcenters', [], 'company')]
157
                ],
158
                'title' => $title,
159
                'elements' => $items,
160
                'company' => $company
161
            ]);
162
    }
163
164
165
    /**
166
     * @Route("/{id}/sedes/modificar/{workcenter}", name="workcenter_form", methods={"GET", "POST"})
167
     */
168 View Code Duplication
    public function workcenterFormAction(Company $company, Workcenter $workcenter, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
169
    {
170
        $form = $this->createForm('AppBundle\Form\Type\WorkcenterType', $workcenter);
171
        $form->handleRequest($request);
172
173
        if ($form->isSubmitted() && $form->isValid()) {
174
            $this->getDoctrine()->getManager()->flush();
175
            $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'company'));
176
            return $this->redirectToRoute('workcenter_index', ['id' => $workcenter->getCompany()->getId()]);
177
        }
178
        $title = $workcenter->getId() ? $workcenter->getName() : $this->get('translator')->trans('form.new_workcenter', [], 'company');
179
180
        return $this->render('company/form_workcenter.html.twig', [
181
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
182
            'breadcrumb' => [
183
                ['fixed' => (string) $workcenter->getCompany(), 'path' => 'workcenter_index', 'options' => ['id' => $workcenter->getCompany()->getId()]],
184
                ['fixed' => $title]
185
            ],
186
            'title' => $title,
187
            'form' => $form->createView(),
188
            'company' => $company,
189
            'workcenter' => $workcenter
190
        ]);
191
    }
192
193
    /**
194
     * @Route("/{id}/sedes/nueva", name="workcenter_new", methods={"GET", "POST"})
195
     */
196
    public function workcenterNewFormAction(Company $company, Request $request)
197
    {
198
        $workcenter = new Workcenter();
199
        $workcenter
200
            ->setCompany($company)
201
            ->setAddress($company->getAddress())
202
            ->setCity($company->getCity())
203
            ->setProvince($company->getProvince())
204
            ->setZipCode($company->getZipCode())
205
            ->setPhoneNumber($company->getPhoneNumber())
206
            ->setEmail($company->getEmail())
207
            ->setManager($company->getManager())
208
        ;
209
        $this->getDoctrine()->getManager()->persist($workcenter);
210
211
        return $this->workcenterFormAction($company, $workcenter, $request);
212
    }
213
214
    /**
215
     * @Route("/{id}/sedes/eliminar/{workcenter}", name="workcenter_delete", methods={"GET", "POST"})
216
     */
217 View Code Duplication
    public function workcenterDeleteAction(Company $company, Workcenter $workcenter, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
218
    {
219
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
220
221
            $em = $this->getDoctrine()->getManager();
222
223
            // Eliminar el desplazamiento de la base de datos
224
            $em->remove($workcenter);
225
            try {
226
                $em->flush();
227
                $this->addFlash('success', $this->get('translator')->trans('alert.workcenter_deleted', [], 'company'));
228
            } catch (\Exception $e) {
229
                $this->addFlash('error', $this->get('translator')->trans('alert.workcenter_not_deleted', [], 'company'));
230
            }
231
            return $this->redirectToRoute('workcenter_index', ['id' => $company->getId()]);
232
        }
233
234
        $title = (string) $workcenter->getName();
235
236
        return $this->render('company/delete_workcenter.html.twig', [
237
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
238
            'breadcrumb' => [
239
                ['fixed' => (string) $workcenter->getCompany(), 'path' => 'workcenter_index', 'options' => ['id' => $workcenter->getCompany()->getId()]],
240
                ['fixed' => $title, 'path' => 'workcenter_form', 'options' => ['id' => $workcenter->getCompany()->getId(), 'workcenter' => $workcenter->getId()]],
241
                ['fixed' => $this->get('translator')->trans('form.delete', [], 'company')]
242
            ],
243
            'title' => $title,
244
            'company' => $company,
245
            'workcenter' => $workcenter
246
        ]);
247
    }
248
}
249