Example #1
0
 static function get_unread($id)
 {
     global $db;
     $r = User::get_notification($id, 'private');
     if (is_null($r)) {
         $r = (int) $db->get_var("select count(*) from privates where `to` = {$id} and `read` = 0");
         User::reset_notification($id, 'private', $r);
     }
     return $r;
 }
Example #2
0
 static function add_notification($id, $type, $value = 1)
 {
     global $db;
     if (!is_null(User::get_notification($id, $type))) {
         if ($value < 0) {
             $value = abs($value);
             return $db->query("update notifications set counter = counter-{$value} where user={$id} and type = '{$type}' and counter >= {$value}");
         } else {
             return $db->query("insert into notifications (user, type, counter) values ({$id}, '{$type}', {$value}) on duplicate key update counter=counter+{$value}");
         }
     }
     return false;
 }
Example #3
0
 static function get_unread_conversations($user = 0)
 {
     global $db, $globals, $current_user;
     $key = 'p_last_read';
     if (!$user && $current_user->user_id > 0) {
         $user = $current_user->user_id;
     }
     $n = User::get_notification($user, 'post');
     if (is_null($n)) {
         $last_read = intval($db->get_var("select pref_value from prefs where pref_user_id = {$user} and pref_key = '{$key}'"));
         $n = (int) $db->get_var("select count(*) from conversations where conversation_user_to = {$user} and conversation_type = 'post' and conversation_time > FROM_UNIXTIME({$last_read})");
         User::reset_notification($user, 'post', $n);
     }
     return $n;
 }