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 — criterios ( 9a729c...49f237 )
by Luis Ramón
09:26
created

CompanyController::workcenterIndexAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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