1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Controller; |
8
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
10
|
|
|
use Chamilo\CoreBundle\Entity\ExtraField; |
11
|
|
|
use Chamilo\CoreBundle\Entity\ExtraFieldRelTag; |
12
|
|
|
use Chamilo\CoreBundle\Framework\Container; |
13
|
|
|
use Chamilo\CoreBundle\Repository\ExtraFieldRelTagRepository; |
14
|
|
|
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository; |
15
|
|
|
use Chamilo\CoreBundle\Security\Authorization\Voter\CourseVoter; |
16
|
|
|
use Chamilo\CoreBundle\Tool\ToolChain; |
17
|
|
|
use Chamilo\CourseBundle\Controller\ToolBaseController; |
18
|
|
|
use Chamilo\CourseBundle\Entity\CCourseDescription; |
19
|
|
|
use Chamilo\CourseBundle\Entity\CTool; |
20
|
|
|
use Chamilo\CourseBundle\Repository\CCourseDescriptionRepository; |
21
|
|
|
use Chamilo\CourseBundle\Repository\CShortcutRepository; |
22
|
|
|
use Chamilo\CourseBundle\Repository\CToolRepository; |
23
|
|
|
use Chamilo\CourseBundle\Settings\SettingsCourseManager; |
24
|
|
|
use Chamilo\CourseBundle\Settings\SettingsFormFactory; |
25
|
|
|
use CourseManager; |
26
|
|
|
use Database; |
27
|
|
|
use Display; |
28
|
|
|
use Doctrine\ORM\EntityRepository; |
29
|
|
|
use Event; |
30
|
|
|
use Exercise; |
31
|
|
|
use ExtraFieldValue; |
32
|
|
|
use Fhaculty\Graph\Graph; |
33
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity; |
34
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
35
|
|
|
use Symfony\Component\HttpFoundation\Request; |
36
|
|
|
use Symfony\Component\HttpFoundation\Response; |
37
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
38
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
39
|
|
|
use Symfony\Component\Validator\Exception\ValidatorException; |
40
|
|
|
use UnserializeApi; |
41
|
|
|
use UserManager; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @author Julio Montoya <[email protected]> |
45
|
|
|
*/ |
46
|
|
|
#[Route('/course')] |
47
|
|
|
class CourseController extends ToolBaseController |
48
|
|
|
{ |
49
|
|
|
#[Route('/{cid}/home.json', name: 'chamilo_core_course_home_json')] |
50
|
|
|
#[Entity('course', expr: 'repository.find(cid)')] |
51
|
|
|
public function indexJson(Request $request, CToolRepository $toolRepository, CShortcutRepository $shortcutRepository, ToolChain $toolChain): Response |
52
|
|
|
{ |
53
|
|
|
$course = $this->getCourse(); |
54
|
|
|
$sessionId = $this->getSessionId(); |
55
|
|
|
|
56
|
|
|
if (null === $course) { |
57
|
|
|
throw $this->createAccessDeniedException(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->denyAccessUnlessGranted(CourseVoter::VIEW, $course); |
61
|
|
|
|
62
|
|
|
$session = $request->getSession(); |
63
|
|
|
|
64
|
|
|
$userId = 0; |
65
|
|
|
$user = $this->getUser(); |
66
|
|
|
if (null !== $user) { |
67
|
|
|
$userId = $user->getId(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$courseCode = $course->getCode(); |
71
|
|
|
$courseId = $course->getId(); |
72
|
|
|
|
73
|
|
|
if ($user && $user->hasRole('ROLE_INVITEE')) { |
74
|
|
|
$isInASession = $sessionId > 0; |
75
|
|
|
$isSubscribed = CourseManager::is_user_subscribed_in_course( |
76
|
|
|
$userId, |
77
|
|
|
$courseCode, |
78
|
|
|
$isInASession, |
79
|
|
|
$sessionId |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
if (!$isSubscribed) { |
83
|
|
|
throw $this->createAccessDeniedException(); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$isSpecialCourse = CourseManager::isSpecialCourse($courseId); |
88
|
|
|
|
89
|
|
|
if ($user && $isSpecialCourse && (isset($_GET['autoreg']) && 1 === (int) $_GET['autoreg']) && |
90
|
|
|
CourseManager::subscribeUser($userId, $courseId, STUDENT) |
91
|
|
|
) { |
92
|
|
|
$session->set('is_allowed_in_course', true); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$logInfo = [ |
96
|
|
|
'tool' => 'course-main', |
97
|
|
|
]; |
98
|
|
|
Event::registerLog($logInfo); |
99
|
|
|
|
100
|
|
|
$qb = $toolRepository->getResourcesByCourse($course, $this->getSession()); |
101
|
|
|
|
102
|
|
|
$qb->addSelect('tool'); |
103
|
|
|
$qb->innerJoin('resource.tool', 'tool'); |
104
|
|
|
|
105
|
|
|
$result = $qb->getQuery()->getResult(); |
106
|
|
|
$tools = []; |
107
|
|
|
$isCourseTeacher = $this->isGranted('ROLE_CURRENT_COURSE_TEACHER'); |
108
|
|
|
|
109
|
|
|
$skipTools = ['course_tool', 'chat', 'notebook', 'wiki']; |
110
|
|
|
|
111
|
|
|
/** @var CTool $item */ |
112
|
|
|
foreach ($result as $item) { |
113
|
|
|
if (\in_array($item->getName(), $skipTools, true)) { |
114
|
|
|
continue; |
115
|
|
|
} |
116
|
|
|
$toolModel = $toolChain->getToolFromName($item->getTool()->getName()); |
117
|
|
|
|
118
|
|
|
if (!$isCourseTeacher && 'admin' === $toolModel->getCategory()) { |
119
|
|
|
continue; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$tools[$toolModel->getCategory()][] = [ |
123
|
|
|
'ctool' => $item, |
124
|
|
|
'tool' => $toolModel, |
125
|
|
|
]; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
// Get session-career diagram |
129
|
|
|
$diagram = ''; |
130
|
|
|
/*$allow = api_get_configuration_value('allow_career_diagram'); |
131
|
|
|
if (true === $allow) { |
132
|
|
|
$htmlHeadXtra[] = api_get_js('jsplumb2.js'); |
133
|
|
|
$extra = new ExtraFieldValue('session'); |
134
|
|
|
$value = $extra->get_values_by_handler_and_field_variable( |
135
|
|
|
api_get_session_id(), |
136
|
|
|
'external_career_id' |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
if (!empty($value) && isset($value['value'])) { |
140
|
|
|
$careerId = $value['value']; |
141
|
|
|
$extraFieldValue = new ExtraFieldValue('career'); |
142
|
|
|
$item = $extraFieldValue->get_item_id_from_field_variable_and_field_value( |
143
|
|
|
'external_career_id', |
144
|
|
|
$careerId, |
145
|
|
|
false, |
146
|
|
|
false, |
147
|
|
|
false |
148
|
|
|
); |
149
|
|
|
|
150
|
|
|
if (!empty($item) && isset($item['item_id'])) { |
151
|
|
|
$careerId = $item['item_id']; |
152
|
|
|
$career = new Career(); |
153
|
|
|
$careerInfo = $career->get($careerId); |
154
|
|
|
if (!empty($careerInfo)) { |
155
|
|
|
$extraFieldValue = new ExtraFieldValue('career'); |
156
|
|
|
$item = $extraFieldValue->get_values_by_handler_and_field_variable( |
157
|
|
|
$careerId, |
158
|
|
|
'career_diagram', |
159
|
|
|
false, |
160
|
|
|
false, |
161
|
|
|
0 |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
if (!empty($item) && isset($item['value']) && !empty($item['value'])) { |
165
|
|
|
// @var Graph $graph |
166
|
|
|
$graph = UnserializeApi::unserialize('career', $item['value']); |
167
|
|
|
$diagram = Career::renderDiagram($careerInfo, $graph); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
}*/ |
173
|
|
|
|
174
|
|
|
// Deleting the objects |
175
|
|
|
$session->remove('toolgroup'); |
176
|
|
|
$session->remove('_gid'); |
177
|
|
|
$session->remove('oLP'); |
178
|
|
|
$session->remove('lpobject'); |
179
|
|
|
|
180
|
|
|
api_remove_in_gradebook(); |
181
|
|
|
Exercise::cleanSessionVariables(); |
182
|
|
|
|
183
|
|
|
$shortcuts = []; |
184
|
|
|
if (null !== $user) { |
185
|
|
|
$shortcutQuery = $shortcutRepository->getResources($course->getResourceNode()); |
186
|
|
|
$shortcuts = $shortcutQuery->getQuery()->getResult(); |
187
|
|
|
} |
188
|
|
|
$responseData = [ |
189
|
|
|
'course' => $course, |
190
|
|
|
'shortcuts' => $shortcuts, |
191
|
|
|
'diagram' => $diagram, |
192
|
|
|
'tools' => $tools, |
193
|
|
|
]; |
194
|
|
|
|
195
|
|
|
$json = $this->get('serializer')->serialize( |
196
|
|
|
$responseData, |
197
|
|
|
'json', |
198
|
|
|
[ |
199
|
|
|
'groups' => ['course:read', 'ctool:read', 'tool:read', 'cshortcut:read'], |
200
|
|
|
] |
201
|
|
|
); |
202
|
|
|
|
203
|
|
|
return new Response( |
204
|
|
|
$json, |
205
|
|
|
Response::HTTP_OK, |
206
|
|
|
[ |
207
|
|
|
'Content-type' => 'application/json', |
208
|
|
|
] |
209
|
|
|
); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Redirects the page to a tool, following the tools settings. |
214
|
|
|
*/ |
215
|
|
|
#[Route('/{cid}/tool/{toolName}', name: 'chamilo_core_course_redirect_tool')] |
216
|
|
|
public function redirectTool(string $toolName, CToolRepository $repo, ToolChain $toolChain): RedirectResponse |
217
|
|
|
{ |
218
|
|
|
/** @var CTool|null $tool */ |
219
|
|
|
$tool = $repo->findOneBy([ |
220
|
|
|
'name' => $toolName, |
221
|
|
|
]); |
222
|
|
|
|
223
|
|
|
if (null === $tool) { |
224
|
|
|
throw new NotFoundHttpException($this->trans('Tool not found')); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
$tool = $toolChain->getToolFromName($tool->getTool()->getName()); |
228
|
|
|
$link = $tool->getLink(); |
229
|
|
|
|
230
|
|
|
if (null === $this->getCourse()) { |
231
|
|
|
throw new NotFoundHttpException($this->trans('Course not found')); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
if (strpos($link, 'nodeId')) { |
235
|
|
|
$nodeId = (string) $this->getCourse()->getResourceNode()->getId(); |
236
|
|
|
$link = str_replace(':nodeId', $nodeId, $link); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
$url = $link.'?'.$this->getCourseUrlQuery(); |
240
|
|
|
|
241
|
|
|
return $this->redirect($url); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function redirectToShortCut(string $toolName, CToolRepository $repo, ToolChain $toolChain): RedirectResponse |
245
|
|
|
{ |
246
|
|
|
/** @var CTool|null $tool */ |
247
|
|
|
$tool = $repo->findOneBy([ |
248
|
|
|
'name' => $toolName, |
249
|
|
|
]); |
250
|
|
|
|
251
|
|
|
if (null === $tool) { |
252
|
|
|
throw new NotFoundHttpException($this->trans('Tool not found')); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
$tool = $toolChain->getToolFromName($tool->getTool()->getName()); |
256
|
|
|
$link = $tool->getLink(); |
257
|
|
|
|
258
|
|
|
if (strpos($link, 'nodeId')) { |
259
|
|
|
$nodeId = (string) $this->getCourse()->getResourceNode()->getId(); |
260
|
|
|
$link = str_replace(':nodeId', $nodeId, $link); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
$url = $link.'?'.$this->getCourseUrlQuery(); |
264
|
|
|
|
265
|
|
|
return $this->redirect($url); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Edit configuration with given namespace. |
270
|
|
|
*/ |
271
|
|
|
#[Route('/{cid}/settings/{namespace}', name: 'chamilo_core_course_settings')] |
272
|
|
|
#[Entity('course', expr: 'repository.find(cid)')] |
273
|
|
|
public function updateSettings(Request $request, Course $course, string $namespace, SettingsCourseManager $manager, SettingsFormFactory $formFactory): Response |
274
|
|
|
{ |
275
|
|
|
$this->denyAccessUnlessGranted(CourseVoter::VIEW, $course); |
276
|
|
|
|
277
|
|
|
$schemaAlias = $manager->convertNameSpaceToService($namespace); |
278
|
|
|
$settings = $manager->load($namespace); |
279
|
|
|
|
280
|
|
|
$form = $formFactory->create($schemaAlias); |
281
|
|
|
|
282
|
|
|
$form->setData($settings); |
283
|
|
|
$form->handleRequest($request); |
284
|
|
|
|
285
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
286
|
|
|
$messageType = 'success'; |
287
|
|
|
|
288
|
|
|
try { |
289
|
|
|
$manager->setCourse($course); |
290
|
|
|
$manager->save($form->getData()); |
291
|
|
|
$message = $this->trans('Update'); |
292
|
|
|
} catch (ValidatorException $validatorException) { |
293
|
|
|
$message = $this->trans($validatorException->getMessage()); |
294
|
|
|
$messageType = 'error'; |
295
|
|
|
} |
296
|
|
|
$this->addFlash($messageType, $message); |
297
|
|
|
|
298
|
|
|
if ($request->headers->has('referer')) { |
299
|
|
|
return $this->redirect($request->headers->get('referer')); |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
$schemas = $manager->getSchemas(); |
304
|
|
|
|
305
|
|
|
return $this->render( |
306
|
|
|
'@ChamiloCore/Course/settings.html.twig', |
307
|
|
|
[ |
308
|
|
|
'course' => $course, |
309
|
|
|
'schemas' => $schemas, |
310
|
|
|
'settings' => $settings, |
311
|
|
|
'form' => $form->createView(), |
312
|
|
|
] |
313
|
|
|
); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
#[Route('/{id}/about', name: 'chamilo_core_course_about')] |
317
|
|
|
public function about(Course $course, IllustrationRepository $illustrationRepository, CCourseDescriptionRepository $courseDescriptionRepository): Response |
318
|
|
|
{ |
319
|
|
|
$courseId = $course->getId(); |
320
|
|
|
$userId = $this->getUser()->getId(); |
321
|
|
|
$em = $this->getDoctrine()->getManager(); |
322
|
|
|
|
323
|
|
|
/** @var EntityRepository $fieldsRepo */ |
324
|
|
|
$fieldsRepo = $em->getRepository(ExtraField::class); |
325
|
|
|
/** @var ExtraFieldRelTagRepository $fieldTagsRepo */ |
326
|
|
|
$fieldTagsRepo = $em->getRepository(ExtraFieldRelTag::class); |
327
|
|
|
|
328
|
|
|
$courseDescriptions = $courseDescriptionRepository->getResourcesByCourse($course)->getQuery()->getResult(); |
329
|
|
|
|
330
|
|
|
$courseValues = new ExtraFieldValue('course'); |
331
|
|
|
|
332
|
|
|
$urlCourse = api_get_path(WEB_PATH).sprintf('course/%s/about', $courseId); |
333
|
|
|
$courseTeachers = $course->getTeachers(); |
334
|
|
|
$teachersData = []; |
335
|
|
|
|
336
|
|
|
foreach ($courseTeachers as $teacherSubscription) { |
337
|
|
|
$teacher = $teacherSubscription->getUser(); |
338
|
|
|
$userData = [ |
339
|
|
|
'complete_name' => UserManager::formatUserFullName($teacher), |
340
|
|
|
'image' => $illustrationRepository->getIllustrationUrl($teacher), |
341
|
|
|
'diploma' => $teacher->getDiplomas(), |
342
|
|
|
'openarea' => $teacher->getOpenarea(), |
343
|
|
|
]; |
344
|
|
|
|
345
|
|
|
$teachersData[] = $userData; |
346
|
|
|
} |
347
|
|
|
/** @var ExtraField $tagField */ |
348
|
|
|
$tagField = $fieldsRepo->findOneBy([ |
349
|
|
|
'extraFieldType' => ExtraField::COURSE_FIELD_TYPE, |
350
|
|
|
'variable' => 'tags', |
351
|
|
|
]); |
352
|
|
|
|
353
|
|
|
$courseTags = []; |
354
|
|
|
if (null !== $tagField) { |
355
|
|
|
$courseTags = $fieldTagsRepo->getTags($tagField, $courseId); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
$courseDescription = $courseObjectives = $courseTopics = $courseMethodology = ''; |
359
|
|
|
$courseMaterial = $courseResources = $courseAssessment = ''; |
360
|
|
|
$courseCustom = []; |
361
|
|
|
foreach ($courseDescriptions as $descriptionTool) { |
362
|
|
|
switch ($descriptionTool->getDescriptionType()) { |
363
|
|
|
case CCourseDescription::TYPE_DESCRIPTION: |
364
|
|
|
$courseDescription = $descriptionTool->getContent(); |
365
|
|
|
|
366
|
|
|
break; |
367
|
|
|
case CCourseDescription::TYPE_OBJECTIVES: |
368
|
|
|
$courseObjectives = $descriptionTool; |
369
|
|
|
|
370
|
|
|
break; |
371
|
|
|
case CCourseDescription::TYPE_TOPICS: |
372
|
|
|
$courseTopics = $descriptionTool; |
373
|
|
|
|
374
|
|
|
break; |
375
|
|
|
case CCourseDescription::TYPE_METHODOLOGY: |
376
|
|
|
$courseMethodology = $descriptionTool; |
377
|
|
|
|
378
|
|
|
break; |
379
|
|
|
case CCourseDescription::TYPE_COURSE_MATERIAL: |
380
|
|
|
$courseMaterial = $descriptionTool; |
381
|
|
|
|
382
|
|
|
break; |
383
|
|
|
case CCourseDescription::TYPE_RESOURCES: |
384
|
|
|
$courseResources = $descriptionTool; |
385
|
|
|
|
386
|
|
|
break; |
387
|
|
|
case CCourseDescription::TYPE_ASSESSMENT: |
388
|
|
|
$courseAssessment = $descriptionTool; |
389
|
|
|
|
390
|
|
|
break; |
391
|
|
|
case CCourseDescription::TYPE_CUSTOM: |
392
|
|
|
$courseCustom[] = $descriptionTool; |
393
|
|
|
|
394
|
|
|
break; |
395
|
|
|
} |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
$topics = [ |
399
|
|
|
'objectives' => $courseObjectives, |
400
|
|
|
'topics' => $courseTopics, |
401
|
|
|
'methodology' => $courseMethodology, |
402
|
|
|
'material' => $courseMaterial, |
403
|
|
|
'resources' => $courseResources, |
404
|
|
|
'assessment' => $courseAssessment, |
405
|
|
|
'custom' => array_reverse($courseCustom), |
406
|
|
|
]; |
407
|
|
|
|
408
|
|
|
$subscriptionUser = CourseManager::is_user_subscribed_in_course($userId, $course->getCode()); |
409
|
|
|
|
410
|
|
|
/*$allowSubscribe = false; |
411
|
|
|
if ($course->getSubscribe() || api_is_platform_admin()) { |
412
|
|
|
$allowSubscribe = true; |
413
|
|
|
} |
414
|
|
|
$plugin = \BuyCoursesPlugin::create(); |
415
|
|
|
$checker = $plugin->isEnabled(); |
416
|
|
|
$courseIsPremium = null; |
417
|
|
|
if ($checker) { |
418
|
|
|
$courseIsPremium = $plugin->getItemByProduct( |
419
|
|
|
$courseId, |
420
|
|
|
\BuyCoursesPlugin::PRODUCT_TYPE_COURSE |
421
|
|
|
); |
422
|
|
|
}*/ |
423
|
|
|
|
424
|
|
|
$image = Container::getIllustrationRepository()->getIllustrationUrl($course, 'course_picture_medium'); |
425
|
|
|
|
426
|
|
|
$params = [ |
427
|
|
|
'course' => $course, |
428
|
|
|
'description' => $courseDescription, |
429
|
|
|
'image' => $image, |
430
|
|
|
'syllabus' => $topics, |
431
|
|
|
'tags' => $courseTags, |
432
|
|
|
'teachers' => $teachersData, |
433
|
|
|
'extra_fields' => $courseValues->getAllValuesForAnItem( |
434
|
|
|
$course->getId(), |
435
|
|
|
null, |
436
|
|
|
true |
437
|
|
|
), |
438
|
|
|
'subscription' => $subscriptionUser, |
439
|
|
|
'url' => '', |
440
|
|
|
'is_premium' => '', |
441
|
|
|
'token' => '', |
442
|
|
|
]; |
443
|
|
|
|
444
|
|
|
$metaInfo = '<meta property="og:url" content="'.$urlCourse.'" />'; |
445
|
|
|
$metaInfo .= '<meta property="og:type" content="website" />'; |
446
|
|
|
$metaInfo .= '<meta property="og:title" content="'.$course->getTitle().'" />'; |
447
|
|
|
$metaInfo .= '<meta property="og:description" content="'.strip_tags($courseDescription).'" />'; |
448
|
|
|
$metaInfo .= '<meta property="og:image" content="'.$image.'" />'; |
449
|
|
|
|
450
|
|
|
$htmlHeadXtra[] = $metaInfo; |
451
|
|
|
$htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js'); |
452
|
|
|
|
453
|
|
|
return $this->render('@ChamiloCore/Course/about.html.twig', $params); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
#[Route('/{id}/welcome', name: 'chamilo_core_course_welcome')] |
457
|
|
|
public function welcome(Course $course): Response |
458
|
|
|
{ |
459
|
|
|
return $this->render('@ChamiloCore/Course/welcome.html.twig', [ |
460
|
|
|
'course' => $course, |
461
|
|
|
]); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
private function autoLaunch(): void |
465
|
|
|
{ |
466
|
|
|
$autoLaunchWarning = ''; |
467
|
|
|
$showAutoLaunchLpWarning = false; |
468
|
|
|
$course_id = api_get_course_int_id(); |
469
|
|
|
$lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch'); |
470
|
|
|
$session_id = api_get_session_id(); |
471
|
|
|
$allowAutoLaunchForCourseAdmins = |
472
|
|
|
api_is_platform_admin() || |
473
|
|
|
api_is_allowed_to_edit(true, true) || |
474
|
|
|
api_is_coach(); |
475
|
|
|
|
476
|
|
|
if (!empty($lpAutoLaunch)) { |
477
|
|
|
if (2 === $lpAutoLaunch) { |
478
|
|
|
// LP list |
479
|
|
|
if ($allowAutoLaunchForCourseAdmins) { |
480
|
|
|
$showAutoLaunchLpWarning = true; |
481
|
|
|
} else { |
482
|
|
|
$session_key = 'lp_autolaunch_'.$session_id.'_'.$course_id.'_'.api_get_user_id(); |
483
|
|
|
if (!isset($_SESSION[$session_key])) { |
484
|
|
|
// Redirecting to the LP |
485
|
|
|
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq(); |
486
|
|
|
$_SESSION[$session_key] = true; |
487
|
|
|
header(sprintf('Location: %s', $url)); |
488
|
|
|
exit; |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
} else { |
492
|
|
|
$lp_table = Database::get_course_table(TABLE_LP_MAIN); |
493
|
|
|
$condition = ''; |
494
|
|
|
if (!empty($session_id)) { |
495
|
|
|
$condition = api_get_session_condition($session_id); |
496
|
|
|
$sql = "SELECT id FROM {$lp_table} |
497
|
|
|
WHERE c_id = {$course_id} AND autolaunch = 1 {$condition} |
498
|
|
|
LIMIT 1"; |
499
|
|
|
$result = Database::query($sql); |
500
|
|
|
// If we found nothing in the session we just called the session_id = 0 autolaunch |
501
|
|
|
if (0 === Database::num_rows($result)) { |
502
|
|
|
$condition = ''; |
503
|
|
|
} |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
$sql = "SELECT iid FROM {$lp_table} |
507
|
|
|
WHERE c_id = {$course_id} AND autolaunch = 1 {$condition} |
508
|
|
|
LIMIT 1"; |
509
|
|
|
$result = Database::query($sql); |
510
|
|
|
if (Database::num_rows($result) > 0) { |
511
|
|
|
$lp_data = Database::fetch_array($result, 'ASSOC'); |
512
|
|
|
if (!empty($lp_data['iid'])) { |
513
|
|
|
if ($allowAutoLaunchForCourseAdmins) { |
514
|
|
|
$showAutoLaunchLpWarning = true; |
515
|
|
|
} else { |
516
|
|
|
$session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
517
|
|
|
if (!isset($_SESSION[$session_key])) { |
518
|
|
|
// Redirecting to the LP |
519
|
|
|
$url = api_get_path(WEB_CODE_PATH). |
520
|
|
|
'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['iid']; |
521
|
|
|
|
522
|
|
|
$_SESSION[$session_key] = true; |
523
|
|
|
header(sprintf('Location: %s', $url)); |
524
|
|
|
exit; |
525
|
|
|
} |
526
|
|
|
} |
527
|
|
|
} |
528
|
|
|
} |
529
|
|
|
} |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
if ($showAutoLaunchLpWarning) { |
533
|
|
|
$autoLaunchWarning = get_lang( |
534
|
|
|
'The learning path auto-launch setting is ON. When learners enter this course, they will be automatically redirected to the learning path marked as auto-launch.' |
535
|
|
|
); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
$forumAutoLaunch = (int) api_get_course_setting('enable_forum_auto_launch'); |
539
|
|
|
if (1 === $forumAutoLaunch) { |
540
|
|
|
if ($allowAutoLaunchForCourseAdmins) { |
541
|
|
|
if (empty($autoLaunchWarning)) { |
542
|
|
|
$autoLaunchWarning = get_lang( |
543
|
|
|
"The forum's auto-launch setting is on. Students will be redirected to the forum tool when entering this course." |
544
|
|
|
); |
545
|
|
|
} |
546
|
|
|
} else { |
547
|
|
|
$url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(); |
548
|
|
|
header(sprintf('Location: %s', $url)); |
549
|
|
|
exit; |
550
|
|
|
} |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
if (api_get_configuration_value('allow_exercise_auto_launch')) { |
554
|
|
|
$exerciseAutoLaunch = (int) api_get_course_setting('enable_exercise_auto_launch'); |
555
|
|
|
if (2 === $exerciseAutoLaunch) { |
556
|
|
|
if ($allowAutoLaunchForCourseAdmins) { |
557
|
|
|
if (empty($autoLaunchWarning)) { |
558
|
|
|
$autoLaunchWarning = get_lang( |
559
|
|
|
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList' |
560
|
|
|
); |
561
|
|
|
} |
562
|
|
|
} else { |
563
|
|
|
// Redirecting to the document |
564
|
|
|
$url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq(); |
565
|
|
|
header(sprintf('Location: %s', $url)); |
566
|
|
|
exit; |
567
|
|
|
} |
568
|
|
|
} elseif (1 === $exerciseAutoLaunch) { |
569
|
|
|
if ($allowAutoLaunchForCourseAdmins) { |
570
|
|
|
if (empty($autoLaunchWarning)) { |
571
|
|
|
$autoLaunchWarning = get_lang( |
572
|
|
|
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise' |
573
|
|
|
); |
574
|
|
|
} |
575
|
|
|
} else { |
576
|
|
|
// Redirecting to an exercise |
577
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_TEST); |
578
|
|
|
$condition = ''; |
579
|
|
|
if (!empty($session_id)) { |
580
|
|
|
$condition = api_get_session_condition($session_id); |
581
|
|
|
$sql = "SELECT iid FROM {$table} |
582
|
|
|
WHERE c_id = {$course_id} AND autolaunch = 1 {$condition} |
583
|
|
|
LIMIT 1"; |
584
|
|
|
$result = Database::query($sql); |
585
|
|
|
// If we found nothing in the session we just called the session_id = 0 autolaunch |
586
|
|
|
if (0 === Database::num_rows($result)) { |
587
|
|
|
$condition = ''; |
588
|
|
|
} |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
$sql = "SELECT iid FROM {$table} |
592
|
|
|
WHERE c_id = {$course_id} AND autolaunch = 1 {$condition} |
593
|
|
|
LIMIT 1"; |
594
|
|
|
$result = Database::query($sql); |
595
|
|
|
if (Database::num_rows($result) > 0) { |
596
|
|
|
$row = Database::fetch_array($result, 'ASSOC'); |
597
|
|
|
$exerciseId = $row['iid']; |
598
|
|
|
$url = api_get_path(WEB_CODE_PATH). |
599
|
|
|
'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq(); |
600
|
|
|
header(sprintf('Location: %s', $url)); |
601
|
|
|
exit; |
602
|
|
|
} |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
$documentAutoLaunch = (int) api_get_course_setting('enable_document_auto_launch'); |
608
|
|
|
if (1 === $documentAutoLaunch) { |
609
|
|
|
if ($allowAutoLaunchForCourseAdmins) { |
610
|
|
|
if (empty($autoLaunchWarning)) { |
611
|
|
|
$autoLaunchWarning = get_lang( |
612
|
|
|
'The document auto-launch feature configuration is enabled. Learners will be automatically redirected to document tool.' |
613
|
|
|
); |
614
|
|
|
} |
615
|
|
|
} else { |
616
|
|
|
// Redirecting to the document |
617
|
|
|
$url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(); |
618
|
|
|
header("Location: $url"); |
619
|
|
|
exit; |
620
|
|
|
} |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
/* SWITCH TO A DIFFERENT HOMEPAGE VIEW |
624
|
|
|
the setting homepage_view is adjustable through |
625
|
|
|
the platform administration section */ |
626
|
|
|
if (!empty($autoLaunchWarning)) { |
627
|
|
|
$this->addFlash( |
628
|
|
|
'warning', |
629
|
|
|
Display::return_message( |
630
|
|
|
$autoLaunchWarning, |
631
|
|
|
'warning' |
632
|
|
|
) |
633
|
|
|
); |
634
|
|
|
} |
635
|
|
|
} |
636
|
|
|
} |
637
|
|
|
|