<?php
/*
[UCenter Home] (C) 2007-2008 Comsenz Inc.
$Id: Notifications.php 9878 2008-11-19 07:07:58Z zhouguoqiang $
*/
if(!defined('IN_UCHOME')) {
exit('Access Denied');
}
class Notifications extends MyBase {
function get($uId) {
global $_SGLOBAL;
$notify = $result = array();
$result = array(
'message' => array(
'unread' => 0,
'mostRecent' => 0
),
'notification' => array(
'unread' => 0 ,
'mostRecent' => 0
),
'friendRequest' => array(
'uIds' => array()
)
);
//֪ͨ
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('notification')." WHERE uid='$uId' AND new='1' ORDER BY id DESC");
$i = 0;
while($value = $_SGLOBAL['db']->fetch_array($query)) {
$i++;
if(!$result['notification']['mostRecent']) $result['notification']['mostRecent'] = $value['dateline'];
}
$result['notification']['unread'] = $i;
//¶ÌÏûÏ¢
include_once S_ROOT.'./uc_client/client.php';
$pmarr = uc_pm_list($uId, 1, 1, 'newbox', 'newpm');
if($pmarr['count']) {
$result['message']['unread'] = $pmarr['count'];
$result['message']['mostRecent'] = $pmarr['data'][0]['dateline'];
}
// ºÃÓÑ
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('friend')." WHERE fuid='$uId' AND status='0' ORDER BY dateline DESC");
$fIds = array();
while($value = $_SGLOBAL['db']->fetch_array($query)) {
if(!$result['friendRequest']['mostRecent']) {
$result['friendRequest']['mostRecent'] = $value['dateline'];
}
$fIds[] = $value['uid'];
}
$result['friendRequest']['uIds'] = $fIds;
return new APIResponse($result);
}
function send($uId, $recipientIds, $appId, $notification) {
global $_SGLOBAL;
//¹ýÂ˺ÚÃûµ¥ÖеÄÓû§
$blacklist = $result = array();
// ÔÊÐíÄäÃû·¢ËÍ
if ($uId) {
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('blacklist')." WHERE uid IN ('".implode("','", $recipientIds)."') AND buid='$uId'");
while($value = $_SGLOBAL['db']->fetch_array($query)) {
$blacklist[$value['uid']] = $value['uid'];
}
}
include_once(S_ROOT.'./source/function_cp.php');
foreach($recipientIds as $recipientId) {
$val = intval($recipientId);
if($val && empty($blacklist[$val])) {
$result[$val] = notification_add($val, $appId, $notification, 1);
} else {
$result[$recipientId] = null;
}
}
return new APIResponse($result);
}
}
?>