Passed
Pull Request — 1.11.x (#4616)
by Angel Fernando Quiroz
09:25 queued 48s
created

hookItemVisibility()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 28
rs 9.7666
cc 3
nc 3
nop 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Entity\Portfolio;
6
use Chamilo\PluginBundle\ExternalNotificationConnect\Traits\RequestTrait\RequestTrait;
7
8
class ExternalNotificationConnectPortfolioItemVisibilityHookObserver extends ExternalNotificationConnectHookObserver implements HookPortfolioItemVisibilityObserverInterface
9
{
10
    use RequestTrait;
11
12
    /**
13
     * {@inheritDoc}
14
     */
15
    public function hookItemVisibility(HookPortfolioItemVisibilityEventInterface $event)
16
    {
17
        /** @var Portfolio $item */
18
        $item = $event->getEventData()['item'];
19
        $recipients = $event->getEventData()['recipients'];
20
21
        try {
22
            $json = $this->doVisibilityRequest(
23
                [
24
                    'content_id' => $item->getId(),
25
                    'content_type' => 'eportfolio',
26
                    'visibility' => $item->getVisibility(),
27
                    'user_list' => $recipients,
28
                ]
29
            );
30
        } catch (Exception $e) {
31
            Display::addFlash(
32
                Display::return_message($e->getMessage(), 'error')
33
            );
34
35
            return;
36
        }
37
38
        if (empty($json)) {
39
            return;
40
        }
41
42
        error_log('ExtNotifConn: Portfolio item visibility: ID '.$json['data']['notification_id']);
43
    }
44
}
45