aboutsummaryrefslogtreecommitdiff
path: root/lib/navigation/MessagingNavigation.php
blob: 77405a03b075c8ef346888c755828040486929b6 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
# Lifter010: TODO
/*
 * MessagingNavigation.php - navigation for messaging area
 *
 * 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.
 *
 * @author      Elmar Ludwig
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 */

class MessagingNavigation extends Navigation
{
    /**
     * Initialize a new Navigation instance.
     */
    public function __construct()
    {

        parent::__construct(_('Nachrichten'));
    }

    public function initItem()
    {
        global $user, $neux;

        parent::initItem();
        $my_messaging_settings = UserConfig::get($user->id)->MESSAGING_SETTINGS;
        $lastVisitedTimestamp = isset($my_messaging_settings['last_box_visit'])?(int)$my_messaging_settings['last_box_visit']:0;

        $query = "SELECT SUM(mkdate > :time AND readed = 0) AS num_new,
                         SUM(readed = 0) AS num_unread,
                         SUM(readed = 1) AS num_read
                  FROM message_user
                  WHERE snd_rec = 'rec' AND user_id = :user_id AND deleted = 0";
        $statement = DBManager::get()->prepare($query);
        $statement->bindValue(':time', $lastVisitedTimestamp);
        $statement->bindValue(':user_id', $GLOBALS['user']->id);
        $statement->execute();
        list($neux, $neum, $altm) = $statement->fetch(PDO::FETCH_NUM);

        $this->setBadgeNumber($neum);

        if ($neux > 0) {
            $tip = sprintf(ngettext('Sie haben %d neue ungelesene Nachricht',
                                    'Sie haben %d neue ungelesene Nachrichten', $neux), $neux);
        } else if ($neum > 1) {
            $tip = sprintf(ngettext('Sie haben %d ungelesene Nachricht',
                                    'Sie haben %d ungelesene Nachrichten', $neum), $neum);
        } else if ($altm > 1) {
            $tip = sprintf(ngettext('Sie haben %d alte empfangene Nachricht',
                                    'Sie haben %d alte empfangene Nachrichten', $altm), $altm);
        } else {
            $tip = _('Sie haben keine alten empfangenen Nachrichten');
        }


        $this->setImage(Icon::create('mail', 'navigation', ["title" => $tip]));
    }

    /**
     * Initialize the subnavigation of this item. This method
     * is called once before the first item is added or removed.
     */
    public function initSubNavigation()
    {
        parent::initSubNavigation();

        $messages = new Navigation(_('Nachrichten'), 'dispatch.php/messages/overview');
        $inbox = new Navigation(_('Eingang'), 'dispatch.php/messages/overview');
        $messages->addSubNavigation('inbox', $inbox);
        $messages->addSubNavigation('sent', new Navigation(_('Gesendet'), 'dispatch.php/messages/sent'));
        $this->addSubNavigation('messages', $messages);

        if ($GLOBALS['perm']->have_perm('tutor') && \MassMail\MassMailPermission::has(User::findCurrent()->id)) {
            $massmail = new Navigation(_('Nachrichten an Zielgruppen'), 'dispatch.php/massmail/message');
            $massmail->addSubNavigation(
                'message',
                new Navigation(_('Nachricht schreiben'), 'dispatch.php/massmail/message')
            );
            $massmail->addSubNavigation(
                'overview',
                new Navigation(_('Nachrichtenübersicht'), 'dispatch.php/massmail/overview')
            );
            if (\MassMail\MassMailPermission::has(User::findCurrent()->id, true)) {
                $massmail->addSubNavigation(
                    'permissions',
                    new Navigation(_('Berechtigungen'), 'dispatch.php/massmail/permissions')
                );
                $massmail->addSubNavigation(
                    'settings',
                    new Navigation(_('Einstellungen'), 'dispatch.php/massmail/settings')
                );
            }
            $this->addSubNavigation('massmail', $massmail);
        }

    }
}