Passed
Push — master ( a5405c...c5a2d1 )
by Marcel
02:30
created

NotificationManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 5
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Data Analytics
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @copyright 2019 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\Notification;
13
14
use OCA\Analytics\Controller\DbController;
15
use OCP\IL10N;
16
use OCP\ILogger;
17
use OCP\Notification\IManager as INotificationManager;
18
19
20
class NotificationManager
21
{
22
    const OBJECT_DATASET = 'analytics_dataset';
23
    const OBJECT_DATA = 'analytics_data';
24
    const SUBJECT_THRESHOLD = 'data_threshold';
25
    const SUBJECT_DATASET_DELETE = 'dataset_delete';
26
    const SUBJECT_DATASET_SHARE = 'dataset_share';
27
    const SUBJECT_DATA_ADD = 'data_add';
28
    const SUBJECT_DATA_ADD_API = 'data_add_api';
29
    /** @var INotificationManager */
30
    protected $notificationManager;
31
    private $l10n;
32
    private $userId;
33
    private $DBController;
34
    private $logger;
35
36
    public function __construct(
37
        IL10N $l10n,
38
        DbController $DBController,
39
        $userId,
40
        ILogger $logger,
41
        INotificationManager $notificationManager
42
    )
43
    {
44
        $this->l10n = $l10n;
45
        $this->userId = $userId;
46
        $this->DBController = $DBController;
47
        $this->logger = $logger;
48
        $this->notificationManager = $notificationManager;
49
    }
50
51
    /**
52
     * @param $object
53
     * @param int $object_id
54
     * @param $subject
55
     * @param array $subject_parameter
56
     * @throws \Exception
57
     */
58
    public function triggerNotification($object, $object_id, $subject, $subject_parameter)
59
    {
60
        // $subject_parameter = ['object' => 'Pflanze'];
61
        $notification = $this->notificationManager->createNotification();
62
        $notification->setApp('analytics')
63
            ->setDateTime(new \DateTime())
64
            ->setObject($object, $object_id)
65
            ->setSubject($subject, $subject_parameter)
66
            ->setUser('admin');
67
        $this->notificationManager->notify($notification);
68
    }
69
70
}