1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-01 05: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 * @var array
*/ */
protected $aEventTypes = array( protected $aEventTypes = array(
'add_wall' => array('related' => 'wall'), 'add_wall' => array('related' => 'wall','unique'=>true),
'add_topic' => array('related' => 'topic'), 'add_topic' => array('related' => 'topic','unique'=>true),
'add_comment' => array('related' => 'comment'), 'add_comment' => array('related' => 'comment','unique'=>true),
'add_blog' => array('related' => 'blog'), 'add_blog' => array('related' => 'blog','unique'=>true),
'vote_topic' => array('related' => 'topic'), 'vote_topic' => array('related' => 'topic'),
'vote_comment' => array('related' => 'comment'), 'vote_comment' => array('related' => 'comment'),
'vote_blog' => array('related' => 'blog'), 'vote_blog' => array('related' => 'blog'),
'vote_user' => array('related' => 'user'), 'vote_user' => array('related' => 'user'),
'add_friend' => array('related' => 'user'), 'add_friend' => array('related' => 'user','unique_user'=>true),
'join_blog' => array('related' => 'blog') 'join_blog' => array('related' => 'blog','unique_user'=>true)
); );
public function Init() { public function Init() {
@ -112,8 +112,8 @@ class ModuleStream extends Module {
* @param unknown_type $iTargetId * @param unknown_type $iTargetId
* @return unknown * @return unknown
*/ */
public function GetEventByTarget($sEventType, $iTargetId) { public function GetEventByTarget($sEventType, $iTargetId, $iUserId=null) {
return $this->oMapper->GetEventByTarget($sEventType, $iTargetId); return $this->oMapper->GetEventByTarget($sEventType, $iTargetId, $iUserId);
} }
/** /**
* Запись события в ленту * Запись события в ленту
@ -122,15 +122,42 @@ class ModuleStream extends Module {
* @param type $iTargetId * @param type $iTargetId
*/ */
public function Write($iUserId, $sEventType, $iTargetId, $iPublish=1) { 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) { if ($oEvent=$this->GetEventByTarget($sEventType, $iTargetId)) {
$oEvent->setPublish($iPublish); /**
$this->UpdateEvent($oEvent); * Событие уже было
*/
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); $oEvent->setPublish($iPublish);
$this->AddEvent($oEvent); $this->AddEvent($oEvent);
} }
return true;
} }
/** /**
* Чтение потока пользователя * Чтение потока пользователя

View file

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