aboutsummaryrefslogtreecommitdiff
path: root/lib/modules/NewsWidget.php
blob: 04f6b08a4c814da6112260eb0fdb2838d7187dbf (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
<?php
/*
 * news.php - News controller
 *
 * Copyright (C) 2014 - Nadine Werner <nadwerner@uos.de>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 */

class NewsWidget extends CorePlugin implements PortalPlugin
{
    public function getPluginName()
    {
        return _('Ankündigungen');
    }

    public function getMetadata()
    {
        return [
            'description' => _('Mit diesem Widget haben Sie Zugriff auf systemweite Ankündigungen.')
        ];
    }

    function getPortalTemplate()
    {
        $controller = app(\Trails\Dispatcher::class)->load_controller('news');
        $response = $controller->relayWithRedirect('news/display/studip');
        $template = $GLOBALS['template_factory']->open('shared/string');
        $template->content = $response->body;
        $icons = [];
        if (StudipNews::CountUnread() > 0) {
            $navigation = new Navigation('', 'dispatch.php/news/visit_all');
            $navigation->setImage(Icon::create('refresh', Icon::ROLE_CLICKABLE, ['title' => _('Alle als gelesen markieren'), 'size' => 20]));
            $navigation->setLinkAttributes(['class' => 'visit-all']);
            $icons[] = $navigation;
        }

        if (Config::get()->NEWS_RSS_EXPORT_ENABLE) {
            if ($rss_id = StudipNews::GetRssIdFromRangeId('studip')) {
                $navigation = new Navigation('', 'rss.php', ['id' => $rss_id]);
                $navigation->setImage(Icon::create('rss', Icon::ROLE_CLICKABLE, ['title' => _('RSS-Feed'), 'size' => 20]));
                $icons[] = $navigation;
            }
        }

        if ($GLOBALS['perm']->have_perm('root')) {
            $navigation = new Navigation('', 'dispatch.php/news/edit_news/new/studip');
            $navigation->setImage(Icon::create('add', Icon::ROLE_CLICKABLE, ['title' => _('Ankündigungen bearbeiten'), 'size' => 20]));
            $navigation->setLinkAttributes(['data-dialog' => '']);

            $icons[] = $navigation;
            if (Config::get()->NEWS_RSS_EXPORT_ENABLE) {
                $navigation = new Navigation('', 'dispatch.php/news/rss_config/studip');
                $navigation->setImage(
                    Icon::create(
                        'admin',
                        Icon::ROLE_CLICKABLE,
                        ['title' => _('RSS-Feed konfigurieren')]
                    ),
                );
                $navigation->setLinkAttributes(['data-dialog' => 'size=auto']);
                $icons[] = $navigation;
            }
        }

        $template->icons = $icons;

        return $template;
    }
}