Completed
Push — master ( 506c79...7daaad )
by Julito
12:09
created

WhispeakMyStudentsLpTrackingHook::trackingHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class WhispeakMyStudentsLpTrackingHook.
6
 */
7
class WhispeakMyStudentsLpTrackingHook extends HookObserver implements HookMyStudentsLpTrackingObserverInterface
8
{
9
    /**
10
     * WhispeakMyStudentsLpTrackingHook constructor.
11
     */
12
    protected function __construct()
13
    {
14
        parent::__construct(
15
            'plugin/whispeakauth/WhispeakAuthPlugin.php',
16
            'whispeakauth'
17
        );
18
    }
19
20
    /**
21
     * @return array
22
     */
23
    public function trackingHeader(HookMyStudentsLpTrackingEventInterface $hook)
24
    {
25
        return [
26
            'value' => WhispeakAuthPlugin::create()->get_lang('plugin_title'),
27
            'attrs' => ['class' => 'text-center'],
28
        ];
29
    }
30
31
    /**
32
     * @throws \Doctrine\ORM\Query\QueryException
33
     *
34
     * @return array
35
     */
36
    public function trackingContent(HookMyStudentsLpTrackingEventInterface $hook)
37
    {
38
        $data = $hook->getEventData();
39
40
        $totalCount = WhispeakAuthPlugin::countAllAttemptsInLearningPath($data['lp_id'], $data['student_id']);
41
42
        if (0 === $totalCount) {
43
            return [
44
                'value' => '-',
45
                'attrs' => ['class' => 'text-center'],
46
            ];
47
        }
48
49
        $successCount = WhispeakAuthPlugin::countSuccessAttemptsInLearningPath($data['lp_id'], $data['student_id']);
50
51
        $attrs = ['class' => 'text-center '];
52
        $attrs['class'] .= $successCount <= $totalCount / 2 ? 'text-danger' : 'text-success';
53
54
        return [
55
            'value' => Display::tag('strong', "$successCount / $totalCount"),
56
            'attrs' => $attrs,
57
        ];
58
    }
59
}
60