8 require_once(CH_DIRECTORY_PATH_CLASSES .
'ChWsbModuleDb.php');
21 parent::__construct();
23 $this->_oConfig = $oConfig;
24 $this->sTablePrefix = $oConfig->getDbPrefix();
38 $iSenderId = (int)$iSenderId;
39 $iRecipientId = (int)$iRecipientId;
45 `{$this -> sTablePrefix}messages`
47 `SenderID` = {$iSenderId},
48 `RecipientID` = {$iRecipientId},
49 `Message` = '{$sMessage}'
52 return (
int)$this->
query($sQuery) > 0 ? $this->
lastId() :
false;
64 $iRecipientId = (int)$iRecipientId;
65 $iLoggedMember = (int)$iLoggedMember;
73 `{$this -> sTablePrefix}messages`
76 `SenderID` = {$iLoggedMember}
78 `RecipientID` = {$iRecipientId}
82 `SenderID` = {$iRecipientId}
84 `RecipientID` = {$iLoggedMember}
91 $iSenderId = $this->
getOne($sQuery);
92 $sFieldId = ($iSenderId == $iLoggedMember) ?
'SenderStatus' :
'RecipientStatus';
97 `{$this -> sTablePrefix}messages`
99 `{$sFieldId}` = 'close'
102 `SenderID` = {$iLoggedMember}
104 `RecipientID` = {$iRecipientId}
108 `SenderID` = {$iRecipientId}
110 `RecipientID` = {$iLoggedMember}
117 return $this->
query($sQuery);
133 `{$this -> sTablePrefix}messages`
135 `SenderID` = {$iProfileId}
137 `RecipientID` = {$iProfileId}
140 $this->
query($sQuery);
153 $iSender = (int)$iSender;
154 $iRecipient = (int)$iRecipient;
155 $iAllowCountMessages = (int)$iAllowCountMessages;
162 `{$this -> sTablePrefix}messages`
165 `SenderID` = {$iSender}
167 `RecipientID` = {$iRecipient}
171 `SenderID` = {$iRecipient}
173 `RecipientID` = {$iSender}
177 $iMessageCount = (int)$this->
getOne($sQuery);
178 if ($iMessageCount > $iAllowCountMessages) {
180 $iRowsDelete = $iMessageCount - $iAllowCountMessages;
185 `{$this -> sTablePrefix}messages`
188 `SenderID` = {$iSender}
190 `RecipientID` = {$iRecipient}
194 `SenderID` = {$iRecipient}
196 `RecipientID` = {$iSender}
202 $this->
query($sQuery);
215 $iRecipient = (int)$iRecipient;
216 $iSender = (int)$iSender;
223 `{$this -> sTablePrefix}messages`
226 `SenderID` = {$iSender}
228 `RecipientID` = {$iRecipient}
230 `SenderID` = {$iRecipient}
232 `RecipientID` = {$iSender}
239 return $this->
getOne($sQuery);
251 $iSender = (int)$iSender;
256 DISTINCT IF(`{$this -> sTablePrefix}messages`.`SenderID` = {$iSender}, `{$this -> sTablePrefix}messages`.`RecipientID`, `{$this -> sTablePrefix}messages`.`SenderID`) AS `RecipientID`
258 `{$this -> sTablePrefix}messages`
262 `Profiles`.`ID` = {$iSender}
264 `{$this -> sTablePrefix}messages`.`RecipientID` = {$iSender}
266 `{$this -> sTablePrefix}messages`.`SenderID` = {$iSender}
269 $aSenders = $this->
getAll($sQuery);
270 $aProcessedSenders = array();
273 foreach ($aSenders
as $iKey => $aItems) {
274 $aItems[
'RecipientID'] = (int)$aItems[
'RecipientID'];
279 IF(`SenderID` = {$aItems['RecipientID']}, `SenderStatus`, `RecipientStatus`) AS `Status`
281 `{$this -> sTablePrefix}messages`
284 `RecipientID` = {$aItems['RecipientID']}
286 `SenderID` = {$iSender}
290 `RecipientID` = {$iSender}
292 `SenderID` = {$aItems['RecipientID']}
299 if ($this->
getOne($sQuery) !=
'close') {
300 $aProcessedSenders[] = $aItems[
'RecipientID'];
304 return $aProcessedSenders;
316 $iRecipient = (int)$iRecipient;
317 $iSender = (int)$iSender;
324 `{$this -> sTablePrefix}messages`
327 `SenderID` = {$iSender}
329 `RecipientID` = {$iRecipient}
333 `SenderID` = {$iRecipient}
335 `RecipientID` = {$iSender}
339 return $this->
getOne($sQuery);
357 function getHistoryList(&$aCoreSettings, $iRecipient, $iSender, $iLastMessageId = 0, $iMessageLimit = 0)
359 $iRecipient = (int)$iRecipient;
360 $iSender = (int)$iSender;
361 $iLastMessageId = (int)$iLastMessageId;
362 $iMessageLimit = (int)$iMessageLimit;
365 $sRowsLimit = ($iMessageLimit) ?
" LIMIT {$iMessageLimit}" :
null;
368 if ($aCoreSettings[
'save_chat_history'] && !$sRowsLimit) {
371 $iLimitFrom = $iMessagesCount - $aCoreSettings[
'number_visible_messages'];
372 $sRowsLimit =
" LIMIT {$iLimitFrom}, 18446744073709551615";
378 `ID`, `Message`, `SenderID`,
379 `RecipientID`, UNIX_TIMESTAMP(`Date`) AS `DateTS`
381 `{$this -> sTablePrefix}messages`
385 `SenderID` = {$iSender}
387 `RecipientID` = {$iRecipient}
391 `SenderID` = {$iRecipient}
393 `RecipientID` = {$iSender}
398 `ID` > {$iLastMessageId}
405 return $this->
getAll($sQuery);
418 $iRecipientId = (int)$iRecipientId;
422 if ($aRegBoxes && is_array($aRegBoxes)) {
423 foreach ($aRegBoxes
as $iKey => $aItem) {
425 $sFilter .=
" AND (`{$this -> sTablePrefix}messages`.`SenderID` <> {$iKey} AND `{$this -> sTablePrefix}messages`.`RecipientID` <> {$iKey})";
432 DISTINCT IF(`{$this -> sTablePrefix}messages`.`SenderID` = {$iRecipientId}, `{$this -> sTablePrefix}messages`.`RecipientID`, `{$this -> sTablePrefix}messages`.`SenderID`) AS `RecipientID`
434 `{$this -> sTablePrefix}messages`
438 `Profiles`.`ID` = `RecipientID`
441 `{$this -> sTablePrefix}messages`.`RecipientID` = {$iRecipientId}
443 `{$this -> sTablePrefix}messages`.`SenderID` = {$iRecipientId}
448 $aSenders = $this->
getAll($sQuery);
449 $aProcessedSenders = array();
452 foreach ($aSenders
as $iKey => $aItems) {
453 $aItems[
'RecipientID'] = (int)$aItems[
'RecipientID'];
458 IF(`SenderID` = {$aItems['RecipientID']}, `SenderStatus`, `RecipientStatus`) AS `Status`
460 `{$this -> sTablePrefix}messages`
463 `RecipientID` = {$aItems['RecipientID']}
465 `SenderID` = {$iRecipientId}
469 `RecipientID` = {$iRecipientId}
471 `SenderID` = {$aItems['RecipientID']}
478 if ($this->
getOne($sQuery) !=
'close') {
479 $aProcessedSenders[] = $aItems[
'RecipientID'];
483 return $aProcessedSenders;
495 $iGroupValue = (int)$iGroupValue;
497 $sQuery =
"SELECT COUNT(*) FROM `{$this -> sTablePrefix}privacy` WHERE `author_id` = {$iMemberId}";
498 if ($this->
getOne($sQuery)) {
500 $sQuery =
"UPDATE `{$this -> sTablePrefix}privacy` SET `allow_contact_to` = {$iGroupValue} WHERE `author_id` = {$iMemberId}";
501 $this->
query($sQuery);
504 $sQuery =
"INSERT INTO `{$this -> sTablePrefix}privacy` SET `allow_contact_to` = {$iGroupValue}, `author_id` = {$iMemberId}";
505 $this->
query($sQuery);
519 $sQuery =
"SELECT `allow_contact_to` FROM `{$this -> sTablePrefix}privacy` WHERE `author_id` = {$iMemberId}";
521 return $this->
getOne($sQuery);