3 namespace wcf\data\conversation
;
5 use wcf\data\user\UserProfile
;
6 use wcf\data\user\UserProfileList
;
10 * Represents a list of conversation participants.
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
17 class ConversationParticipantList
extends UserProfileList
23 public $conversationID = 0;
31 * Creates a new ConversationParticipantList object.
33 * @param integer $conversationID
34 * @param integer $userID
35 * @param boolean $isAuthor true if given user is the author of this conversation
37 public function __construct($conversationID, $userID = 0, $isAuthor = false)
39 parent
::__construct();
41 $this->conversationID
= $conversationID;
42 $this->getConditionBuilder()->add('conversation_to_user.conversationID = ?', [$conversationID]);
45 $this->getConditionBuilder()->add(
46 '(conversation_to_user.isInvisible = 0 OR conversation_to_user.participantID = ?)',
50 $this->getConditionBuilder()->add(
51 'conversation_to_user.isInvisible = 0'
55 $this->sqlConditionJoins
.= " LEFT JOIN wcf" . WCF_N
. "_user user_table ON (user_table.userID = conversation_to_user.participantID)";
57 if (!empty($this->sqlSelects
)) {
58 $this->sqlSelects
.= ',';
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 . ")";
67 public function countObjects()
69 $sql = "SELECT COUNT(*) AS count
70 FROM wcf" . WCF_N
. "_conversation_to_user conversation_to_user
71 " . $this->sqlConditionJoins
. "
72 " . $this->getConditionBuilder()->__toString();
73 $statement = WCF
::getDB()->prepareStatement($sql);
74 $statement->execute($this->getConditionBuilder()->getParameters());
75 $row = $statement->fetchArray();
83 public function readObjectIDs()
85 $this->objectIDs
= [];
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
: '');
91 $statement = WCF
::getDB()->prepareStatement($sql, $this->sqlLimit
, $this->sqlOffset
);
92 $statement->execute($this->getConditionBuilder()->getParameters());
93 $this->objectIDs
= $statement->fetchAll(\PDO
::FETCH_COLUMN
);
99 public function readObjects()
101 parent
::readObjects();
103 // check for deleted users
104 $sql = "SELECT username
105 FROM wcf" . WCF_N
. "_conversation_to_user
106 WHERE conversationID = ?
107 AND participantID IS NULL";
108 $statement = WCF
::getDB()->prepareStatement($sql);
109 $statement->execute([$this->conversationID
]);
111 while ($row = $statement->fetchArray()) {
112 // create fake user profiles
113 $this->objects
['x' . (++
$i)] = UserProfile
::getGuestUserProfile($row['username']);
114 $this->indexToObject
[] = 'x' . $i;