3cead1c0eb1a432626c1b7d13c28df0b7d205a17
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\data\user\notification\recipient;
3 use wcf\data\user\notification\type\UserNotificationType;
4 use wcf\data\user\User;
5 use wcf\data\DatabaseObjectDecorator;
6 use wcf\system\WCF;
7
8 /**
9 * Decorates the user object to provide special functions for handling recipients of user notifications.
10 *
11 * @author Marcel Werk
12 * @copyright 2001-2011 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package com.woltlab.wcf.notification
15 * @subpackage data.user.notification.user
16 * @category Community Framework
17 */
18 class UserNotificationRecipient extends DatabaseObjectDecorator {
19 /**
20 * @see DatabaseObjectDecorator::$baseClass
21 */
22 protected static $baseClass = 'wcf\data\user\User';
23
24 /**
25 * Creates a new UserNotificationRecipient object.
26 *
27 * @param wcf\data\user\User $object
28 */
29 public function __construct(User $object) {
30 parent::__construct($object);
31
32 // get notification types
33 if (!isset($this->object->data['notificationTypes'])) {
34 $this->object->data['notificationTypes'] = array();
35 $sql = "SELECT event_to_user.eventID, notification_type.*
36 FROM wcf".WCF_N."_user_notification_event_to_user event_to_user
37 LEFT JOIN wcf".WCF_N."_user_notification_type notification_type
38 ON (notification_type.notificationTypeID = event_to_user.notificationTypeID)
39 WHERE event_to_user.userID = ?
40 AND event_to_user.enabled = ?";
41 $statement = WCF::getDB()->prepareStatement($sql);
42 $statement->execute(array($this->userID, 1));
43 while ($row = $statement->fetchArray()) {
44 $this->object->data['notificationTypes'][$row['eventID']] = new UserNotificationType(null, $row);
45 }
46 }
47 }
48
49 /**
50 * Returns the enabled notification types for the given event.
51 *
52 * @param integer $eventID
53 * @return array<wcf\data\user\notification\type\UserNotificationType>
54 */
55 public function getNotificationTypes($eventID) {
56 if (isset($this->notificationTypes[$eventID])) {
57 return $this->notificationTypes[$eventID];
58 }
59
60 return array();
61 }
62 }