Passed
Push — master ( 21de45...bc9ea1 )
by Julito
08:48
created

CourseController::about()   C

Complexity

Conditions 12
Paths 40

Size

Total Lines 138
Code Lines 87

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 87
c 0
b 0
f 0
nc 40
nop 3
dl 0
loc 138
rs 5.8569

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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