Fix title of data section when editing conversation label
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / data / conversation / ConversationParticipantList.class.php
1 <?php
2 namespace wcf\data\conversation;
3 use wcf\data\user\UserProfile;
4 use wcf\data\user\UserProfileList;
5 use wcf\system\WCF;
6
7 /**
8 * Represents a list of conversation participants.
9 *
10 * @author Marcel Werk
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
14 */
15 class ConversationParticipantList extends UserProfileList {
16 /**
17 * conversation id
18 * @var integer
19 */
20 public $conversationID = 0;
21
22 /**
23 * @inheritDoc
24 */
25 public $sqlLimit = 0;
26
27 /**
28 * Creates a new ConversationParticipantList object.
29 *
30 * @param integer $conversationID
31 * @param integer $userID
32 * @param boolean $isAuthor true if given user is the author of this conversation
33 */
34 public function __construct($conversationID, $userID = 0, $isAuthor = false) {
35 parent::__construct();
36
37 $this->conversationID = $conversationID;
38 $this->getConditionBuilder()->add('conversation_to_user.conversationID = ?', [$conversationID]);
39 if (!$isAuthor) {
40 if ($userID) {
41 $this->getConditionBuilder()->add('(conversation_to_user.isInvisible = 0 OR conversation_to_user.participantID = ?)', [$userID]);
42 }
43 else {
44 $this->getConditionBuilder()->add('conversation_to_user.isInvisible = 0');
45 }
46 }
47 $this->sqlConditionJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = conversation_to_user.participantID)";
48
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.")";
52 }
53
54 /** @noinspection PhpMissingParentCallCommonInspection */
55 /**
56 * @inheritDoc
57 */
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();
66 return $row['count'];
67 }
68
69 /** @noinspection PhpMissingParentCallCommonInspection */
70 /**
71 * @inheritDoc
72 */
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);
83 }
84
85 /**
86 * @inheritDoc
87 */
88 public function readObjects() {
89 parent::readObjects();
90
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]);
98 $i = 0;
99 while ($row = $statement->fetchArray()) {
100 // create fake user profiles
101 $this->objects['x'.(++$i)] = UserProfile::getGuestUserProfile($row['username']);
102 $this->indexToObject[] = 'x'.$i;
103 }
104 }
105 }