2 namespace wcf\data\conversation
;
3 use wcf\data\user\UserProfile
;
4 use wcf\data\user\UserProfileList
;
8 * Represents a list of conversation participants.
11 * @copyright 2001-2018 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\Data\Conversation
15 class ConversationParticipantList
extends UserProfileList
{
20 public $conversationID = 0;
28 * Creates a new ConversationParticipantList object.
30 * @param integer $conversationID
31 * @param integer $userID
32 * @param boolean $isAuthor true if given user is the author of this conversation
34 public function __construct($conversationID, $userID = 0, $isAuthor = false) {
35 parent
::__construct();
37 $this->conversationID
= $conversationID;
38 $this->getConditionBuilder()->add('conversation_to_user.conversationID = ?', [$conversationID]);
41 $this->getConditionBuilder()->add('(conversation_to_user.isInvisible = 0 OR conversation_to_user.participantID = ?)', [$userID]);
44 $this->getConditionBuilder()->add('conversation_to_user.isInvisible = 0');
47 $this->sqlConditionJoins
.= " LEFT JOIN wcf".WCF_N
."_user user_table ON (user_table.userID = conversation_to_user.participantID)";
49 if (!empty($this->sqlSelects
)) $this->sqlSelects
.= ',';
50 $this->sqlSelects
= 'conversation_to_user.*';
51 $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.")";
54 /** @noinspection PhpMissingParentCallCommonInspection */
58 public function countObjects() {
59 $sql = "SELECT COUNT(*) AS count
60 FROM wcf".WCF_N
."_conversation_to_user conversation_to_user
61 ".$this->sqlConditionJoins
."
62 ".$this->getConditionBuilder()->__toString();
63 $statement = WCF
::getDB()->prepareStatement($sql);
64 $statement->execute($this->getConditionBuilder()->getParameters());
65 $row = $statement->fetchArray();
69 /** @noinspection PhpMissingParentCallCommonInspection */
73 public function readObjectIDs() {
74 $this->objectIDs
= [];
75 $sql = "SELECT conversation_to_user.participantID AS objectID
76 FROM wcf".WCF_N
."_conversation_to_user conversation_to_user
77 ".$this->sqlConditionJoins
."
78 ".$this->getConditionBuilder()->__toString()."
79 ".(!empty($this->sqlOrderBy
) ?
"ORDER BY ".$this->sqlOrderBy
: '');
80 $statement = WCF
::getDB()->prepareStatement($sql, $this->sqlLimit
, $this->sqlOffset
);
81 $statement->execute($this->getConditionBuilder()->getParameters());
82 $this->objectIDs
= $statement->fetchAll(\PDO
::FETCH_COLUMN
);
88 public function readObjects() {
89 parent
::readObjects();
91 // check for deleted users
92 $sql = "SELECT username
93 FROM wcf".WCF_N
."_conversation_to_user
94 WHERE conversationID = ?
95 AND participantID IS NULL";
96 $statement = WCF
::getDB()->prepareStatement($sql);
97 $statement->execute([$this->conversationID
]);
99 while ($row = $statement->fetchArray()) {
100 // create fake user profiles
101 $this->objects
['x'.(++
$i)] = UserProfile
::getGuestUserProfile($row['username']);
102 $this->indexToObject
[] = 'x'.$i;