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.
Completed
Push — user-entity ( a5fdbe...6d5c03 )
by Luis Ramón
02:54
created

CompanyController::workcenterDeleteAction()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 31
Code Lines 20

Duplication

Lines 31
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 31
loc 31
rs 8.5806
cc 4
eloc 20
nc 4
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
     */
100
    public function companyNewFormAction(Request $request)
101
    {
102
        $company = new Company();
103
        $this->getDoctrine()->getManager()->persist($company);
104
105
        return $this->companyFormAction($company, $request);
106
    }
107
108
    /**
109
     * @Route("/{id}", name="company_form", methods={"GET", "POST"})
110
     */
111
    public function companyFormAction(Company $company, Request $request)
112
    {
113
        $form = $this->createForm('AppBundle\Form\Type\CompanyType', $company);
114
        $form->handleRequest($request);
115
116
        if ($form->isValid() && $form->isSubmitted()) {
117
            $this->getDoctrine()->getManager()->flush();
118
            $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'company'));
119
            return $this->redirectToRoute('company_index');
120
        }
121
        $title = $company->getId() ? (string) $company : $this->get('translator')->trans('form.new', [], 'company');
122
123
        return $this->render('company/form_company.html.twig', [
124
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
125
            'breadcrumb' => [
126
                ['fixed' => $title]
127
            ],
128
            'title' => $title,
129
            'form' => $form->createView(),
130
            'company' => $company
131
        ]);
132
    }
133
134
    /**
135
     * @Route("/{id}/sedes", name="workcenter_index", methods={"GET"})
136
     */
137
    public function workcenterIndexAction(Company $company)
138
    {
139
        $items = $company->getWorkcenters();
140
141
        $title = $this->get('translator')->trans('browse.workcenter', ['%company%' => (string) $company], 'company');
142
143
        return $this->render('company/workcenter_index.html.twig',
144
            [
145
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
146
                'breadcrumb' => [
147
                    ['fixed' => (string) $company],
148
                    ['fixed' => $this->get('translator')->trans('form.workcenters', [], 'company')]
149
                ],
150
                'title' => $title,
151
                'elements' => $items,
152
                'company' => $company
153
            ]);
154
    }
155
156
157
    /**
158
     * @Route("/{id}/sedes/modificar/{workcenter}", name="workcenter_form", methods={"GET", "POST"})
159
     */
160 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...
161
    {
162
        $form = $this->createForm('AppBundle\Form\Type\WorkcenterType', $workcenter);
163
        $form->handleRequest($request);
164
165
        if ($form->isValid() && $form->isSubmitted()) {
166
            $this->getDoctrine()->getManager()->flush();
167
            $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'company'));
168
            return $this->redirectToRoute('workcenter_index', ['id' => $workcenter->getCompany()->getId()]);
169
        }
170
        $title = $workcenter->getId() ? $workcenter->getName() : $this->get('translator')->trans('form.new_workcenter', [], 'company');
171
172
        return $this->render('company/form_workcenter.html.twig', [
173
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
174
            'breadcrumb' => [
175
                ['fixed' => (string) $workcenter->getCompany(), 'path' => 'workcenter_index', 'options' => ['id' => $workcenter->getCompany()->getId()]],
176
                ['fixed' => $title]
177
            ],
178
            'title' => $title,
179
            'form' => $form->createView(),
180
            'company' => $company,
181
            'workcenter' => $workcenter
182
        ]);
183
    }
184
185
    /**
186
     * @Route("/{id}/sedes/nueva", name="workcenter_new", methods={"GET", "POST"})
187
     */
188
    public function workcenterNewFormAction(Company $company, Request $request)
189
    {
190
        $workcenter = new Workcenter();
191
        $workcenter->setCompany($company);
192
        $this->getDoctrine()->getManager()->persist($workcenter);
193
194
        return $this->workcenterFormAction($company, $workcenter, $request);
195
    }
196
197
    /**
198
     * @Route("/{id}/sedes/eliminar/{workcenter}", name="workcenter_delete", methods={"GET", "POST"})
199
     */
200 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...
201
    {
202
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
203
204
            $em = $this->getDoctrine()->getManager();
205
206
            // Eliminar el desplazamiento de la base de datos
207
            $em->remove($workcenter);
208
            try {
209
                $em->flush();
210
                $this->addFlash('success', $this->get('translator')->trans('alert.workcenter_deleted', [], 'company'));
211
            } catch (\Exception $e) {
212
                $this->addFlash('error', $this->get('translator')->trans('alert.workcenter_not_deleted', [], 'company'));
213
            }
214
            return $this->redirectToRoute('workcenter_index', ['id' => $company->getId()]);
215
        }
216
217
        $title = (string) $workcenter->getName();
218
219
        return $this->render('company/delete_workcenter.html.twig', [
220
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('company_index'),
221
            'breadcrumb' => [
222
                ['fixed' => (string) $workcenter->getCompany(), 'path' => 'workcenter_index', 'options' => ['id' => $workcenter->getCompany()->getId()]],
223
                ['fixed' => $title, 'path' => 'workcenter_form', 'options' => ['id' => $workcenter->getCompany()->getId(), 'workcenter' => $workcenter->getId()]],
224
                ['fixed' => $this->get('translator')->trans('form.delete', [], 'company')]
225
            ],
226
            'title' => $title,
227
            'company' => $company,
228
            'workcenter' => $workcenter
229
        ]);
230
    }
231
}
232