3 namespace wcf\system\search
;
5 use wcf\data\conversation\Conversation
;
6 use wcf\data\conversation\message\SearchResultConversationMessage
;
7 use wcf\data\conversation\message\SearchResultConversationMessageList
;
9 use wcf\form\SearchForm
;
10 use wcf\system\database\util\PreparedStatementConditionBuilder
;
14 * An implementation of ISearchableObjectType for searching in conversations.
17 * @copyright 2001-2019 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package WoltLabSuite\Core\System\Search
21 class ConversationMessageSearch
extends AbstractSearchableObjectType
24 * id of the searched conversation
27 public $conversationID = 0;
30 * searched conversation
37 * @var SearchResultConversationMessage[]
39 public $messageCache = [];
44 public function cacheObjects(array $objectIDs, ?
array $additionalData = null)
46 $messageList = new SearchResultConversationMessageList();
47 $messageList->setObjectIDs($objectIDs);
48 $messageList->readObjects();
49 foreach ($messageList->getObjects() as $message) {
50 $this->messageCache
[$message->messageID
] = $message;
57 public function getAdditionalData()
60 'conversationID' => $this->conversationID
,
67 public function getObject($objectID)
69 return $this->messageCache
[$objectID] ??
null;
75 public function getJoins()
77 return " JOIN wcf" . WCF_N
. "_conversation_to_user conversation_to_user
78 ON conversation_to_user.participantID = " . WCF
::getUser()->userID
. "
79 AND conversation_to_user.conversationID = " . $this->getTableName() . ".conversationID
80 LEFT JOIN wcf" . WCF_N
. "_conversation conversation
81 ON conversation.conversationID = " . $this->getTableName() . ".conversationID";
87 public function getTableName()
89 return 'wcf' . WCF_N
. '_conversation_message';
95 public function getIDFieldName()
97 return $this->getTableName() . '.messageID';
103 public function getSubjectFieldName()
105 return 'conversation.subject';
111 public function getConditions(?IForm
$form = null)
113 $conditionBuilder = new PreparedStatementConditionBuilder();
114 $conditionBuilder->add('conversation_to_user.hideConversation IN (0,1)');
116 if (isset($_POST['conversationID'])) {
117 $this->conversationID
= \
intval($_POST['conversationID']);
119 $conditionBuilder->add('conversation.conversationID = ?', [$this->conversationID
]);
122 return $conditionBuilder;
128 public function isAccessible()
130 if (!WCF
::getUser()->userID
) {
133 if (!MODULE_CONVERSATION
) {
137 return WCF
::getSession()->getPermission('user.conversation.canUseConversation');
143 public function getFormTemplateName()
145 if ($this->conversation
) {
146 return 'searchConversationMessage';
153 public function show(?IForm
$form = null)
155 /** @var SearchForm $form */
157 // get existing values
160 && isset($form->searchData
['additionalData']['com.woltlab.wcf.conversation.message']['conversationID'])
162 $this->conversationID
= $form->searchData
['additionalData']['com.woltlab.wcf.conversation.message']['conversationID'];
164 if ($this->conversationID
) {
165 $this->conversation
= Conversation
::getUserConversation($this->conversationID
, WCF
::getUser()->userID
);
167 if ($this->conversation
=== null ||
!$this->conversation
->canRead()) {
168 $this->conversationID
= 0;
169 $this->conversation
= null;
174 WCF
::getTPL()->assign('searchedConversation', $this->conversation
);