aboutsummaryrefslogtreecommitdiff
path: root/lib/modules/ActivityFeed.php
blob: 62762b6b3cd2ccfb860dc6cf6f9e87bf83f13879 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
 * @author      André Klaßen <klassen@elan-ev.de>
 * @author      Till Glöggler <tgloeggl@uos.de>
 * @license     GPL 2 or later
 */
class ActivityFeed extends CorePlugin implements PortalPlugin
{
    public function getPluginName()
    {
        return _('Aktivitäten');
    }

    public function getMetadata()
    {
        return [
            'description' => _('Mit diesem Widget haben Sie alle Aktivitäten im Überblick.')
        ];
    }

    public function getPortalTemplate()
    {
        $template = $GLOBALS['template_factory']->open('start/activityfeed');

        $template->user_id = $GLOBALS['user']->id;
        $template->scrolledfrom = strtotime('+1 day');
        $template->config = UserConfig::get($GLOBALS['user']->id)->getValue('ACTIVITY_FEED');

        $navigation = new Navigation('', 'dispatch.php/activityfeed/configuration');
        $navigation->setImage(Icon::create('edit', 'clickable', ["title" => _('Konfigurieren')]), ['data-dialog'=>'size=auto']);
        $icons[] = $navigation;

        $navigation = new Navigation('', '#', ['cid' => null]);
        $navigation->setImage(Icon::create('person-online', 'clickable'));
        $navigation->setLinkAttributes([
            'id'    => 'toggle-user-activities',
            'title' => _('Eigene Aktivitäten ein-/ausblenden'),
        ]);
        $icons[] = $navigation;

        $navigation = new Navigation('', '#', ['cid' => null]);
        $navigation->setImage(Icon::create('no-activity', 'clickable'));
        $navigation->setLinkAttributes([
            'id'    => 'toggle-all-activities',
            'title' => _('Aktivitätsdetails ein-/ausblenden'),
        ]);
        $icons[] = $navigation;

        $template->icons = $icons;

        return $template;
    }

    public static function onEnable($pluginId)
    {
        $errors = [];
        if (!Config::get()->API_ENABLED) {
            $errors[] = sprintf(
                _('Die REST-API ist nicht aktiviert (%s "API_ENABLED")'),
                formatReady(sprintf('[%s]%s',
                    _('Konfiguration'),
                    URLHelper::getLink('dispatch.php/admin/configuration/configuration')
                ))
            );
        } elseif (!RESTAPI\ConsumerPermissions::get('global')->check('/user/:user_id/activitystream', 'get')) {
            $errors[] = sprintf(
                _('Die REST-API-Route ist nicht aktiviert (%s "/user/:user_id/activitystream"")'),
                formatReady(sprintf('[%s]%s',
                    _('Konfiguration'),
                    URLHelper::getLink('dispatch.php/admin/api/permissions')
                ))
            );
        }

        return count($errors) === 0;
    }
}