8 require_once( CH_DIRECTORY_PATH_CLASSES .
'ChWsbModuleDb.php' );
20 parent::__construct();
22 $this -> _oConfig = $oConfig;
23 $this -> sTablePrefix = $oConfig -> getDbPrefix();
33 $sQuery =
"SELECT * FROM `{$this->sTablePrefix}handlers`";
34 return $this ->
getAll($sQuery);
49 $sWhere =
"WHERE `type` = '{$sType}'";
52 $sQuery =
"SELECT COUNT(*) FROM `{$this->sTablePrefix}data` {$sWhere}";
53 !($iCount = $this ->
getOne($sQuery) ) ? $iCount = 0 :
null;
70 $sWhere =
"WHERE `type` = '{$sType}'";
73 $sQuery =
"SELECT `id` FROM `{$this->sTablePrefix}data` {$sWhere} ORDER BY `id` DESC LIMIT 1";
74 !($iLastEventId = $this ->
getOne($sQuery) ) ? $iLastEventId = 0 :
null;
93 $sWhere =
" AND `ch_spy_data`.`type` = '{$sType}'";
103 `ch_spy_friends_data`
105 `ch_spy_friends_data`.`event_id` = `ch_spy_data`.`id`
107 `ch_spy_friends_data`.`friend_id` = {$iProfileId}
109 `ch_spy_data`.`sender_id` <> {$iProfileId}
112 `ch_spy_data`.`id` DESC LIMIT 1
115 !($iLastEventId = $this ->
getOne($sQuery) ) ? $iLastEventId = 0 :
null;
116 return $iLastEventId;
133 $sWhere =
" AND `ch_spy_data`.`type` = '{$sType}'";
139 COUNT(`ch_spy_data`.`id`)
143 `ch_spy_friends_data`
145 `ch_spy_friends_data`.`event_id` = `ch_spy_data`.`id`
147 `ch_spy_friends_data`.`friend_id` = {$iProfileId}
149 `ch_spy_data`.`sender_id` <> {$iProfileId}
153 !($iCount = $this ->
getOne($sQuery) ) ? $iCount = 0 :
null;
165 return $this ->
getOne(
'SELECT `kateg` FROM `sys_options` WHERE `Name` = "' . $sValueName .
'"');
176 $iActivityId = (int) $iActivityId;
177 $sQuery =
"UPDATE `{$this->sTablePrefix}data` SET `viewed` = 1";
178 $this ->
query($sQuery);
190 $sQuery =
"UPDATE `{$this->sTablePrefix}data` SET `viewed` = 1 WHERE `recipient_id` = {$iProfileId}";
191 $this ->
query($sQuery);
197 foreach($aData[
'handlers']
as $aHandler) {
207 `{$this->sTablePrefix}handlers`
209 `alert_unit` = '{$aHandler['alert_unit']}',
210 `alert_action` = '{$aHandler['alert_action']}',
211 `module_uri` = '{$aHandler['module_uri']}',
212 `module_class` = '{$aHandler['module_class']}',
213 `module_method` = '{$aHandler['module_method']}'
216 $this ->
query($sQuery);
219 $sAlertName = $this -> _oConfig -> getAlertSystemName();
227 `sys_alerts_handlers`
233 $iHandlerId = (int) $this ->
getOne($sQuery, [$sAlertName]);
235 foreach($aData[
'alerts']
as $aAlert) {
244 `unit` = '{$aAlert['unit']}',
245 `action` = '{$aAlert['action']}',
246 `handler_id` = '{$iHandlerId}'
249 $this ->
query($sQuery);
256 foreach($aData[
'handlers']
as $aHandler) {
266 `{$this->sTablePrefix}handlers`
268 `alert_unit` = '{$aHandler['alert_unit']}'
270 `alert_action` = '{$aHandler['alert_action']}'
272 `module_uri` = '{$aHandler['module_uri']}'
274 `module_class` = '{$aHandler['module_class']}'
276 `module_method` = '{$aHandler['module_method']}'
280 $this ->
query($sQuery);
284 $sAlertName = $this -> _oConfig -> getAlertSystemName();
292 `sys_alerts_handlers`
298 $iHandlerId = (int) $this ->
getOne($sQuery, [$sAlertName]);
299 foreach($aData[
'alerts']
as $aAlert) {
308 `unit` = '{$aAlert['unit']}'
310 `action` = '{$aAlert['action']}'
312 `handler_id` = '{$iHandlerId}'
316 $this ->
query($sQuery);
331 function createActivity($sAlertUnit, $sAlertAction, $iObjectId, $iCommentId, $iSenderId, $iRecipientId, $aActivityInfo)
333 $iSenderId = (int) $iSenderId;
334 $iRecipientId = (int) $iRecipientId;
345 `{$this->sTablePrefix}data`
347 `alert_unit` = '{$sAlertUnit}',
348 `alert_action` = '{$sAlertAction}',
349 `object_id` = {$iObjectId},
350 `comment_id` = {$iCommentId},
351 `sender_id` = {$iSenderId},
352 `recipient_id` = {$iRecipientId},
353 `lang_key` = '{$sLangKey}',
354 `params` = '{$aParameters}',
355 `date` = TIMESTAMP( NOW() ),
356 `type` = '{$sActivityType}'
359 $this ->
query($sQuery);
367 $sWhereAddon =
"AND `comment_id`='" . $iCommentId .
"'";
370 `" . $this->sTablePrefix .
"data`
372 `alert_unit`='" . $sUnit .
"' AND
373 `object_id`='" . $iObjectId .
"' " . $sWhereAddon;
375 return $this->
query($sSql);
381 `" . $this->sTablePrefix .
"data`
383 `sender_id`='" . $iUserId .
"' OR
384 `recipient_id`='" . $iUserId .
"'";
386 return $this->
query($sSql);
399 $iEventId = (int) $iEventId;
400 $iSenderId = (int) $iSenderId;
401 $iFriendId = (int) $iFriendId;
406 `{$this->sTablePrefix}friends_data`
408 `event_id` = {$iEventId},
409 `sender_id` = {$iSenderId},
410 `friend_id` = {$iFriendId}
413 $this ->
query($sQuery);
424 $iDays = (int) $iDays;
429 $iAffectedRows = $this ->
query(
"DELETE FROM `{$this->sTablePrefix}data` WHERE `{$this->sTablePrefix}data`.`date` < DATE_SUB(NOW(), INTERVAL $iDays DAY)");
430 $this ->
query(
"OPTIMIZE TABLE `{$this->sTablePrefix}data`");
432 $this ->
query(
"DELETE `{$this->sTablePrefix}friends_data` FROM `{$this->sTablePrefix}friends_data` LEFT JOIN `{$this->sTablePrefix}data` ON (`{$this->sTablePrefix}data`.`id` = `{$this->sTablePrefix}friends_data`.`event_id`) WHERE `{$this->sTablePrefix}data`.`id` IS NULL");
433 $this ->
query(
"OPTIMIZE TABLE `{$this->sTablePrefix}friends_data`");
435 return $iAffectedRows;