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 if (isset($this->messageCache
[$objectID])) {
70 return $this->messageCache
[$objectID];
77 public function getJoins()
79 return " JOIN wcf" . WCF_N
. "_conversation_to_user conversation_to_user
80 ON conversation_to_user.participantID = " . WCF
::getUser()->userID
. "
81 AND conversation_to_user.conversationID = " . $this->getTableName() . ".conversationID
82 LEFT JOIN wcf" . WCF_N
. "_conversation conversation
83 ON conversation.conversationID = " . $this->getTableName() . ".conversationID";
89 public function getTableName()
91 return 'wcf' . WCF_N
. '_conversation_message';
97 public function getIDFieldName()
99 return $this->getTableName() . '.messageID';
105 public function getSubjectFieldName()
107 return 'conversation.subject';
113 public function getConditions(?IForm
$form = null)
115 $conditionBuilder = new PreparedStatementConditionBuilder();
116 $conditionBuilder->add('conversation_to_user.hideConversation IN (0,1)');
118 if (isset($_POST['conversationID'])) {
119 $this->conversationID
= \
intval($_POST['conversationID']);
121 $conditionBuilder->add('conversation.conversationID = ?', [$this->conversationID
]);
124 return $conditionBuilder;
130 public function isAccessible()
132 if (!WCF
::getUser()->userID
) {
135 if (!MODULE_CONVERSATION
) {
139 return WCF
::getSession()->getPermission('user.conversation.canUseConversation');
145 public function getFormTemplateName()
147 if ($this->conversation
) {
148 return 'searchConversationMessage';
155 public function show(?IForm
$form = null)
157 /** @var SearchForm $form */
159 // get existing values
162 && isset($form->searchData
['additionalData']['com.woltlab.wcf.conversation.message']['conversationID'])
164 $this->conversationID
= $form->searchData
['additionalData']['com.woltlab.wcf.conversation.message']['conversationID'];
166 if ($this->conversationID
) {
167 $this->conversation
= Conversation
::getUserConversation($this->conversationID
, WCF
::getUser()->userID
);
169 if ($this->conversation
=== null ||
!$this->conversation
->canRead()) {
170 $this->conversationID
= 0;
171 $this->conversation
= null;
176 WCF
::getTPL()->assign('searchedConversation', $this->conversation
);