1: <?php
2: /**
3: * Notifications methods for Horde_Service_Faceboook
4: *
5: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
6: *
7: * @author Michael J. Rubinsky <mrubinsk@horde.org>
8: * @category Horde
9: * @package Service_Facebook
10: */
11: class Horde_Service_Facebook_Notifications extends Horde_Service_Facebook_Base
12: {
13: /**
14: * Returns the outstanding notifications for the session user.
15: *
16: * @return array An assoc array of notification count objects for
17: * 'messages', 'pokes' and 'shares', a uid list of
18: * 'friend_requests', a gid list of 'group_invites',
19: * and an eid list of 'event_invites'
20: * @throws Horde_Service_Facebook_Exception
21: */
22: public function &get()
23: {
24: // Session key is *required*
25: if (!$skey = $this->_facebook->auth->getSessionKey()) {
26: throw new Horde_Service_Facebook_Exception(
27: 'session_key is required',
28: Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
29: }
30:
31: return $this->_facebook->callMethod('facebook.notifications.get');
32: }
33:
34: /**
35: * Sends a notification to the specified users.
36: *
37: * @param mixed $to_ids Either an array of uids or a string
38: * list of uids.
39: * @param string $notification A FBML string for the notification.
40: * @param string $type Either 'user_to_user' or 'app_to_user'
41: *
42: * @throws Horde_Service_Facebook_Exception
43: *
44: * @return string A comma separated list of successful recipients
45: */
46: public function &send($to_ids, $notification, $type)
47: {
48: // Session key is *required*
49: if (!$this->_facebook->auth->getSessionKey()) {
50: throw new Horde_Service_Facebook_Exception(
51: 'session_key is required',
52: Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
53: }
54:
55: return $this->_facebook->callMethod(
56: 'facebook.notifications.send',
57: array('to_ids' => $to_ids,
58: 'notification' => $notification,
59: 'type' => $type));
60: }
61:
62: /**
63: * Sends an email to the specified user of the application.
64: *
65: * @param string $recipients comma-separated ids of the recipients
66: * @param string $subject subject of the email
67: * @param string $text (plain text) body of the email
68: * @param string $fbml fbml markup for an html version of the email
69: *
70: * @throws Horde_Service_Facebook_Exception
71: * @return string A comma separated list of successful recipients
72: * @error
73: * API_EC_PARAM_USER_ID_LIST
74: */
75: public function &sendEmail($recipients, $subject, $text, $fbml)
76: {
77: // Session key is *required*
78: if (!$this->_facebook->auth->getSessionKey()) {
79: throw new Horde_Service_Facebook_Exception(
80: 'session_key is required',
81: Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
82: }
83: return $this->_facebook->callMethod(
84: 'facebook.notifications.sendEmail',
85: array('recipients' => $recipients,
86: 'subject' => $subject,
87: 'text' => $text,
88: 'fbml' => $fbml));
89: }
90:
91: }