2009-05-10 10:50:39 +03:00
|
|
|
<?php
|
2008-09-21 09:36:57 +03:00
|
|
|
/*-------------------------------------------------------
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
---------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Mapper_Topic extends Mapper {
|
2009-06-27 18:05:17 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
public function AddTopic(TopicEntity_Topic $oTopic) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.topic')."
|
2008-09-21 09:36:57 +03:00
|
|
|
(blog_id,
|
|
|
|
user_id,
|
|
|
|
topic_type,
|
2008-09-27 18:21:07 +03:00
|
|
|
topic_title,
|
2008-09-21 09:36:57 +03:00
|
|
|
topic_tags,
|
|
|
|
topic_date_add,
|
|
|
|
topic_user_ip,
|
2008-10-11 00:02:31 +03:00
|
|
|
topic_publish,
|
2009-02-15 10:10:07 +02:00
|
|
|
topic_publish_draft,
|
2008-10-25 23:31:29 +03:00
|
|
|
topic_publish_index,
|
|
|
|
topic_cut_text,
|
2009-03-01 12:19:06 +02:00
|
|
|
topic_forbid_comment,
|
|
|
|
topic_text_hash
|
2008-09-21 09:36:57 +03:00
|
|
|
)
|
2009-03-01 12:19:06 +02:00
|
|
|
VALUES(?d, ?d, ?, ?, ?, ?, ?, ?d, ?d, ?d, ?, ?, ?)
|
2008-09-27 18:21:07 +03:00
|
|
|
";
|
|
|
|
if ($iId=$this->oDb->query($sql,$oTopic->getBlogId(),$oTopic->getUserId(),$oTopic->getType(),$oTopic->getTitle(),
|
2009-03-01 12:19:06 +02:00
|
|
|
$oTopic->getTags(),$oTopic->getDateAdd(),$oTopic->getUserIp(),$oTopic->getPublish(),$oTopic->getPublishDraft(),$oTopic->getPublishIndex(),$oTopic->getCutText(),$oTopic->getForbidComment(),$oTopic->getTextHash()))
|
2008-09-27 18:21:07 +03:00
|
|
|
{
|
|
|
|
$oTopic->setId($iId);
|
|
|
|
$this->AddTopicContent($oTopic);
|
|
|
|
return $iId;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function AddTopicContent(TopicEntity_Topic $oTopic) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.topic_content')."
|
2008-09-27 18:21:07 +03:00
|
|
|
(topic_id,
|
|
|
|
topic_text,
|
|
|
|
topic_text_short,
|
|
|
|
topic_text_source,
|
|
|
|
topic_extra
|
|
|
|
)
|
|
|
|
VALUES(?d, ?, ?, ?, ? )
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
2008-09-27 18:21:07 +03:00
|
|
|
if ($iId=$this->oDb->query($sql,$oTopic->getId(),$oTopic->getText(),
|
|
|
|
$oTopic->getTextShort(),$oTopic->getTextSource(),$oTopic->getExtra()))
|
2008-09-21 09:36:57 +03:00
|
|
|
{
|
|
|
|
return $iId;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function AddTopicTag(TopicEntity_TopicTag $oTopicTag) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.topic_tag')."
|
2008-09-21 09:36:57 +03:00
|
|
|
(topic_id,
|
|
|
|
user_id,
|
|
|
|
blog_id,
|
|
|
|
topic_tag_text
|
|
|
|
)
|
|
|
|
VALUES(?d, ?d, ?d, ?)
|
|
|
|
";
|
|
|
|
if ($iId=$this->oDb->query($sql,$oTopicTag->getTopicId(),$oTopicTag->getUserId(),$oTopicTag->getBlogId(),$oTopicTag->getText()))
|
|
|
|
{
|
|
|
|
return $iId;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-28 01:35:26 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
|
|
|
public function DeleteTopicTagsByTopicId($sTopicId) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "DELETE FROM ".Config::Get('db.table.topic_tag')."
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
|
|
|
topic_id = ?d
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$sTopicId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-11-22 19:30:25 +02:00
|
|
|
public function DeleteTopic($sTopicId) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "DELETE FROM ".Config::Get('db.table.topic')."
|
2008-11-22 19:30:25 +02:00
|
|
|
WHERE
|
|
|
|
topic_id = ?d
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$sTopicId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-24 14:02:34 +03:00
|
|
|
|
2009-03-01 12:19:06 +02:00
|
|
|
public function GetTopicUnique($sUserId,$sHash) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "SELECT topic_id FROM ".Config::Get('db.table.topic')."
|
2009-03-01 12:19:06 +02:00
|
|
|
WHERE
|
|
|
|
user_id = ?d
|
|
|
|
AND
|
|
|
|
topic_text_hash =?
|
|
|
|
";
|
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sUserId,$sHash)) {
|
2009-05-24 14:02:34 +03:00
|
|
|
return $aRow['topic_id'];
|
2009-03-01 12:19:06 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2008-11-12 22:04:21 +02:00
|
|
|
|
2009-05-17 20:35:47 +03:00
|
|
|
public function GetTopicsByArrayId($aArrayId) {
|
2008-11-12 22:04:21 +02:00
|
|
|
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
|
|
|
return array();
|
|
|
|
}
|
2009-05-17 20:35:47 +03:00
|
|
|
|
2008-11-12 22:04:21 +02:00
|
|
|
$sql = "SELECT
|
2009-05-29 18:32:37 +03:00
|
|
|
t.*,
|
|
|
|
tc.*
|
2009-05-17 20:35:47 +03:00
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.topic')." as t
|
|
|
|
JOIN ".Config::Get('db.table.topic_content')." AS tc ON t.topic_id=tc.topic_id
|
2009-05-17 20:35:47 +03:00
|
|
|
WHERE
|
2009-05-29 18:32:37 +03:00
|
|
|
t.topic_id IN(?a)
|
2009-05-17 20:35:47 +03:00
|
|
|
ORDER BY FIELD(t.topic_id,?a) ";
|
2008-11-12 22:04:21 +02:00
|
|
|
$aTopics=array();
|
2009-05-17 20:35:47 +03:00
|
|
|
if ($aRows=$this->oDb->select($sql,$aArrayId,$aArrayId)) {
|
2008-11-12 22:04:21 +02:00
|
|
|
foreach ($aRows as $aTopic) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aTopics[]=Engine::GetEntity('Topic',$aTopic);
|
2008-11-12 22:04:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aTopics;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-17 20:35:47 +03:00
|
|
|
public function GetTopics($aFilter,&$iCount,$iCurrPage,$iPerPage) {
|
|
|
|
$sWhere=$this->buildFilter($aFilter);
|
2008-09-26 23:52:26 +03:00
|
|
|
|
2009-05-17 20:35:47 +03:00
|
|
|
$sql = "SELECT
|
2009-05-24 14:02:34 +03:00
|
|
|
t.topic_id
|
2008-09-26 23:52:26 +03:00
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.topic')." as t,
|
2009-09-18 23:36:07 +03:00
|
|
|
".Config::Get('db.table.blog')." as b
|
2008-09-26 23:52:26 +03:00
|
|
|
WHERE
|
2009-05-17 20:35:47 +03:00
|
|
|
1=1
|
2009-09-18 23:36:07 +03:00
|
|
|
".$sWhere."
|
2008-09-26 23:52:26 +03:00
|
|
|
AND
|
2009-09-18 23:36:07 +03:00
|
|
|
t.blog_id=b.blog_id
|
2009-05-17 20:35:47 +03:00
|
|
|
ORDER by t.topic_id desc
|
|
|
|
LIMIT ?d, ?d";
|
2008-09-21 09:36:57 +03:00
|
|
|
$aTopics=array();
|
2009-05-17 20:35:47 +03:00
|
|
|
if ($aRows=$this->oDb->selectPage($iCount,$sql,($iCurrPage-1)*$iPerPage, $iPerPage)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
foreach ($aRows as $aTopic) {
|
2009-05-24 14:02:34 +03:00
|
|
|
$aTopics[]=$aTopic['topic_id'];
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
2009-05-17 20:35:47 +03:00
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
return $aTopics;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetCountTopics($aFilter) {
|
|
|
|
$sWhere=$this->buildFilter($aFilter);
|
|
|
|
$sql = "SELECT
|
|
|
|
count(t.topic_id) as count
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.topic')." as t,
|
2009-09-18 23:36:07 +03:00
|
|
|
".Config::Get('db.table.blog')." as b
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
|
|
|
1=1
|
|
|
|
|
|
|
|
".$sWhere."
|
|
|
|
|
|
|
|
AND
|
2009-09-18 23:36:07 +03:00
|
|
|
t.blog_id=b.blog_id;";
|
2008-09-21 09:36:57 +03:00
|
|
|
if ($aRow=$this->oDb->selectRow($sql)) {
|
|
|
|
return $aRow['count'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-18 23:36:07 +03:00
|
|
|
public function GetAllTopics($aFilter) {
|
|
|
|
$sWhere=$this->buildFilter($aFilter);
|
|
|
|
|
|
|
|
$sql = "SELECT
|
|
|
|
t.topic_id
|
|
|
|
FROM
|
|
|
|
".Config::Get('db.table.topic')." as t,
|
|
|
|
".Config::Get('db.table.blog')." as b
|
|
|
|
WHERE
|
|
|
|
1=1
|
|
|
|
".$sWhere."
|
|
|
|
AND
|
|
|
|
t.blog_id=b.blog_id
|
|
|
|
ORDER by t.topic_id desc";
|
|
|
|
$aTopics=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql)) {
|
|
|
|
foreach ($aRows as $aTopic) {
|
|
|
|
$aTopics[]=$aTopic['topic_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $aTopics;
|
|
|
|
}
|
|
|
|
|
2009-09-19 21:25:11 +03:00
|
|
|
public function GetTopicsByTag($sTag,$aExcludeTopic,&$iCount,$iCurrPage,$iPerPage) {
|
2009-05-24 14:02:34 +03:00
|
|
|
$sql = "
|
2008-09-27 18:21:07 +03:00
|
|
|
SELECT
|
|
|
|
topic_id
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.topic_tag')."
|
2008-09-27 18:21:07 +03:00
|
|
|
WHERE
|
2009-05-24 14:02:34 +03:00
|
|
|
topic_tag_text = ?
|
2009-09-19 21:25:11 +03:00
|
|
|
{ AND topic_id NOT IN (?a) }
|
2008-09-27 18:21:07 +03:00
|
|
|
ORDER BY topic_id DESC
|
2009-05-24 14:02:34 +03:00
|
|
|
LIMIT ?d, ?d ";
|
2008-09-27 18:21:07 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
$aTopics=array();
|
2009-09-19 21:25:11 +03:00
|
|
|
if ($aRows=$this->oDb->selectPage(
|
|
|
|
$iCount,$sql,$sTag,
|
|
|
|
(is_array($aExcludeTopic)&&count($aExcludeTopic)) ? $aExcludeTopic : DBSIMPLE_SKIP,
|
|
|
|
($iCurrPage-1)*$iPerPage, $iPerPage
|
|
|
|
)
|
|
|
|
) {
|
2008-09-21 09:36:57 +03:00
|
|
|
foreach ($aRows as $aTopic) {
|
2009-05-24 14:02:34 +03:00
|
|
|
$aTopics[]=$aTopic['topic_id'];
|
2009-09-19 21:25:11 +03:00
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
return $aTopics;
|
|
|
|
}
|
|
|
|
|
2008-09-27 18:21:07 +03:00
|
|
|
|
2009-09-19 17:48:28 +03:00
|
|
|
public function GetTopicsRatingByDate($sDate,$iLimit,$aExcludeBlog=array()) {
|
2008-09-21 09:36:57 +03:00
|
|
|
$sql = "SELECT
|
2009-05-24 14:02:34 +03:00
|
|
|
t.topic_id
|
2008-09-27 18:21:07 +03:00
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.topic')." as t
|
2008-09-27 18:21:07 +03:00
|
|
|
WHERE
|
|
|
|
t.topic_publish = 1
|
|
|
|
AND
|
2009-09-18 23:36:07 +03:00
|
|
|
t.topic_date_add >= ?
|
2008-09-27 18:21:07 +03:00
|
|
|
AND
|
2009-09-19 17:48:28 +03:00
|
|
|
t.topic_rating >= 0
|
|
|
|
{ AND t.blog_id NOT IN(?a) }
|
2008-09-27 18:21:07 +03:00
|
|
|
ORDER by t.topic_rating desc, t.topic_id desc
|
2009-05-17 20:35:47 +03:00
|
|
|
LIMIT 0, ?d ";
|
2008-09-21 09:36:57 +03:00
|
|
|
$aTopics=array();
|
2009-09-19 17:48:28 +03:00
|
|
|
if ($aRows=$this->oDb->select(
|
|
|
|
$sql,$sDate,
|
|
|
|
(is_array($aExcludeBlog)&&count($aExcludeBlog)) ? $aExcludeBlog : DBSIMPLE_SKIP,
|
|
|
|
$iLimit
|
|
|
|
)
|
|
|
|
) {
|
2008-09-21 09:36:57 +03:00
|
|
|
foreach ($aRows as $aTopic) {
|
2009-05-24 14:02:34 +03:00
|
|
|
$aTopics[]=$aTopic['topic_id'];
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aTopics;
|
|
|
|
}
|
|
|
|
|
2009-09-19 21:25:11 +03:00
|
|
|
public function GetTopicTags($iLimit,$aExcludeTopic=array()) {
|
2008-09-21 09:36:57 +03:00
|
|
|
$sql = "SELECT
|
|
|
|
tt.topic_tag_text,
|
|
|
|
count(tt.topic_tag_text) as count
|
|
|
|
FROM
|
2009-09-19 21:25:11 +03:00
|
|
|
".Config::Get('db.table.topic_tag')." as tt
|
|
|
|
WHERE
|
|
|
|
1=1
|
|
|
|
{AND tt.topic_id NOT IN(?a) }
|
2008-09-21 09:36:57 +03:00
|
|
|
GROUP BY
|
|
|
|
tt.topic_tag_text
|
|
|
|
ORDER BY
|
|
|
|
count desc
|
2009-09-19 21:25:11 +03:00
|
|
|
LIMIT 0, ?d
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
|
|
|
$aReturn=array();
|
|
|
|
$aReturnSort=array();
|
2009-09-19 21:25:11 +03:00
|
|
|
if ($aRows=$this->oDb->select(
|
|
|
|
$sql,
|
|
|
|
(is_array($aExcludeTopic)&&count($aExcludeTopic)) ? $aExcludeTopic : DBSIMPLE_SKIP,
|
|
|
|
$iLimit
|
|
|
|
)
|
|
|
|
) {
|
2008-09-21 09:36:57 +03:00
|
|
|
foreach ($aRows as $aRow) {
|
2009-03-05 21:34:52 +02:00
|
|
|
$aReturn[mb_strtolower($aRow['topic_tag_text'],'UTF-8')]=$aRow;
|
|
|
|
}
|
|
|
|
ksort($aReturn);
|
2008-09-21 09:36:57 +03:00
|
|
|
foreach ($aReturn as $aRow) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aReturnSort[]=Engine::GetEntity('Topic_TopicTag',$aRow);
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aReturnSort;
|
|
|
|
}
|
|
|
|
|
2009-05-29 18:32:37 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
public function increaseTopicCountComment($sTopicId) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.topic')."
|
2008-09-21 09:36:57 +03:00
|
|
|
SET
|
|
|
|
topic_count_comment=topic_count_comment+1
|
|
|
|
WHERE
|
|
|
|
topic_id = ?
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$sTopicId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function UpdateTopic(TopicEntity_Topic $oTopic) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.topic')."
|
2008-09-21 09:36:57 +03:00
|
|
|
SET
|
|
|
|
blog_id= ?d,
|
2008-09-27 18:21:07 +03:00
|
|
|
topic_title= ?,
|
2008-09-21 09:36:57 +03:00
|
|
|
topic_tags= ?,
|
2009-02-15 10:10:07 +02:00
|
|
|
topic_date_add = ?,
|
2008-09-21 09:36:57 +03:00
|
|
|
topic_date_edit = ?,
|
|
|
|
topic_user_ip= ?,
|
2009-02-15 10:10:07 +02:00
|
|
|
topic_publish= ?d ,
|
|
|
|
topic_publish_draft= ?d ,
|
|
|
|
topic_publish_index= ?d,
|
2008-09-21 09:36:57 +03:00
|
|
|
topic_rating= ?f,
|
|
|
|
topic_count_vote= ?d,
|
|
|
|
topic_count_read= ?d,
|
2008-10-25 23:31:29 +03:00
|
|
|
topic_count_comment= ?d,
|
|
|
|
topic_cut_text = ? ,
|
2009-03-01 12:19:06 +02:00
|
|
|
topic_forbid_comment = ? ,
|
|
|
|
topic_text_hash = ?
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
|
|
|
topic_id = ?d
|
|
|
|
";
|
2009-03-01 12:19:06 +02:00
|
|
|
if ($this->oDb->query($sql,$oTopic->getBlogId(),$oTopic->getTitle(),$oTopic->getTags(),$oTopic->getDateAdd(),$oTopic->getDateEdit(),$oTopic->getUserIp(),$oTopic->getPublish(),$oTopic->getPublishDraft(),$oTopic->getPublishIndex(),$oTopic->getRating(),$oTopic->getCountVote(),$oTopic->getCountRead(),$oTopic->getCountComment(),$oTopic->getCutText(),$oTopic->getForbidComment(),$oTopic->getTextHash(),$oTopic->getId())) {
|
2008-09-27 18:21:07 +03:00
|
|
|
$this->UpdateTopicContent($oTopic);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function UpdateTopicContent(TopicEntity_Topic $oTopic) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.topic_content')."
|
2008-09-27 18:21:07 +03:00
|
|
|
SET
|
|
|
|
topic_text= ?,
|
|
|
|
topic_text_short= ?,
|
|
|
|
topic_text_source= ?,
|
|
|
|
topic_extra= ?
|
|
|
|
WHERE
|
|
|
|
topic_id = ?d
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$oTopic->getText(),$oTopic->getTextShort(),$oTopic->getTextSource(),$oTopic->getExtra(),$oTopic->getId())) {
|
2008-09-21 09:36:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildFilter($aFilter) {
|
|
|
|
$sWhere='';
|
|
|
|
if (isset($aFilter['topic_publish'])) {
|
|
|
|
$sWhere.=" AND t.topic_publish = ".(int)$aFilter['topic_publish'];
|
2008-09-26 23:52:26 +03:00
|
|
|
}
|
|
|
|
if (isset($aFilter['topic_rating']) and is_array($aFilter['topic_rating'])) {
|
2008-10-11 00:02:31 +03:00
|
|
|
$sPublishIndex='';
|
|
|
|
if (isset($aFilter['topic_rating']['publish_index']) and $aFilter['topic_rating']['publish_index']==1) {
|
|
|
|
$sPublishIndex=" or topic_publish_index=1 ";
|
|
|
|
}
|
2008-09-26 23:52:26 +03:00
|
|
|
if ($aFilter['topic_rating']['type']=='top') {
|
2008-10-11 00:02:31 +03:00
|
|
|
$sWhere.=" AND ( t.topic_rating >= ".(float)$aFilter['topic_rating']['value']." {$sPublishIndex} ) ";
|
2008-09-26 23:52:26 +03:00
|
|
|
} else {
|
2008-10-11 00:02:31 +03:00
|
|
|
$sWhere.=" AND ( t.topic_rating < ".(float)$aFilter['topic_rating']['value']." ) ";
|
2008-09-26 23:52:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($aFilter['topic_new'])) {
|
|
|
|
$sWhere.=" AND t.topic_date_add >= '".$aFilter['topic_new']."'";
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
if (isset($aFilter['user_id'])) {
|
|
|
|
$sWhere.=" AND t.user_id = ".(int)$aFilter['user_id'];
|
|
|
|
}
|
|
|
|
if (isset($aFilter['blog_id'])) {
|
2009-09-18 23:36:07 +03:00
|
|
|
if(!is_array($aFilter['blog_id'])) {
|
|
|
|
$aFilter['blog_id']=array($aFilter['blog_id']);
|
|
|
|
}
|
|
|
|
$sWhere.=" AND t.blog_id IN ('".join("','",$aFilter['blog_id'])."')";
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
2008-09-26 23:52:26 +03:00
|
|
|
if (isset($aFilter['blog_type']) and is_array($aFilter['blog_type'])) {
|
2009-09-18 23:36:07 +03:00
|
|
|
$aBlogTypes = array();
|
|
|
|
foreach ($aFilter['blog_type'] as $sType=>$aBlogId) {
|
|
|
|
/**
|
|
|
|
* Позиция вида 'type'=>array('id1', 'id2')
|
|
|
|
*/
|
|
|
|
if(!is_array($aBlogId) && is_string($sType)){
|
|
|
|
$aBlogId=array($aBlogId);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Позиция вида 'type'
|
|
|
|
*/
|
|
|
|
if(is_string($aBlogId) && is_int($sType)) {
|
|
|
|
$sType=$aBlogId;
|
|
|
|
$aBlogId=array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$aBlogTypes[] = (count($aBlogId)==0)
|
|
|
|
? "(b.blog_type='".$sType."')"
|
2009-09-19 13:53:33 +03:00
|
|
|
: "(b.blog_type='".$sType."' AND t.blog_id IN ('".join("','",$aBlogId)."'))";
|
2009-09-18 23:36:07 +03:00
|
|
|
}
|
|
|
|
$sWhere.=" AND (".join(" OR ",(array)$aBlogTypes).")";
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
2009-09-19 03:43:00 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
return $sWhere;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetTopicTagsByLike($sTag,$iLimit) {
|
2008-09-22 18:18:08 +03:00
|
|
|
$sTag=mb_strtolower($sTag,"UTF-8");
|
2008-09-21 09:36:57 +03:00
|
|
|
$sql = "SELECT
|
|
|
|
topic_tag_text
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.topic_tag')."
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
2008-11-03 13:08:12 +02:00
|
|
|
topic_tag_text LIKE ?
|
2008-09-21 09:36:57 +03:00
|
|
|
GROUP BY
|
|
|
|
topic_tag_text
|
|
|
|
LIMIT 0, ?d
|
|
|
|
";
|
|
|
|
$aReturn=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sTag.'%',$iLimit)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aReturn[]=Engine::GetEntity('Topic_TopicTag',$aRow);
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aReturn;
|
|
|
|
}
|
|
|
|
|
2009-01-24 11:54:59 +02:00
|
|
|
public function UpdateTopicRead(TopicEntity_TopicRead $oTopicRead) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.topic_read')."
|
2008-12-28 12:51:59 +02:00
|
|
|
SET
|
|
|
|
comment_count_last = ? ,
|
2009-01-24 11:54:59 +02:00
|
|
|
comment_id_last = ? ,
|
2008-12-28 12:51:59 +02:00
|
|
|
date_read = ?
|
|
|
|
WHERE
|
|
|
|
topic_id = ?
|
|
|
|
AND
|
|
|
|
user_id = ?
|
|
|
|
";
|
2009-01-24 11:54:59 +02:00
|
|
|
return $this->oDb->query($sql,$oTopicRead->getCommentCountLast(),$oTopicRead->getCommentIdLast(),$oTopicRead->getDateRead(),$oTopicRead->getTopicId(),$oTopicRead->getUserId());
|
2008-12-28 12:51:59 +02:00
|
|
|
}
|
|
|
|
|
2009-01-24 11:54:59 +02:00
|
|
|
public function AddTopicRead(TopicEntity_TopicRead $oTopicRead) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.topic_read')."
|
2008-10-30 08:12:44 +02:00
|
|
|
SET
|
2008-11-03 22:18:09 +02:00
|
|
|
comment_count_last = ? ,
|
2009-01-24 11:54:59 +02:00
|
|
|
comment_id_last = ? ,
|
2008-10-30 08:12:44 +02:00
|
|
|
date_read = ? ,
|
2008-12-28 12:51:59 +02:00
|
|
|
topic_id = ? ,
|
2008-09-21 09:36:57 +03:00
|
|
|
user_id = ?
|
|
|
|
";
|
2009-01-24 11:54:59 +02:00
|
|
|
return $this->oDb->query($sql,$oTopicRead->getCommentCountLast(),$oTopicRead->getCommentIdLast(),$oTopicRead->getDateRead(),$oTopicRead->getTopicId(),$oTopicRead->getUserId());
|
2008-12-28 12:51:59 +02:00
|
|
|
}
|
2008-11-03 22:18:09 +02:00
|
|
|
|
2009-06-27 18:05:17 +03:00
|
|
|
|
2009-05-29 18:32:37 +03:00
|
|
|
public function GetTopicsReadByArray($aArrayId,$sUserId) {
|
|
|
|
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT
|
|
|
|
t.*
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.topic_read')." as t
|
2009-05-29 18:32:37 +03:00
|
|
|
WHERE
|
|
|
|
t.user_id = ?d
|
|
|
|
AND
|
|
|
|
t.topic_id IN(?a)
|
|
|
|
";
|
|
|
|
$aReads=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId,$aArrayId)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aReads[]=Engine::GetEntity('Topic_TopicRead',$aRow);
|
2009-05-29 18:32:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aReads;
|
|
|
|
}
|
|
|
|
|
2008-10-01 21:53:51 +03:00
|
|
|
public function AddTopicQuestionVote(TopicEntity_TopicQuestionVote $oTopicQuestionVote) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.topic_question_vote')."
|
2008-10-01 21:53:51 +03:00
|
|
|
(topic_id,
|
|
|
|
user_voter_id,
|
|
|
|
answer
|
|
|
|
)
|
|
|
|
VALUES(?d, ?d, ?f)
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$oTopicQuestionVote->getTopicId(),$oTopicQuestionVote->getVoterId(),$oTopicQuestionVote->getAnswer())===0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-27 18:05:17 +03:00
|
|
|
|
2009-05-29 18:32:37 +03:00
|
|
|
public function GetTopicsQuestionVoteByArray($aArrayId,$sUserId) {
|
|
|
|
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT
|
|
|
|
v.*
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.topic_question_vote')." as v
|
2009-05-29 18:32:37 +03:00
|
|
|
WHERE
|
|
|
|
v.user_voter_id = ?d
|
|
|
|
AND
|
|
|
|
v.topic_id IN(?a)
|
|
|
|
";
|
|
|
|
$aVotes=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId,$aArrayId)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aVotes[]=Engine::GetEntity('Topic_TopicQuestionVote',$aRow);
|
2009-05-29 18:32:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aVotes;
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
?>
|