Issues (2160)

plugin/xapi/tincan/stats.php (3 issues)

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use Chamilo\PluginBundle\Entity\XApi\ToolLaunch;
5
use Knp\Component\Pager\Paginator;
6
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...
7
8
require_once __DIR__.'/../../../main/inc/global.inc.php';
9
10
api_protect_course_script(true);
11
api_protect_teacher_script();
12
13
$request = HttpRequest::createFromGlobals();
14
15
$em = Database::getManager();
16
17
$toolLaunch = $em->find(
18
    ToolLaunch::class,
19
    $request->query->getInt('id')
20
);
21
22
if (null === $toolLaunch) {
23
    header('Location: '.api_get_course_url());
24
    exit;
25
}
26
27
$course = api_get_course_entity();
28
$session = api_get_session_entity();
29
30
$cidReq = api_get_cidreq();
31
32
$plugin = XApiPlugin::create();
33
34
$length = 20;
35
$page = $request->query->getInt('page', 1);
36
$start = ($page - 1) * $length;
37
$countStudentList = CourseManager::get_student_list_from_course_code(
38
    $course->getCode(),
39
    (bool) $session,
40
    $session ? $session->getId() : 0,
0 ignored issues
show
$session is of type Chamilo\CoreBundle\Entity\Session, thus it always evaluated to true.
Loading history...
41
    null,
42
    null,
43
    true,
44
    0,
45
    true
46
);
47
48
$statsUrl = api_get_self().'?'.api_get_cidreq().'&id='.$toolLaunch->getId();
49
50
$paginator = new Paginator();
51
$pagination = $paginator->paginate([]);
52
$pagination->setTotalItemCount($countStudentList);
53
$pagination->setItemNumberPerPage($length);
54
$pagination->setCurrentPageNumber($page);
55
$pagination->renderer = function ($data) use ($statsUrl) {
56
    $render = '';
57
    if ($data['pageCount'] > 1) {
58
        $render = '<ul class="pagination">';
59
        for ($i = 1; $i <= $data['pageCount']; $i++) {
60
            $pageContent = '<li><a href="'.$statsUrl.'&page='.$i.'">'.$i.'</a></li>';
61
            if ($data['current'] == $i) {
62
                $pageContent = '<li class="active"><a href="#" >'.$i.'</a></li>';
63
            }
64
            $render .= $pageContent;
65
        }
66
        $render .= '</ul>';
67
    }
68
69
    return $render;
70
};
71
72
$students = CourseManager::get_student_list_from_course_code(
73
    $course->getCode(),
74
    (bool) $session,
75
    $session ? $session->getId() : 0,
0 ignored issues
show
$session is of type Chamilo\CoreBundle\Entity\Session, thus it always evaluated to true.
Loading history...
76
    null,
77
    null,
78
    true,
79
    0,
80
    false,
81
    $start,
82
    $length
83
);
84
85
$content = '';
86
$content .= '<div class="xapi-students">';
87
88
$loadingMessage = Display::returnFontAwesomeIcon('spinner', '', true, 'fa-pulse').' '.get_lang('Loading');
89
90
foreach ($students as $studentInfo) {
91
    $content .= Display::panelCollapse(
92
        api_get_person_name($studentInfo['firstname'], $studentInfo['lastname']),
93
        $loadingMessage,
94
        "pnl-student-{$studentInfo['id']}",
95
        [
96
            'class' => 'pnl-student',
97
            'data-student' => $studentInfo['id'],
98
            'data-tool' => $toolLaunch->getId(),
99
        ],
100
        "pnl-student-{$studentInfo['id']}-accordion",
101
        "pnl-student-{$studentInfo['id']}-collapse",
102
        false
103
    );
104
}
105
106
$content .= '</div>';
107
$content .= $pagination;
108
109
// View
110
$interbreadcrumb[] = [
111
    'name' => $plugin->get_title(),
112
    'url' => '../start.php',
113
];
114
115
$htmlHeadXtra[] = "<script>
116
    $(function () {
117
        $('.pnl-student').on('show.bs.collapse', function (e) {
118
            var \$self = \$(this);
119
            var \$body = \$self.find('.panel-body');
120
121
            if (!\$self.data('loaded')) {
122
                $.post(
123
                    'stats_attempts.ajax.php?' + _p.web_cid_query,
124
                    \$self.data(),
125
                    function (response) {
126
                        \$self.data('loaded', true);
127
                        \$body.html(response);
128
                    }
129
                );
130
            }
131
        });
132
133
        $('.xapi-students').on('click', '.btn_xapi_attempt_detail', function (e) {
134
            e.preventDefault();
135
136
            var \$self = \$(this)
137
                .addClass('disabled')
138
                .html('".$loadingMessage."');
139
140
            $.post(
141
                'stats_statements.ajax.php?' + _p.web_cid_query,
142
                \$self.data(),
143
                function (response) {
144
                    \$self.replaceWith(response);
145
                }
146
            );
147
        });
148
    })
149
</script>";
150
151
$actions = Display::url(
152
    Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
153
    "../start.php?$cidReq"
154
);
155
156
$view = new Template($toolLaunch->getTitle());
157
$view->assign(
158
    'actions',
159
    Display::toolbarAction('xapi_actions', [$actions])
160
);
161
$view->assign('header', $toolLaunch->getTitle());
162
$view->assign('content', $content);
163
$view->display_one_col_template();
164