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

89 lines
3 KiB
PHP
Raw Normal View History

2011-06-06 14:58:19 +03:00
<?php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
2011-06-06 14:58:19 +03:00
class ModuleStream_MapperStream extends Mapper {
2011-06-06 14:58:19 +03:00
public function AddEvent($oObject) {
$sql = "INSERT INTO ".Config::Get('db.table.stream_event')." SET ?a ";
if ($iId=$this->oDb->query($sql,$oObject->_getData())) {
return $iId;
}
return false;
}
public function UpdateEvent($oObject) {
$sql = "UPDATE ".Config::Get('db.table.stream_event')." SET ?a WHERE id = ?d ";
return $this->oDb->query($sql,$oObject->_getData(array('publish')),$oObject->getId());
}
public function getTypesList($iUserId) {
$sql = 'SELECT event_type FROM ' . Config::Get('db.table.stream_user_type') . ' WHERE user_id = ?d';
$aRet = $this->oDb->selectCol($sql, $iUserId);
return $aRet;
}
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 Read($aEventTypes, $aUsersList, $iCount, $iFromId) {
$sql = 'SELECT * FROM ' . Config::Get('db.table.stream_event'). '
WHERE
event_type IN (?a)
AND user_id IN (?a)
{ AND id < ?d }
ORDER BY id DESC
{ LIMIT 0,?d }';
$aReturn=array();
if ($aRows=$this->oDb->select($sql,$aEventTypes,$aUsersList,!is_null($iFromId) ? $iFromId : DBSIMPLE_SKIP,!is_null($iCount) ? $iCount : DBSIMPLE_SKIP)) {
foreach ($aRows as $aRow) {
$aReturn[]=Engine::GetEntity('Stream_Event',$aRow);
}
}
return $aReturn;
}
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);
}
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);
}
}
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
}