lib.php 2.67 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
6
 *
Francois Marier's avatar
Francois Marier committed
7
8
9
10
 * 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 3 of the License, or
 * (at your option) any later version.
11
 *
Francois Marier's avatar
Francois Marier committed
12
13
14
15
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
16
 *
Francois Marier's avatar
Francois Marier committed
17
18
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
 *
 * @package    mahara
Penny Leach's avatar
Penny Leach committed
21
 * @subpackage notification-internal
22
 * @author     Catalyst IT Ltd
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
25
26
27
28
29
 *
 */

defined('INTERNAL') || die();

30
31
32
class PluginNotificationInternal extends PluginNotification {

    public static function notify_user($user, $data) {
33
        $toinsert = new StdClass;
34
        $toinsert->type = $data->type;
35
36
37
38
39
40
41
        $toinsert->usr = $user->id;
        if (!empty($user->markasread)) {
            $toinsert->read = 1;
        } 
        else {
            $toinsert->read = 0;
        }
42
        $toinsert->message = $data->message;
43
        $toinsert->subject = $data->subject;
Evan Goldenberg's avatar
Evan Goldenberg committed
44
        $toinsert->parent = $data->parent;
45
        $toinsert->ctime = db_format_timestamp(time());
46

47
48
49
50
        if (!empty($data->url)) {
            $toinsert->url = $data->url;
        }
        
51
        return insert_record('notification_internal_activity', $toinsert, 'id', true);
52
    }
53
54
55
56
57
58
    
    /** 
     * this method is only implemented in internal & is used for the header
     */

    public static function unread_count($userid) {
59
60
61
62
63
        static $unreadcount = array();
        if (!isset($unreadcount[$userid])) {
            $unreadcount[$userid] = count_records('notification_internal_activity', 'usr', $userid, 'read', 0);
        }
        return $unreadcount[$userid];
64
    }
65
    
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    public static function get_event_subscriptions() {
        $subscriptions = array(
            (object)array(
                'plugin'       => 'internal',
                'event'        => 'deleteuser',
                'callfunction' => 'deleteuser',
            ),
        );
        return $subscriptions;
    }

    public static function deleteuser($event, $user) {
        delete_records('notification_internal_activity', 'usr', $user['id']);
    }
80
81
82
}

?>