Commit | Line | Data |
---|---|---|
ba1ab5e5 | 1 | <?php |
fea86294 | 2 | |
530c5f83 | 3 | namespace wcf\data\conversation; |
fea86294 | 4 | |
07e90692 | 5 | use wcf\data\user\UserProfile; |
530c5f83 MW |
6 | use wcf\data\user\UserProfileList; |
7 | use wcf\system\WCF; | |
8 | ||
db864366 MS |
9 | /** |
10 | * Represents a list of conversation participants. | |
fea86294 TD |
11 | * |
12 | * @author Marcel Werk | |
13 | * @copyright 2001-2019 WoltLab GmbH | |
14 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
15 | * @package WoltLabSuite\Core\Data\Conversation | |
db864366 | 16 | */ |
fea86294 TD |
17 | class ConversationParticipantList extends UserProfileList |
18 | { | |
19 | /** | |
20 | * conversation id | |
21 | * @var integer | |
22 | */ | |
23 | public $conversationID = 0; | |
24 | ||
25 | /** | |
26 | * @inheritDoc | |
27 | */ | |
28 | public $sqlLimit = 0; | |
29 | ||
30 | /** | |
31 | * Creates a new ConversationParticipantList object. | |
32 | * | |
33 | * @param integer $conversationID | |
34 | * @param integer $userID | |
35 | * @param boolean $isAuthor true if given user is the author of this conversation | |
36 | */ | |
37 | public function __construct($conversationID, $userID = 0, $isAuthor = false) | |
38 | { | |
39 | parent::__construct(); | |
40 | ||
41 | $this->conversationID = $conversationID; | |
42 | $this->getConditionBuilder()->add('conversation_to_user.conversationID = ?', [$conversationID]); | |
43 | if (!$isAuthor) { | |
44 | if ($userID) { | |
45 | $this->getConditionBuilder()->add( | |
46 | '(conversation_to_user.isInvisible = 0 OR conversation_to_user.participantID = ?)', | |
47 | [$userID] | |
48 | ); | |
49 | } else { | |
50 | $this->getConditionBuilder()->add( | |
51 | 'conversation_to_user.isInvisible = 0' | |
52 | ); | |
53 | } | |
54 | } | |
55 | $this->sqlConditionJoins .= " LEFT JOIN wcf" . WCF_N . "_user user_table ON (user_table.userID = conversation_to_user.participantID)"; | |
56 | ||
57 | if (!empty($this->sqlSelects)) { | |
58 | $this->sqlSelects .= ','; | |
59 | } | |
60 | $this->sqlSelects = 'conversation_to_user.*'; | |
61 | $this->sqlJoins .= " LEFT JOIN wcf" . WCF_N . "_conversation_to_user conversation_to_user ON (conversation_to_user.participantID = user_table.userID AND conversation_to_user.conversationID = " . $conversationID . ")"; | |
62 | } | |
63 | ||
fea86294 TD |
64 | /** |
65 | * @inheritDoc | |
66 | */ | |
67 | public function countObjects() | |
68 | { | |
8fbd8b01 MS |
69 | $sql = "SELECT COUNT(*) AS count |
70 | FROM wcf" . WCF_N . "_conversation_to_user conversation_to_user | |
71 | " . $this->sqlConditionJoins . " | |
72 | " . $this->getConditionBuilder()->__toString(); | |
fea86294 TD |
73 | $statement = WCF::getDB()->prepareStatement($sql); |
74 | $statement->execute($this->getConditionBuilder()->getParameters()); | |
75 | $row = $statement->fetchArray(); | |
76 | ||
77 | return $row['count']; | |
78 | } | |
79 | ||
fea86294 TD |
80 | /** |
81 | * @inheritDoc | |
82 | */ | |
83 | public function readObjectIDs() | |
84 | { | |
85 | $this->objectIDs = []; | |
8fbd8b01 MS |
86 | $sql = "SELECT conversation_to_user.participantID AS objectID |
87 | FROM wcf" . WCF_N . "_conversation_to_user conversation_to_user | |
88 | " . $this->sqlConditionJoins . " | |
89 | " . $this->getConditionBuilder()->__toString() . " | |
90 | " . (!empty($this->sqlOrderBy) ? "ORDER BY " . $this->sqlOrderBy : ''); | |
fea86294 TD |
91 | $statement = WCF::getDB()->prepareStatement($sql, $this->sqlLimit, $this->sqlOffset); |
92 | $statement->execute($this->getConditionBuilder()->getParameters()); | |
93 | $this->objectIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); | |
94 | } | |
95 | ||
96 | /** | |
97 | * @inheritDoc | |
98 | */ | |
99 | public function readObjects() | |
100 | { | |
101 | parent::readObjects(); | |
102 | ||
103 | // check for deleted users | |
8fbd8b01 MS |
104 | $sql = "SELECT username |
105 | FROM wcf" . WCF_N . "_conversation_to_user | |
106 | WHERE conversationID = ? | |
107 | AND participantID IS NULL"; | |
fea86294 TD |
108 | $statement = WCF::getDB()->prepareStatement($sql); |
109 | $statement->execute([$this->conversationID]); | |
110 | $i = 0; | |
111 | while ($row = $statement->fetchArray()) { | |
112 | // create fake user profiles | |
113 | $this->objects['x' . (++$i)] = UserProfile::getGuestUserProfile($row['username']); | |
114 | $this->indexToObject[] = 'x' . $i; | |
115 | } | |
116 | } | |
530c5f83 | 117 | } |