1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-05 07:54:24 +03:00
ifhub.club/classes/modules/stream/mapper/Stream.mapper.class.php

77 lines
2.6 KiB
PHP
Raw Normal View History

2011-06-06 14:58:19 +03:00
<?php
class ModuleStream_MapperStream extends Mapper
{
public function subscribeUser($iUserId, $iTargetUserId)
{
$sql = 'SELECT * FROM ' . Config::Get('db.table.stream_subscribe') . ' WHERE
user_id = ?d AND target_user_id = ?d';
if (!$this->oDb->select($sql, $iUserId, $iTargetUserId)) {
$sql = 'INSERT INTO ' . Config::Get('db.table.stream_subscribe') . ' SET
user_id = ?d, target_user_id = ?d';
$this->oDb->query($sql, $iUserId, $iTargetUserId);
}
}
2011-06-06 14:58:19 +03:00
public function unsubscribeUser($iUserId, $iTargetUserId)
{
$sql = 'DELETE FROM ' . Config::Get('db.table.stream_subscribe') . ' WHERE
user_id = ?d AND target_user_id = ?d';
$this->oDb->query($sql, $iUserId, $iTargetUserId);
}
2011-06-06 14:58:19 +03:00
public function read($aEventTypes, $aUsesrList, $iCount, $iFromId)
{
$sql = 'SELECT * FROM ' . Config::Get('db.table.stream_event'). ' WHERE
event_type IN (?a) AND initiator IN (?a)';
$aParams = array($aEventTypes, $aUsesrList);
if ($iFromId) {
$sql .= ' AND id < ?d';
$aParams[] = $iFromId;
}
$sql .= ' ORDER BY id DESC';
if ($iCount) {
$sql .= ' LIMIT 0,?d';
$aParams[] = $iCount;
}
return call_user_func_array(array($this->oDb, 'select'), array_merge(array($sql), $aParams));
}
2011-06-06 14:58:19 +03:00
public function addEvent($oUserId, $sEventType, $iTargetId)
{
$sql = 'INSERT INTO ' . Config::Get('db.table.stream_event'). ' SET
event_type = ?, target_id = ?d, initiator = ?d';
$this->oDb->query($sql, $sEventType, $iTargetId, $oUserId);
}
2011-06-06 14:58:19 +03:00
public function deleteEvent($oUser, $sEventType, $iTargetId)
{
$sql = 'DELETE FROM' . Config::Get('db.table.stream_event'). ' WHERE
event_type = ? AND target_id = ?d AND initiator = ?d';
$this->oDb->query($sql, $sEventType, $iTargetId, $oUser->getId());
}
2011-06-06 14:58:19 +03:00
public function getUserSubscribes($iUserId)
{
$sql = 'SELECT target_user_id FROM ' . Config::Get('db.table.stream_subscribe') . ' WHERE user_id = ?d';
return $this->oDb->selectCol($sql, $iUserId);
}
2011-06-06 14:58:19 +03:00
public function getTypesList($iUserId)
{
$sql = 'SELECT event_type FROM ' . Config::Get('db.table.stream_user_type') . ' WHERE user_id = ?d';
$ret = $this->oDb->selectCol($sql, $iUserId);
return $ret;
}
2011-06-06 14:58:19 +03:00
public function switchUserEventType($iUserId, $sEventType)
{
$sql = 'SELECT * FROM ' . Config::Get('db.table.stream_user_type') . ' WHERE user_id = ?d AND event_type = ?';
if ($this->oDb->select($sql, $iUserId, $sEventType)) {
$sql = 'DELETE FROM ' . Config::Get('db.table.stream_user_type') . ' WHERE user_id = ?d AND event_type = ?';
} else {
$sql = 'INSERT INTO '. Config::Get('db.table.stream_user_type') . ' SET user_id = ?d , event_type = ?';
}
$this->oDb->query($sql, $iUserId, $sEventType);
}
2011-06-06 14:58:19 +03:00
}