Notifications.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: Notifications.php 25828 2011-11-23 10:50:40Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class Cloud_Service_Server_Notifications extends Cloud_Service_Server_Restful {
  12. protected static $_instance;
  13. public static function getInstance() {
  14. if (!(self::$_instance instanceof self)) {
  15. self::$_instance = new self();
  16. }
  17. return self::$_instance;
  18. }
  19. public function onNotificationsSend($uId, $recipientIds, $appId, $notification) {
  20. $this->getUserSpace($uId);
  21. $result = array();
  22. foreach($recipientIds as $recipientId) {
  23. $val = intval($recipientId);
  24. if($val) {
  25. if ($uId) {
  26. $result[$val] = notification_add($val, $appId, $notification) === null;
  27. } else {
  28. $result[$val] = notification_add($val, $appId, $notification, array(), 1) === null;
  29. }
  30. } else {
  31. $result[$recipientId] = null;
  32. }
  33. }
  34. return $result;
  35. }
  36. public function onNotificationsGet($uId) {
  37. $notify = $result = array();
  38. $result = array(
  39. 'message' => array(
  40. 'unread' => 0,
  41. 'mostRecent' => 0
  42. ),
  43. 'notification' => array(
  44. 'unread' => 0 ,
  45. 'mostRecent' => 0
  46. ),
  47. 'friendRequest' => array(
  48. 'uIds' => array()
  49. )
  50. );
  51. $i = 0;
  52. foreach(C::t('home_notification')->fetch_all_by_uid($uId, 1) as $value) {
  53. $i++;
  54. if(!$result['notification']['mostRecent']) $result['notification']['mostRecent'] = $value['dateline'];
  55. }
  56. $result['notification']['unread'] = $i;
  57. loaducenter();
  58. $pmarr = uc_pm_list($uId, 1, 1, 'newbox', 'newpm');
  59. if($pmarr['count']) {
  60. $result['message']['unread'] = $pmarr['count'];
  61. $result['message']['mostRecent'] = $pmarr['data'][0]['dateline'];
  62. }
  63. $fIds = array();
  64. foreach(C::t('home_friend_request')->fetch_all_by_uid($uId) as $value) {
  65. if(!$result['friendRequest']['mostRecent']) {
  66. $result['friendRequest']['mostRecent'] = $value['dateline'];
  67. }
  68. $fIds[] = $value['uid'];
  69. }
  70. $result['friendRequest']['uIds'] = $fIds;
  71. return $result;
  72. }
  73. }