Issues (2160)

plugin/xapi/cmi5/view.php (1 issue)

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\PluginBundle\Entity\XApi\Cmi5Item;
6
use Chamilo\PluginBundle\Entity\XApi\ToolLaunch;
7
use Symfony\Component\HttpFoundation\Request as HttpRequest;
0 ignored issues
show
This use statement conflicts with another class in this namespace, HttpRequest. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use Xabbuh\XApi\Model\LanguageMap;
9
10
require_once __DIR__.'/../../../main/inc/global.inc.php';
11
12
api_protect_course_script(true);
13
api_block_anonymous_users();
14
15
$request = HttpRequest::createFromGlobals();
16
17
$em = Database::getManager();
18
19
$toolLaunch = $em->find(
20
    ToolLaunch::class,
21
    $request->query->getInt('id')
22
);
23
24
if (null === $toolLaunch
25
    || 'cmi5' !== $toolLaunch->getActivityType()
26
) {
27
    header('Location: '.api_get_course_url());
28
    exit;
29
}
30
31
$plugin = XApiPlugin::create();
32
$course = api_get_course_entity();
33
$session = api_get_session_entity();
34
$cidReq = api_get_cidreq();
35
$user = api_get_user_entity(api_get_user_id());
36
$interfaceLanguage = api_get_interface_language();
37
38
$itemsRepo = $em->getRepository(Cmi5Item::class);
39
40
$query = $em->createQueryBuilder()
41
    ->select('item')
42
    ->from(Cmi5Item::class, 'item')
43
    ->where('item.tool = :tool')
44
    ->setParameter('tool', $toolLaunch->getId())
45
    ->getQuery();
46
47
$tocHtml = $itemsRepo->buildTree(
48
    $query->getArrayResult(),
49
    [
50
        'decorate' => true,
51
        'rootOpen' => '<ul>',
52
        'rootClose' => '</ul>',
53
        'childOpen' => '<li>',
54
        'childClose' => '</li>',
55
        'nodeDecorator' => function ($node) use ($interfaceLanguage, $cidReq, $toolLaunch) {
56
            $titleMap = LanguageMap::create($node['title']);
57
            $title = XApiPlugin::extractVerbInLanguage($titleMap, $interfaceLanguage);
58
59
            if ('block' === $node['type']) {
60
                return Display::page_subheader($title, null, 'h4');
61
            }
62
63
            return Display::url(
64
                $title,
65
                "launch.php?tool={$toolLaunch->getId()}&id={$node['id']}&$cidReq",
66
                [
67
                    'target' => 'ifr_content',
68
                    'class' => 'text-left btn-link',
69
                ]
70
            );
71
        },
72
    ]
73
);
74
75
$webPluginPath = api_get_path(WEB_PLUGIN_PATH);
76
77
$htmlHeadXtra[] = api_get_css($webPluginPath.'xapi/assets/css/cmi5_launch.css');
78
$htmlHeadXtra[] = api_get_js_simple($webPluginPath.'xapi/assets/js/cmi5_launch.js');
79
80
$view = new Template('', false, false, true, true, false);
81
$view->assign('tool', $toolLaunch);
82
$view->assign('toc_html', $tocHtml);
83
$view->assign('content', $view->fetch('xapi/views/cmi5_launch.twig'));
84
$view->display_no_layout_template();
85