From 2ec7c692279bbd5405d45c8aa06b61c4601245a7 Mon Sep 17 00:00:00 2001 From: Mzhelskiy Maxim Date: Sat, 14 Apr 2012 14:06:23 +0400 Subject: [PATCH] =?UTF-8?q?fix=20=D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8=20-=20=D0=BD=D0=B5=20=D0=B2=D1=81?= =?UTF-8?q?=D0=B5=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D1=8F=20=D1=83?= =?UTF-8?q?=D1=87=D0=B8=D1=82=D1=8B=D0=B2=D0=B0=D0=BB=D0=B8=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/modules/stream/Stream.class.php | 56 ++++++++++++++----- .../stream/mapper/Stream.mapper.class.php | 6 +- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/classes/modules/stream/Stream.class.php b/classes/modules/stream/Stream.class.php index 1e47b684..2fbece48 100644 --- a/classes/modules/stream/Stream.class.php +++ b/classes/modules/stream/Stream.class.php @@ -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; } /** * Чтение потока пользователя diff --git a/classes/modules/stream/mapper/Stream.mapper.class.php b/classes/modules/stream/mapper/Stream.mapper.class.php index 7c9c2a44..5621fd59 100644 --- a/classes/modules/stream/mapper/Stream.mapper.class.php +++ b/classes/modules/stream/mapper/Stream.mapper.class.php @@ -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;