1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-29 04:55:02 +03:00

fix активности - не все события учитывались

This commit is contained in:
Mzhelskiy Maxim 2012-04-14 14:06:23 +04:00
parent daa1c7237c
commit 2ec7c69227
2 changed files with 45 additions and 17 deletions

View file

@ -37,16 +37,16 @@ class ModuleStream extends Module {
* @var array
*/
protected $aEventTypes = array(
'add_wall' => array('related' => 'wall'),
'add_topic' => array('related' => 'topic'),
'add_comment' => array('related' => 'comment'),
'add_blog' => array('related' => 'blog'),
'add_wall' => array('related' => 'wall','unique'=>true),
'add_topic' => array('related' => 'topic','unique'=>true),
'add_comment' => array('related' => 'comment','unique'=>true),
'add_blog' => array('related' => 'blog','unique'=>true),
'vote_topic' => array('related' => 'topic'),
'vote_comment' => array('related' => 'comment'),
'vote_blog' => array('related' => 'blog'),
'vote_user' => array('related' => 'user'),
'add_friend' => array('related' => 'user'),
'join_blog' => array('related' => 'blog')
'add_friend' => array('related' => 'user','unique_user'=>true),
'join_blog' => array('related' => 'blog','unique_user'=>true)
);
public function Init() {
@ -112,8 +112,8 @@ class ModuleStream extends Module {
* @param unknown_type $iTargetId
* @return unknown
*/
public function GetEventByTarget($sEventType, $iTargetId) {
return $this->oMapper->GetEventByTarget($sEventType, $iTargetId);
public function GetEventByTarget($sEventType, $iTargetId, $iUserId=null) {
return $this->oMapper->GetEventByTarget($sEventType, $iTargetId, $iUserId);
}
/**
* Запись события в ленту
@ -122,15 +122,42 @@ class ModuleStream extends Module {
* @param type $iTargetId
*/
public function Write($iUserId, $sEventType, $iTargetId, $iPublish=1) {
if ($oEvent=$this->GetEventByTarget($sEventType, $iTargetId)) {
if (!$this->IsAllowEventType($sEventType)) {
return false;
}
$aParams=$this->aEventTypes[$sEventType];
if (isset($aParams['unique']) and $aParams['unique']) {
/**
* Событие уже было
* Проверяем на уникальность
*/
if ($oEvent->getPublish()!=$iPublish) {
$oEvent->setPublish($iPublish);
$this->UpdateEvent($oEvent);
if ($oEvent=$this->GetEventByTarget($sEventType, $iTargetId)) {
/**
* Событие уже было
*/
if ($oEvent->getPublish()!=$iPublish) {
$oEvent->setPublish($iPublish);
$this->UpdateEvent($oEvent);
}
return true;
}
} elseif ($iPublish) {
}
if (isset($aParams['unique_user']) and $aParams['unique_user']) {
/**
* Проверяем на уникальность для конкретного пользователя
*/
if ($oEvent=$this->GetEventByTarget($sEventType, $iTargetId, $iUserId)) {
/**
* Событие уже было
*/
if ($oEvent->getPublish()!=$iPublish) {
$oEvent->setPublish($iPublish);
$this->UpdateEvent($oEvent);
}
return true;
}
}
if ($iPublish) {
/**
* Создаем новое событие
*/
@ -142,6 +169,7 @@ class ModuleStream extends Module {
$oEvent->setPublish($iPublish);
$this->AddEvent($oEvent);
}
return true;
}
/**
* Чтение потока пользователя

View file

@ -25,11 +25,11 @@ class ModuleStream_MapperStream extends Mapper {
return false;
}
public function GetEventByTarget($sEventType, $iTargetId) {
public function GetEventByTarget($sEventType, $iTargetId, $iUserId=null) {
$sql = "SELECT * FROM
".Config::Get('db.table.stream_event')."
WHERE target_id = ?d AND event_type = ? ";
if ($aRow=$this->oDb->selectRow($sql,$iTargetId,$sEventType)) {
WHERE target_id = ?d AND event_type = ? { AND user_id = ?d } ";
if ($aRow=$this->oDb->selectRow($sql,$iTargetId,$sEventType,is_null($iUserId) ? DBSIMPLE_SKIP : $iUserId)) {
return Engine::GetEntity('ModuleStream_EntityEvent',$aRow);
}
return null;