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 — master ( 45667e...23896c )
by Luis Ramón
02:44
created

departmentsIndexAction()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 25
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 25
loc 25
rs 8.8571
cc 1
eloc 14
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\Department;
24
use AppBundle\Form\Type\DepartmentType;
25
use Doctrine\ORM\EntityManager;
26
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
27
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
28
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
29
use Symfony\Component\HttpFoundation\Request;
30
31
/**
32
 * @Route("/admin/departamentos")
33
 * @Security("is_granted('ROLE_ADMIN')")
34
 */
35
class AdminDepartmentController extends Controller
36
{
37
    /**
38
     * @Route("/", name="admin_departments", methods={"GET"})
39
     */
40 View Code Duplication
    public function departmentsIndexAction(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...
41
    {
42
        /** @var EntityManager $em */
43
        $em = $this->getDoctrine()->getManager();
44
45
        $departmentsQuery = $em->createQuery('SELECT d FROM AppBundle:Department d JOIN d.head h JOIN h.person p');
46
47
        $paginator  = $this->get('knp_paginator');
48
        $pagination = $paginator->paginate(
49
            $departmentsQuery,
50
            $request->query->getInt('page', 1),
51
            $this->getParameter('page.size'),
52
            [
53
                'defaultSortFieldName' => 'd.name',
54
                'defaultSortDirection' => 'asc'
55
            ]
56
        );
57
58
        return $this->render('admin/manage_departments.html.twig',
59
            [
60
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_departments'),
61
                'title' => null,
62
                'pagination' => $pagination
63
            ]);
64
    }
65
66
    /**
67
     * @Route("/nuevo", name="admin_department_new", methods={"GET", "POST"})
68
     * @Route("/{department}", name="admin_department_form", methods={"GET", "POST"}, requirements={"department": "\d+"})
69
     */
70
    public function formAction(Department $department = null, Request $request)
71
    {
72
        $em = $this->getDoctrine()->getManager();
73
74
        $new = (null === $department);
75
        if ($new) {
76
            $department = new Department();
77
            $em->persist($department);
78
        }
79
80
        $form = $this->createForm(DepartmentType::class, $department);
81
82
        $form->handleRequest($request);
83
84
        if ($form->isSubmitted() && $form->isValid()) {
85
86
            // Probar a guardar los cambios
87
            try {
88
                $em->flush();
89
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'user'));
90
                return $this->redirectToRoute('admin_departments');
91
            } catch (\Exception $e) {
92
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'user'));
93
            }
94
        }
95
96
        $titulo = ((string) $department) ?: $this->get('translator')->trans('department.new', [], 'admin');
97
98
        return $this->render('admin/form_department.html.twig', [
99
            'form' => $form->createView(),
100
            'new' => $new,
101
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_departments'),
102
            'breadcrumb' => [
103
                ['fixed' => $titulo]
104
            ],
105
            'department' => $department,
106
            'title' => $titulo
107
        ]);
108
    }
109
110
    /**
111
     * @Route("/eliminar/{department}", name="admin_department_delete", methods={"GET", "POST"}, requirements={"department": "\d+"} )
112
     */
113
    public function deleteElementAction(Request $request, Department $department)
114
    {
115
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
116
117
            // Eliminar el departamento de la base de datos
118
            $this->getDoctrine()->getManager()->remove($department);
119
            try {
120
                $this->getDoctrine()->getManager()->flush();
121
                $this->addFlash('success', $this->get('translator')->trans('alert.deleted', [], 'department'));
122
            }
123
            catch(\Exception $e) {
124
                $this->addFlash('error', $this->get('translator')->trans('alert.not_deleted', [], 'department'));
125
            }
126
            return $this->redirectToRoute('admin_departments');
127
        }
128
129
        $title = $department->getName();
130
131
        $breadcrumb = [
132
            ['fixed' => $title, 'path' => 'admin_department_form', 'options' => ['department' => $department->getId()]],
133
            ['caption' => 'menu.delete']
134
        ];
135
136
        return $this->render(':admin:delete_department.html.twig', [
137
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_departments'),
138
            'breadcrumb' => $breadcrumb,
139
            'title' => $title,
140
            'department' => $department
141
        ]);
142
    }
143
}
144