|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
namespace Chamilo\CourseBundle\Controller; |
|
5
|
|
|
|
|
6
|
|
|
use APY\DataGridBundle\Grid\Action\RowAction; |
|
7
|
|
|
use APY\DataGridBundle\Grid\Source\Entity; |
|
8
|
|
|
use Chamilo\CourseBundle\Entity\CToolIntro; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class CDocumentController. |
|
15
|
|
|
* |
|
16
|
|
|
* @author Julio Montoya <[email protected]> |
|
17
|
|
|
* |
|
18
|
|
|
* @Route("/documents") |
|
19
|
|
|
*/ |
|
20
|
|
|
class CDocumentController extends ToolBaseController |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @Route("/") |
|
24
|
|
|
*/ |
|
25
|
|
|
public function indexAction() |
|
26
|
|
|
{ |
|
27
|
|
|
$breadCrumb = $this->get('chamilo_core.block.breadcrumb'); |
|
28
|
|
|
$breadCrumb->addChild($this->trans('Introduction')); |
|
29
|
|
|
|
|
30
|
|
|
// Creates a simple grid based on your entity (ORM) |
|
31
|
|
|
$source = new Entity('ChamiloCourseBundle:CToolIntro'); |
|
32
|
|
|
|
|
33
|
|
|
// Get a Grid instance |
|
34
|
|
|
$grid = $this->get('grid'); |
|
35
|
|
|
|
|
36
|
|
|
// Attach the source to the grid |
|
37
|
|
|
$grid->setSource($source); |
|
38
|
|
|
|
|
39
|
|
|
$rowUpdateAction = new RowAction( |
|
40
|
|
|
$this->trans('Update'), |
|
41
|
|
|
'chamilo_course_ctoolintro_update', |
|
42
|
|
|
false, |
|
43
|
|
|
'_self', |
|
44
|
|
|
['class' => 'btn'], |
|
45
|
|
|
null//$role |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
$rowUpdateAction->setRouteParameters( |
|
49
|
|
|
['iid', 'course' => $this->getCourse()->getCode()] |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$rowAction = new RowAction( |
|
53
|
|
|
$this->trans('Delete'), |
|
54
|
|
|
'chamilo_course_ctoolintro_delete', |
|
55
|
|
|
true, |
|
56
|
|
|
'_self', |
|
57
|
|
|
['class' => 'btn'], |
|
58
|
|
|
null//$role |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$rowAction->setRouteParameters( |
|
62
|
|
|
['iid', 'course' => $this->getCourse()->getCode()] |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
$grid->addRowAction($rowUpdateAction); |
|
66
|
|
|
$grid->addRowAction($rowAction); |
|
67
|
|
|
|
|
68
|
|
|
// Return the response of the grid to the template |
|
69
|
|
|
return $grid->getGridResponse( |
|
70
|
|
|
'grid.html.twig' |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @Route("/{tool}/create") |
|
76
|
|
|
*/ |
|
77
|
|
|
public function createAction(Request $request, $tool) |
|
78
|
|
|
{ |
|
79
|
|
|
// Breadcrumb |
|
80
|
|
|
$breadCrumb = $this->get('chamilo_core.block.breadcrumb'); |
|
81
|
|
|
$breadCrumb->addChild( |
|
82
|
|
|
$this->trans('Introduction'), |
|
83
|
|
|
[ |
|
84
|
|
|
'route' => 'chamilo_course_ctoolintro_index', |
|
85
|
|
|
'routeParameters' => [ |
|
86
|
|
|
'course' => $this->getCourse()->getCode(), |
|
87
|
|
|
], |
|
88
|
|
|
] |
|
89
|
|
|
); |
|
90
|
|
|
$breadCrumb->addChild($this->trans('Create')); |
|
91
|
|
|
|
|
92
|
|
|
$course = $this->getCourse(); |
|
93
|
|
|
$session = $this->getSession(); |
|
94
|
|
|
|
|
95
|
|
|
$toolIntro = new CToolIntro(); |
|
96
|
|
|
$toolIntro |
|
97
|
|
|
->setSessionId(0) |
|
98
|
|
|
->setTool($tool) |
|
|
|
|
|
|
99
|
|
|
->setCId($course->getId()); |
|
100
|
|
|
|
|
101
|
|
|
if ($session) { |
|
|
|
|
|
|
102
|
|
|
$toolIntro->setSessionId($session->getId()); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
// Declared in forms.yml |
|
106
|
|
|
$formService = $this->get('chamilo_course.form.type.c_tool_intro'); |
|
107
|
|
|
|
|
108
|
|
|
$form = $this->createForm($formService, $toolIntro); |
|
109
|
|
|
$form->handleRequest($request); |
|
110
|
|
|
|
|
111
|
|
|
if ($form->isValid()) { |
|
112
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
113
|
|
|
$em->persist($toolIntro); |
|
114
|
|
|
$em->flush(); |
|
115
|
|
|
$this->addFlash('success', $this->trans('Saved')); |
|
116
|
|
|
|
|
117
|
|
|
return $this->redirectToRoute( |
|
118
|
|
|
'chamilo_course_ctoolintro_update', |
|
119
|
|
|
['course' => $course->getCode(), 'iid' => $toolIntro->getId()] |
|
120
|
|
|
); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return $this->render( |
|
124
|
|
|
'@ChamiloTheme/CToolIntro/create.html.twig', |
|
125
|
|
|
['form' => $form->createView(), 'tool' => $tool] |
|
126
|
|
|
); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @Route("/{iid}/update/", methods={"GET|POST"}) |
|
131
|
|
|
* |
|
132
|
|
|
* @return Response |
|
133
|
|
|
*/ |
|
134
|
|
|
public function updateAction($iid, Request $request) |
|
135
|
|
|
{ |
|
136
|
|
|
// Breadcrumb |
|
137
|
|
|
$breadCrumb = $this->get('chamilo_core.block.breadcrumb'); |
|
138
|
|
|
$breadCrumb->addChild( |
|
139
|
|
|
$this->trans('Introduction'), |
|
140
|
|
|
[ |
|
141
|
|
|
'route' => 'chamilo_course_ctoolintro_index', |
|
142
|
|
|
'routeParameters' => [ |
|
143
|
|
|
'course' => $this->getCourse()->getCode(), |
|
144
|
|
|
], |
|
145
|
|
|
] |
|
146
|
|
|
); |
|
147
|
|
|
$breadCrumb->addChild($this->trans('Update')); |
|
148
|
|
|
|
|
149
|
|
|
$course = $this->getCourse(); |
|
150
|
|
|
|
|
151
|
|
|
$em = $this->get('doctrine')->getManager(); |
|
152
|
|
|
$criteria = [ |
|
153
|
|
|
'iid' => $iid, |
|
154
|
|
|
]; |
|
155
|
|
|
|
|
156
|
|
|
$formService = $this->get('chamilo_course.form.type.c_tool_intro'); |
|
157
|
|
|
|
|
158
|
|
|
$toolIntro = $em->getRepository('ChamiloCourseBundle:CToolIntro')->findOneBy($criteria); |
|
159
|
|
|
$form = $this->createForm($formService, $toolIntro); |
|
160
|
|
|
$tool = $toolIntro->getTool(); |
|
161
|
|
|
$form->handleRequest($request); |
|
162
|
|
|
|
|
163
|
|
|
if ($form->isValid()) { |
|
164
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
165
|
|
|
$em->persist($toolIntro); |
|
166
|
|
|
$em->flush(); |
|
167
|
|
|
$this->addFlash('success', $this->trans('Updated')); |
|
168
|
|
|
|
|
169
|
|
|
return $this->redirectToRoute( |
|
170
|
|
|
'chamilo_course_ctoolintro_update', |
|
171
|
|
|
['course' => $course->getCode(), 'tool' => $tool, 'iid' => $iid] |
|
172
|
|
|
); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
return $this->render( |
|
176
|
|
|
'@ChamiloTheme/CToolIntro/update.html.twig', |
|
177
|
|
|
[ |
|
178
|
|
|
'tool' => $tool, |
|
179
|
|
|
'iid' => $iid, |
|
180
|
|
|
'form' => $form->createView(), |
|
181
|
|
|
] |
|
182
|
|
|
); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @Route("/{iid}/delete", methods={"GET"}) |
|
187
|
|
|
* |
|
188
|
|
|
* @param int $iid |
|
189
|
|
|
* |
|
190
|
|
|
* @return Response |
|
191
|
|
|
*/ |
|
192
|
|
|
public function deleteAction($iid, Request $request) |
|
193
|
|
|
{ |
|
194
|
|
|
$criteria = [ |
|
195
|
|
|
'iid' => $iid, |
|
196
|
|
|
]; |
|
197
|
|
|
|
|
198
|
|
|
$doctrine = $this->getDoctrine(); |
|
199
|
|
|
$toolIntro = $doctrine->getRepository('ChamiloCourseBundle:CToolIntro')->findOneBy($criteria); |
|
200
|
|
|
if ($toolIntro) { |
|
201
|
|
|
$doctrine->getManager()->remove($toolIntro); |
|
202
|
|
|
$doctrine->getManager()->flush(); |
|
203
|
|
|
$this->addFlash('success', $this->trans("IntroductionTextDeleted")); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
return $this->redirectCourseHome(); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function uploadAction() |
|
210
|
|
|
{ |
|
211
|
|
|
|
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.