6253315f98404e3e643709f0b985cf44631cebf4
[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\UserList;
5 use wcf\data\user\User;
6 use wcf\system\database\util\PreparedStatementConditionBuilder;
7 use wcf\system\WCF;
8
9 /**
10 * Decorates the user object to provide special functions for handling recipients of user notifications.
11 *
12 * @author Marcel Werk
13 * @copyright 2001-2011 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf.notification
16 * @subpackage data.user.notification.user
17 * @category Community Framework
18 */
19 class UserNotificationRecipientList extends UserList {
20 /**
21 * @see wcf\data\DatabaseObjectList\DatabaseObjectList::readObjects()
22 */
23 public function readObjects() {
24 if ($this->objectIDs === null) {
25 $this->readObjectIDs();
26 }
27
28 if (!count($this->objectIDs)) {
29 return;
30 }
31
32 // get notification types
33 $notificationTypes = array();
34 $conditionBuilder = new PreparedStatementConditionBuilder();
35 $conditionBuilder->add('event_to_user.userID IN (?)', array($this->objectIDs));
36 $conditionBuilder->add('event_to_user.enabled = ?', array(1));
37
38 $sql = "SELECT event_to_user.eventID, event_to_user.userID, notification_type.*
39 FROM wcf".WCF_N."_user_notification_event_to_user event_to_user
40 LEFT JOIN wcf".WCF_N."_user_notification_type notification_type
41 ON (notification_type.notificationTypeID = event_to_user.notificationTypeID)
42 ".$conditionBuilder->__toString();
43 $statement = WCF::getDB()->prepareStatement($sql);
44 $statement->execute($conditionBuilder->getParameters());
45 while ($row = $statement->fetchArray()) {
46 $databaseObject = new UserNotificationType(null, $row);
47 $notificationTypes[$row['userID']][$row['eventID']][] = $databaseObject->getProcessor();
48 }
49
50 // get users
51 $sql = "SELECT ".(!empty($this->sqlSelects) ? $this->sqlSelects.',' : '')."
52 ".$this->getDatabaseTableAlias().".*
53 FROM ".$this->getDatabaseTableName()." ".$this->getDatabaseTableAlias()."
54 ".$this->sqlJoins."
55 WHERE ".$this->getDatabaseTableAlias().".".$this->getDatabaseTableIndexName()." IN (?".str_repeat(',?', count($this->objectIDs) - 1).")
56 ".(!empty($this->sqlOrderBy) ? "ORDER BY ".$this->sqlOrderBy : '');
57 $statement = WCF::getDB()->prepareStatement($sql);
58 $statement->execute($this->objectIDs);
59 while ($row = $statement->fetchArray()) {
60 $row['notificationTypes'] = (isset($notificationTypes[$row['userID']]) ? $notificationTypes[$row['userID']] : array());
61 $this->objects[] = new UserNotificationRecipient(new User(null, $row));
62 }
63 }
64 }