Passed
Pull Request — master (#5629)
by Angel Fernando Quiroz
08:49
created

XApiLearningPathItemViewedHookObserver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 21
c 1
b 0
f 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A hookLearningPathItemViewed() 0 19 2
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
use Chamilo\PluginBundle\XApi\ToolExperience\Statement\LearningPathItemViewed;
8
9
class XApiLearningPathItemViewedHookObserver extends XApiActivityHookObserver implements HookLearningPathItemViewedObserverInterface
10
{
11
    public function hookLearningPathItemViewed(HookLearningPathItemViewedEventInterface $event)
12
    {
13
        $data = $event->getEventData();
14
        $em = Database::getManager();
15
16
        $lpItemView = $em->find('ChamiloCourseBundle:CLpItemView', $data['item_view_id']);
17
        $lpItem = $em->find('ChamiloCourseBundle:CLpItem', $lpItemView->getLpItemId());
18
19
        if ('quiz' == $lpItem->getItemType()) {
20
            return null;
21
        }
22
23
        $lpView = $em->find('ChamiloCourseBundle:CLpView', $lpItemView->getLpViewId());
24
25
        $lpItemViewed = new LearningPathItemViewed($lpItemView, $lpItem, $lpView);
26
27
        $statement = $lpItemViewed->generate();
28
29
        $this->saveSharedStatement($statement);
30
    }
31
}
32