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 — develop ( ea63f9...3c014b )
by Luis Ramón
04:34
created

ActivityController::learningOutcomeDeleteAction()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 34
Code Lines 21

Duplication

Lines 34
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 34
loc 34
rs 8.5806
cc 4
eloc 21
nc 4
nop 2
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\Activity;
24
use AppBundle\Entity\LearningOutcome;
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("/programa")
33
 * @Security("is_granted('ROLE_DEPARTMENT_HEAD')")
34
 */
35
class ActivityController extends Controller
36
{
37
38
    /**
39
     * @Route("/actividades/{id}", name="admin_program_training_activities", methods={"GET"})
40
     */
41
    public function activitiesIndexAction(LearningOutcome $learningOutcome, Request $request)
42
    {
43
        /** @var EntityManager $em */
44
        $em = $this->getDoctrine()->getManager();
45
46
        $usersQuery = $em->createQuery('SELECT a FROM AppBundle:Activity a WHERE a.learningOutcome = :learningOutcome')
47
            ->setParameter('learningOutcome', $learningOutcome);
48
49
        $paginator  = $this->get('knp_paginator');
50
        $pagination = $paginator->paginate(
51
            $usersQuery,
52
            $request->query->getInt('page', 1),
53
            $this->getParameter('page.size'),
54
            [
55
                'defaultSortFieldName' => 'a.code',
56
                'defaultSortDirection' => 'asc'
57
            ]
58
        );
59
60
        return $this->render('activity/manage_activities.html.twig',
61
            [
62
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
63
                'breadcrumb' => [
64
                    ['fixed' => $learningOutcome->getTraining()->getName(), 'path' => 'admin_program_training_learning_outcomes', 'options' => ['id' => $learningOutcome->getTraining()->getId()]],
65
                    ['fixed' => (string) $learningOutcome],
66
                ],
67
                'title' => $learningOutcome->getName(),
68
                'pagination' => $pagination,
69
                'learning_outcome' => $learningOutcome
70
            ]);
71
    }
72
73
    /**
74
     * @Route("/actividad/nuevo/{id}", name="admin_program_activity_new", methods={"GET", "POST"}, requirements={"id": "\d+"})
75
     */
76
    public function formActivityNewAction(LearningOutcome $learningOutcome, Request $request)
77
    {
78
        $activity = new Activity();
79
        $activity->setLearningOutcome($learningOutcome);
80
        $this->getDoctrine()->getManager()->persist($activity);
81
82
        return $this->formActivityAction($activity, $request);
83
    }
84
85
    /**
86
     * @Route("/actividad/{id}", name="admin_program_activity_form", methods={"GET", "POST"}, requirements={"id": "\d+"})
87
     */
88
    public function formActivityAction(Activity $activity, Request $request)
89
    {
90
        $em = $this->getDoctrine()->getManager();
91
92
        $form = $this->createForm('AppBundle\Form\Type\ActivityType', $activity, [
93
            'fixed' => true
94
        ]);
95
        
96
        $form->handleRequest($request);
97
98 View Code Duplication
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
99
100
            // Guardar el usuario en la base de datos
101
            // Probar a guardar los cambios
102
            try {
103
                $em->flush();
104
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'activity'));
105
                return $this->redirectToRoute('admin_program_training_activities', ['id' => $activity->getLearningOutcome()->getId()]);
106
            } catch (\Exception $e) {
107
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'activity'));
108
            }
109
        }
110
111
        $title = $activity->getId() ? (string) $activity : $this->get('translator')->trans('form.new', [], 'activity');
112
113
        return $this->render('activity/form_activity.html.twig', [
114
            'form' => $form->createView(),
115
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
116
            'breadcrumb' => [
117
                ['fixed' => $activity->getLearningOutcome()->getTraining(), 'path' => 'admin_program_training_learning_outcomes', 'options' => ['id' => $activity->getLearningOutcome()->getTraining()->getId()]],
118
                ['fixed' => $activity->getLearningOutcome(), 'path' => 'admin_program_training_activities', 'options' => ['id' => $activity->getLearningOutcome()->getId()]],
119
                ['fixed' => $title]
120
            ],
121
            'new' => $activity->getId() == 0,
122
            'title' => $title,
123
            'item' => $activity
124
        ]);
125
    }
126
127
    /**
128
     * @Route("/actividad/eliminar/{id}", name="admin_program_activity_delete", methods={"GET", "POST"}, requirements={"id": "\d+"})
129
     */
130
    public function activityDeleteAction(Activity $activity, Request $request)
131
    {
132
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
133
134
            // Eliminar el departamento de la base de datos
135
            $this->getDoctrine()->getManager()->remove($activity);
136
            try {
137
                $this->getDoctrine()->getManager()->flush();
138
                $this->addFlash('success', $this->get('translator')->trans('alert.deleted', [], 'activity'));
139
            } catch (\Exception $e) {
140
                $this->addFlash('error', $this->get('translator')->trans('alert.not_deleted', [], 'activity'));
141
            }
142
            return $this->redirectToRoute('admin_program_training_activities', ['id' => $activity->getLearningOutcome()->getId()]);
143
        }
144
145
        $title = (string) $activity->getName();
146
147
        $breadcrumb = [
148
            ['fixed' => $activity->getLearningOutcome()->getTraining(), 'path' => 'admin_program_training_learning_outcomes', 'options' => ['id' => $activity->getLearningOutcome()->getTraining()->getId()]],
149
            ['fixed' => $activity->getLearningOutcome(), 'path' => 'admin_program_training_activities', 'options' => ['id' => $activity->getLearningOutcome()->getId()]],
150
            ['fixed' => (string) $activity, 'path' => 'admin_program_activity_form', 'options' => ['id' => $activity->getId()]],
151
            ['caption' => 'menu.delete']
152
        ];
153
154
        return $this->render('activity/delete_activity.html.twig', [
155
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
156
            'breadcrumb' => $breadcrumb,
157
            'title' => $title,
158
            'element' => $activity
159
        ]);
160
    }
161
}
162