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 {
|
|
|
|
|
protected $oUserCurrent=null;
|
|
|
|
|
|
|
|
|
|
public function SetUserCurrent($oUserCurrent) {
|
|
|
|
|
$this->oUserCurrent=$oUserCurrent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function AddTopic(TopicEntity_Topic $oTopic) {
|
|
|
|
|
$sql = "INSERT INTO ".DB_TABLE_TOPIC."
|
|
|
|
|
(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,
|
2008-10-25 23:31:29 +03:00
|
|
|
|
topic_publish_index,
|
|
|
|
|
topic_cut_text,
|
|
|
|
|
topic_forbid_comment
|
2008-09-21 09:36:57 +03:00
|
|
|
|
)
|
2008-10-25 23:31:29 +03:00
|
|
|
|
VALUES(?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(),
|
2008-10-25 23:31:29 +03:00
|
|
|
|
$oTopic->getTags(),$oTopic->getDateAdd(),$oTopic->getUserIp(),$oTopic->getPublish(),$oTopic->getPublishIndex(),$oTopic->getCutText(),$oTopic->getForbidComment()))
|
2008-09-27 18:21:07 +03:00
|
|
|
|
{
|
|
|
|
|
$oTopic->setId($iId);
|
|
|
|
|
$this->AddTopicContent($oTopic);
|
|
|
|
|
return $iId;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function AddTopicContent(TopicEntity_Topic $oTopic) {
|
|
|
|
|
$sql = "INSERT INTO ".DB_TABLE_TOPIC_CONTENT."
|
|
|
|
|
(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) {
|
|
|
|
|
$sql = "INSERT INTO ".DB_TABLE_TOPIC_TAG."
|
|
|
|
|
(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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function AddTopicVote(TopicEntity_TopicVote $oTopicVote) {
|
|
|
|
|
$sql = "INSERT INTO ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
(topic_id,
|
|
|
|
|
user_voter_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
)
|
|
|
|
|
VALUES(?d, ?d, ?f)
|
|
|
|
|
";
|
|
|
|
|
if ($this->oDb->query($sql,$oTopicVote->getTopicId(),$oTopicVote->getVoterId(),$oTopicVote->getDelta())===0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function DeleteTopicTagsByTopicId($sTopicId) {
|
|
|
|
|
$sql = "DELETE FROM ".DB_TABLE_TOPIC_TAG."
|
|
|
|
|
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) {
|
|
|
|
|
$sql = "DELETE FROM ".DB_TABLE_TOPIC."
|
|
|
|
|
WHERE
|
|
|
|
|
topic_id = ?d
|
|
|
|
|
";
|
|
|
|
|
if ($this->oDb->query($sql,$sTopicId)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
public function GetTopicById($sId,$oUser,$iPublish) {
|
|
|
|
|
$iCurrentUserId=-1;
|
|
|
|
|
if (is_object($this->oUserCurrent)) {
|
|
|
|
|
$iCurrentUserId=$this->oUserCurrent->getId();
|
|
|
|
|
}
|
2008-10-17 22:52:11 +03:00
|
|
|
|
$sWhereUser=' 1=1 ';
|
|
|
|
|
if ($iPublish!=-1) { //можно считать это костылём..
|
|
|
|
|
$sWhereUser=' t.topic_publish = '.(int)$iPublish.' ';
|
|
|
|
|
if ($oUser) {
|
|
|
|
|
$sWhereUser.=' OR t.user_id = '.(int)$oUser->getId();
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
t.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
2008-10-01 21:53:51 +03:00
|
|
|
|
tv.vote_delta as user_vote_delta,
|
|
|
|
|
IF(tqv.topic_id IS NULL,0,1) as user_question_is_vote
|
2008-09-21 09:36:57 +03:00
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC." as t
|
|
|
|
|
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
2008-10-01 21:53:51 +03:00
|
|
|
|
) AS tv ON tv.topic_id = t.topic_id
|
|
|
|
|
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_QUESTION_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tqv ON tqv.topic_id = t.topic_id,
|
2008-09-21 09:36:57 +03:00
|
|
|
|
|
|
|
|
|
".DB_TABLE_USER." as u,
|
|
|
|
|
".DB_TABLE_BLOG." as b
|
|
|
|
|
WHERE
|
|
|
|
|
t.topic_id = ?d
|
|
|
|
|
AND
|
2008-10-17 22:52:11 +03:00
|
|
|
|
(
|
2008-09-21 09:36:57 +03:00
|
|
|
|
".$sWhereUser."
|
|
|
|
|
)
|
|
|
|
|
AND
|
|
|
|
|
t.user_id=u.user_id
|
|
|
|
|
AND
|
|
|
|
|
t.blog_id=b.blog_id
|
|
|
|
|
";
|
2008-09-27 18:21:07 +03:00
|
|
|
|
/**
|
|
|
|
|
* оптимизированный запрос
|
|
|
|
|
*/
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
t_fast.*,
|
|
|
|
|
tc.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
b.blog_title as blog_title,
|
2008-10-18 15:32:24 +03:00
|
|
|
|
b.user_owner_id as blog_owner_id,
|
2008-09-27 18:21:07 +03:00
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
2008-10-01 21:53:51 +03:00
|
|
|
|
tv.vote_delta as user_vote_delta,
|
2008-10-17 22:52:11 +03:00
|
|
|
|
IF(tqv.topic_id IS NULL,0,1) as user_question_is_vote,
|
|
|
|
|
bu.is_moderator as user_is_blog_moderator,
|
|
|
|
|
bu.is_administrator as user_is_blog_administrator
|
2008-09-27 18:21:07 +03:00
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
SELECT
|
|
|
|
|
t.*
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC." as t
|
|
|
|
|
WHERE
|
|
|
|
|
t.topic_id = ?d
|
|
|
|
|
AND
|
2008-10-17 22:52:11 +03:00
|
|
|
|
(
|
2008-09-27 18:21:07 +03:00
|
|
|
|
".$sWhereUser."
|
|
|
|
|
)
|
|
|
|
|
) AS t_fast
|
|
|
|
|
JOIN ".DB_TABLE_USER." AS u ON t_fast.user_id=u.user_id
|
|
|
|
|
JOIN ".DB_TABLE_BLOG." AS b ON t_fast.blog_id=b.blog_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tv ON t_fast.topic_id=tv.topic_id
|
2008-10-17 22:52:11 +03:00
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
is_moderator,
|
|
|
|
|
is_administrator,
|
|
|
|
|
blog_id
|
|
|
|
|
FROM ".DB_TABLE_BLOG_USER."
|
|
|
|
|
WHERE user_id = ?d
|
|
|
|
|
) AS bu ON t_fast.blog_id=bu.blog_id
|
2008-10-01 21:53:51 +03:00
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_QUESTION_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tqv ON t_fast.topic_id=tqv.topic_id
|
2008-09-27 18:21:07 +03:00
|
|
|
|
JOIN ".DB_TABLE_TOPIC_CONTENT." AS tc ON t_fast.topic_id=tc.topic_id
|
|
|
|
|
";
|
2008-10-17 22:52:11 +03:00
|
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sId,$iCurrentUserId,$iCurrentUserId,$iCurrentUserId)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
return new TopicEntity_Topic($aRow);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-12 22:04:21 +02:00
|
|
|
|
|
|
|
|
|
public function GetTopicsByArrayId($aArrayId,$oUser,$iPublish) {
|
|
|
|
|
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$iCurrentUserId=-1;
|
|
|
|
|
if (is_object($this->oUserCurrent)) {
|
|
|
|
|
$iCurrentUserId=$this->oUserCurrent->getId();
|
|
|
|
|
}
|
|
|
|
|
$sWhereUser=' 1=1 ';
|
|
|
|
|
if ($iPublish!=-1) { //можно считать это костылём..
|
|
|
|
|
$sWhereUser=' t.topic_publish = '.(int)$iPublish.' ';
|
|
|
|
|
if ($oUser) {
|
|
|
|
|
$sWhereUser.=' OR t.user_id = '.(int)$oUser->getId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
t_fast.*,
|
|
|
|
|
tc.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
b.user_owner_id as blog_owner_id,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
|
|
|
|
tv.vote_delta as user_vote_delta,
|
|
|
|
|
IF(tqv.topic_id IS NULL,0,1) as user_question_is_vote,
|
|
|
|
|
bu.is_moderator as user_is_blog_moderator,
|
|
|
|
|
bu.is_administrator as user_is_blog_administrator
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
SELECT
|
|
|
|
|
t.*
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC." as t
|
|
|
|
|
WHERE
|
|
|
|
|
t.topic_id IN(?a)
|
|
|
|
|
AND
|
|
|
|
|
(
|
|
|
|
|
".$sWhereUser."
|
|
|
|
|
)
|
|
|
|
|
) AS t_fast
|
|
|
|
|
JOIN ".DB_TABLE_USER." AS u ON t_fast.user_id=u.user_id
|
|
|
|
|
JOIN ".DB_TABLE_BLOG." AS b ON t_fast.blog_id=b.blog_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tv ON t_fast.topic_id=tv.topic_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
is_moderator,
|
|
|
|
|
is_administrator,
|
|
|
|
|
blog_id
|
|
|
|
|
FROM ".DB_TABLE_BLOG_USER."
|
|
|
|
|
WHERE user_id = ?d
|
|
|
|
|
) AS bu ON t_fast.blog_id=bu.blog_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_QUESTION_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tqv ON t_fast.topic_id=tqv.topic_id
|
|
|
|
|
JOIN ".DB_TABLE_TOPIC_CONTENT." AS tc ON t_fast.topic_id=tc.topic_id
|
2008-11-21 21:58:17 +02:00
|
|
|
|
ORDER BY FIELD(t_fast.topic_id,?a)
|
2008-11-12 22:04:21 +02:00
|
|
|
|
";
|
|
|
|
|
$aTopics=array();
|
2008-11-21 21:58:17 +02:00
|
|
|
|
if ($aRows=$this->oDb->select($sql,$aArrayId,$iCurrentUserId,$iCurrentUserId,$iCurrentUserId,$aArrayId)) {
|
2008-11-12 22:04:21 +02:00
|
|
|
|
foreach ($aRows as $aTopic) {
|
|
|
|
|
$aTopics[]=new TopicEntity_Topic($aTopic);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aTopics;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
public function GetTopics($aFilter,&$iCount,$iCurrPage,$iPerPage) {
|
|
|
|
|
$iCurrentUserId=-1;
|
|
|
|
|
if (is_object($this->oUserCurrent)) {
|
|
|
|
|
$iCurrentUserId=$this->oUserCurrent->getId();
|
|
|
|
|
}
|
2008-09-26 23:52:26 +03:00
|
|
|
|
$sWhere=$this->buildFilter($aFilter);
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
$sql = "SELECT
|
|
|
|
|
t.*,
|
2008-09-26 23:52:26 +03:00
|
|
|
|
tc.*,
|
2008-09-21 09:36:57 +03:00
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
|
|
|
|
tv.vote_delta as user_vote_delta
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC." as t
|
|
|
|
|
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
2008-09-26 23:52:26 +03:00
|
|
|
|
) AS tv ON tv.topic_id = t.topic_id
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
".DB_TABLE_TOPIC_CONTENT."
|
|
|
|
|
AS tc ON tc.topic_id = t.topic_id,
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
".DB_TABLE_USER." as u,
|
|
|
|
|
".DB_TABLE_BLOG." as b
|
|
|
|
|
WHERE
|
|
|
|
|
1=1
|
|
|
|
|
|
|
|
|
|
".$sWhere."
|
|
|
|
|
|
|
|
|
|
AND
|
|
|
|
|
t.blog_id=b.blog_id
|
|
|
|
|
AND
|
|
|
|
|
t.user_id=u.user_id
|
|
|
|
|
ORDER by t.topic_date_add desc
|
|
|
|
|
LIMIT ?d, ?d
|
|
|
|
|
;
|
|
|
|
|
";
|
2008-09-26 23:52:26 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* запрос немного оптимизирован, почуствуй разницу :)
|
|
|
|
|
* на самом деле его еще можно ускорить - во вложеном запросе убрать условие по типу блога и вынести его в JOIN + изменив фильтр(вынести из него тип блога)
|
|
|
|
|
* и вообще от фильтра нужно избавляться, т.к. эта универсальной сказывается на быстродействии из-за разных комбинаций ключей
|
|
|
|
|
*
|
|
|
|
|
* при таком запросе приходиться отдельно запрашивать общее число записей
|
|
|
|
|
*/
|
|
|
|
|
$sql = "
|
|
|
|
|
SELECT
|
|
|
|
|
t_fast.*,
|
|
|
|
|
tc.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
2008-10-01 21:53:51 +03:00
|
|
|
|
tv.vote_delta as user_vote_delta,
|
2008-10-17 22:52:11 +03:00
|
|
|
|
IF(tqv.topic_id IS NULL,0,1) as user_question_is_vote,
|
|
|
|
|
bu.is_moderator as user_is_blog_moderator,
|
2008-10-25 23:31:29 +03:00
|
|
|
|
bu.is_administrator as user_is_blog_administrator,
|
2009-02-14 17:39:58 +02:00
|
|
|
|
IF(tr.comment_count_last IS NULL,t_fast.topic_count_comment,t_fast.topic_count_comment-tr.comment_count_last) as count_comment_new,
|
|
|
|
|
IF(ft.topic_id IS NULL,0,1) as topic_is_favourite
|
2008-09-26 23:52:26 +03:00
|
|
|
|
FROM (
|
|
|
|
|
SELECT
|
|
|
|
|
t.*,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
b.blog_type as blog_type,
|
2008-10-18 15:32:24 +03:00
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
b.user_owner_id as blog_owner_id
|
2008-09-26 23:52:26 +03:00
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC." as t,
|
|
|
|
|
".DB_TABLE_BLOG." as b
|
|
|
|
|
WHERE
|
|
|
|
|
1=1
|
|
|
|
|
|
|
|
|
|
".$sWhere."
|
|
|
|
|
|
|
|
|
|
AND
|
|
|
|
|
t.blog_id=b.blog_id
|
|
|
|
|
ORDER by t.topic_date_add desc
|
|
|
|
|
LIMIT ?d, ?d
|
|
|
|
|
) as t_fast
|
|
|
|
|
JOIN ".DB_TABLE_USER." AS u ON t_fast.user_id=u.user_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tv ON t_fast.topic_id=tv.topic_id
|
2009-02-14 17:39:58 +02:00
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM ".DB_TABLE_FAVOURITE_TOPIC."
|
|
|
|
|
WHERE user_id = ?d
|
|
|
|
|
) AS ft ON t_fast.topic_id=ft.topic_id
|
2008-10-25 23:31:29 +03:00
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
comment_count_last
|
2008-11-03 22:18:09 +02:00
|
|
|
|
FROM ".DB_TABLE_TOPIC_READ."
|
2008-10-25 23:31:29 +03:00
|
|
|
|
WHERE user_id = ?d
|
2008-11-03 22:18:09 +02:00
|
|
|
|
) AS tr ON t_fast.topic_id=tr.topic_id
|
2008-10-01 21:53:51 +03:00
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_QUESTION_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tqv ON t_fast.topic_id=tqv.topic_id
|
2008-10-17 22:52:11 +03:00
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
is_moderator,
|
|
|
|
|
is_administrator,
|
|
|
|
|
blog_id
|
|
|
|
|
FROM ".DB_TABLE_BLOG_USER."
|
|
|
|
|
WHERE user_id = ?d
|
|
|
|
|
) AS bu ON t_fast.blog_id=bu.blog_id
|
2008-09-26 23:52:26 +03:00
|
|
|
|
JOIN ".DB_TABLE_TOPIC_CONTENT." AS tc ON t_fast.topic_id=tc.topic_id
|
2008-11-21 20:50:46 +02:00
|
|
|
|
order by t_fast.topic_date_add desc
|
2008-09-26 23:52:26 +03:00
|
|
|
|
;
|
|
|
|
|
";
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
$aTopics=array();
|
2009-02-14 17:39:58 +02:00
|
|
|
|
if ($aRows=$this->oDb->select($sql,($iCurrPage-1)*$iPerPage, $iPerPage, $iCurrentUserId,$iCurrentUserId,$iCurrentUserId,$iCurrentUserId,$iCurrentUserId)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
foreach ($aRows as $aTopic) {
|
|
|
|
|
$aTopics[]=new TopicEntity_Topic($aTopic);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-26 23:52:26 +03:00
|
|
|
|
$iCount=$this->GetCountTopics($aFilter);
|
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
|
2008-09-27 18:21:07 +03:00
|
|
|
|
".DB_TABLE_TOPIC." as t,
|
2008-09-21 09:36:57 +03:00
|
|
|
|
".DB_TABLE_BLOG." as b
|
|
|
|
|
WHERE
|
|
|
|
|
1=1
|
|
|
|
|
|
|
|
|
|
".$sWhere."
|
|
|
|
|
|
|
|
|
|
AND
|
2008-09-27 18:21: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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetTopicsByTag($sTag,&$iCount,$iCurrPage,$iPerPage) {
|
|
|
|
|
$iCurrentUserId=-1;
|
|
|
|
|
if (is_object($this->oUserCurrent)) {
|
|
|
|
|
$iCurrentUserId=$this->oUserCurrent->getId();
|
|
|
|
|
}
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
t.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
|
|
|
|
tv.vote_delta as user_vote_delta
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC_TAG." as tt,
|
|
|
|
|
".DB_TABLE_TOPIC." as t
|
|
|
|
|
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tv ON tv.topic_id = t.topic_id,
|
|
|
|
|
|
|
|
|
|
".DB_TABLE_USER." as u,
|
|
|
|
|
".DB_TABLE_BLOG." as b
|
|
|
|
|
WHERE
|
|
|
|
|
tt.topic_tag_text = ?
|
|
|
|
|
AND
|
|
|
|
|
t.topic_id = tt.topic_id
|
|
|
|
|
AND
|
|
|
|
|
t.topic_publish = 1
|
|
|
|
|
AND
|
|
|
|
|
b.blog_type in ('personal','open')
|
|
|
|
|
AND
|
|
|
|
|
t.blog_id=b.blog_id
|
|
|
|
|
AND
|
|
|
|
|
t.user_id=u.user_id
|
|
|
|
|
ORDER by t.topic_date_add desc
|
|
|
|
|
LIMIT ?d, ?d
|
|
|
|
|
;
|
|
|
|
|
";
|
2008-09-27 18:21:07 +03:00
|
|
|
|
/**
|
|
|
|
|
* оптимизирован
|
|
|
|
|
*/
|
|
|
|
|
$sql = " SELECT
|
|
|
|
|
t.*,
|
|
|
|
|
tc.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
2008-10-01 21:53:51 +03:00
|
|
|
|
tv.vote_delta as user_vote_delta,
|
|
|
|
|
IF(tqv.topic_id IS NULL,0,1) as user_question_is_vote
|
2008-09-27 18:21:07 +03:00
|
|
|
|
FROM (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC_TAG."
|
|
|
|
|
WHERE
|
|
|
|
|
topic_tag_text = ?
|
|
|
|
|
ORDER BY topic_id DESC
|
|
|
|
|
LIMIT ?d, ?d
|
|
|
|
|
) as tt
|
|
|
|
|
JOIN ".DB_TABLE_TOPIC." AS t ON tt.topic_id=t.topic_id
|
|
|
|
|
JOIN ".DB_TABLE_USER." AS u ON t.user_id=u.user_id
|
|
|
|
|
JOIN ".DB_TABLE_BLOG." AS b ON t.blog_id=b.blog_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tv ON tt.topic_id=tv.topic_id
|
2008-10-01 21:53:51 +03:00
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_QUESTION_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tqv ON tt.topic_id=tqv.topic_id
|
2008-09-27 18:21:07 +03:00
|
|
|
|
LEFT JOIN ".DB_TABLE_TOPIC_CONTENT." AS tc ON tt.topic_id=tc.topic_id
|
2008-11-21 20:50:46 +02:00
|
|
|
|
order by t.topic_id desc
|
2008-09-27 18:21:07 +03:00
|
|
|
|
;
|
|
|
|
|
";
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
$aTopics=array();
|
2008-10-01 21:53:51 +03:00
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sTag,($iCurrPage-1)*$iPerPage, $iPerPage,$iCurrentUserId,$iCurrentUserId)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
foreach ($aRows as $aTopic) {
|
|
|
|
|
$aTopics[]=new TopicEntity_Topic($aTopic);
|
|
|
|
|
}
|
2008-09-27 18:21:07 +03:00
|
|
|
|
$iCount=$this->GetCountTopicsByTag($sTag);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
return $aTopics;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-27 18:21:07 +03:00
|
|
|
|
public function GetCountTopicsByTag($sTag) {
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
count(topic_id) as count
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC_TAG."
|
|
|
|
|
WHERE
|
|
|
|
|
topic_tag_text = ? ;
|
|
|
|
|
";
|
|
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sTag)) {
|
|
|
|
|
return $aRow['count'];
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
public function GetTopicsRatingByDate($sDate,$iLimit) {
|
|
|
|
|
$iCurrentUserId=-1;
|
|
|
|
|
if (is_object($this->oUserCurrent)) {
|
|
|
|
|
$iCurrentUserId=$this->oUserCurrent->getId();
|
|
|
|
|
}
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
t.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
|
|
|
|
tv.vote_delta as user_vote_delta
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC." as t
|
|
|
|
|
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tv ON tv.topic_id = t.topic_id,
|
|
|
|
|
|
|
|
|
|
".DB_TABLE_USER." as u,
|
|
|
|
|
".DB_TABLE_BLOG." as b
|
|
|
|
|
WHERE
|
|
|
|
|
t.topic_date_add >= ?
|
|
|
|
|
AND
|
|
|
|
|
t.topic_publish = 1
|
|
|
|
|
AND
|
|
|
|
|
b.blog_type in ('personal','open')
|
|
|
|
|
AND
|
|
|
|
|
t.topic_rating >= 0
|
|
|
|
|
AND
|
|
|
|
|
t.blog_id=b.blog_id
|
|
|
|
|
AND
|
|
|
|
|
t.user_id=u.user_id
|
|
|
|
|
ORDER by t.topic_rating desc, t.topic_date_add desc
|
|
|
|
|
LIMIT 0, ?d ;
|
|
|
|
|
";
|
2008-09-27 18:21:07 +03:00
|
|
|
|
/**
|
|
|
|
|
* оптимизирован
|
|
|
|
|
*/
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
t_fast.*,
|
|
|
|
|
tc.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
2008-10-01 21:53:51 +03:00
|
|
|
|
tv.vote_delta as user_vote_delta,
|
|
|
|
|
IF(tqv.topic_id IS NULL,0,1) as user_question_is_vote
|
2008-09-27 18:21:07 +03:00
|
|
|
|
FROM (
|
|
|
|
|
SELECT
|
|
|
|
|
t.*,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC." as t,
|
|
|
|
|
".DB_TABLE_BLOG." as b
|
|
|
|
|
WHERE
|
|
|
|
|
t.topic_publish = 1
|
|
|
|
|
AND
|
|
|
|
|
t.topic_date_add >= ?
|
|
|
|
|
AND
|
|
|
|
|
t.topic_rating >= 0
|
|
|
|
|
AND
|
|
|
|
|
t.blog_id=b.blog_id
|
|
|
|
|
AND
|
|
|
|
|
b.blog_type in ('personal','open')
|
|
|
|
|
ORDER by t.topic_rating desc, t.topic_id desc
|
|
|
|
|
LIMIT 0, ?d
|
|
|
|
|
) AS t_fast
|
|
|
|
|
JOIN ".DB_TABLE_USER." AS u ON t_fast.user_id=u.user_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tv ON t_fast.topic_id=tv.topic_id
|
2008-10-01 21:53:51 +03:00
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_QUESTION_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tqv ON t_fast.topic_id=tqv.topic_id
|
2008-11-21 20:50:46 +02:00
|
|
|
|
JOIN ".DB_TABLE_TOPIC_CONTENT." AS tc ON t_fast.topic_id=tc.topic_id
|
|
|
|
|
order by t_fast.topic_rating desc
|
2008-09-27 18:21:07 +03:00
|
|
|
|
";
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
$aTopics=array();
|
2008-10-01 21:53:51 +03:00
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sDate,$iLimit,$iCurrentUserId,$iCurrentUserId)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
foreach ($aRows as $aTopic) {
|
|
|
|
|
$aTopics[]=new TopicEntity_Topic($aTopic);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aTopics;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetTopicTags($iLimit) {
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
tt.topic_tag_text,
|
|
|
|
|
count(tt.topic_tag_text) as count
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC_TAG." as tt,
|
|
|
|
|
".DB_TABLE_TOPIC." as t
|
|
|
|
|
WHERE
|
|
|
|
|
t.topic_id=tt.topic_id
|
|
|
|
|
AND
|
|
|
|
|
t.topic_publish = 1
|
|
|
|
|
GROUP BY
|
|
|
|
|
tt.topic_tag_text
|
|
|
|
|
ORDER BY
|
|
|
|
|
count desc
|
|
|
|
|
LIMIT 0, ?d
|
|
|
|
|
";
|
|
|
|
|
$aReturn=array();
|
|
|
|
|
$aReturnSort=array();
|
|
|
|
|
if ($aRows=$this->oDb->select($sql,$iLimit)) {
|
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
|
$aReturn[$aRow['topic_tag_text']]=$aRow;
|
|
|
|
|
}
|
|
|
|
|
ksort($aReturn);
|
|
|
|
|
foreach ($aReturn as $aRow) {
|
|
|
|
|
$aReturnSort[]=new TopicEntity_TopicTag($aRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aReturnSort;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetTopicTagsByUserId($sUserId,$iLimit) {
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
topic_tag_text,
|
|
|
|
|
count(topic_tag_text) as count
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC_TAG."
|
|
|
|
|
WHERE
|
|
|
|
|
user_id = ?
|
|
|
|
|
GROUP BY
|
|
|
|
|
topic_tag_text
|
|
|
|
|
ORDER BY
|
|
|
|
|
topic_tag_text ASC
|
|
|
|
|
LIMIT 0, ?d
|
|
|
|
|
";
|
|
|
|
|
$aReturn=array();
|
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId,$iLimit)) {
|
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
|
$aReturn[]=new TopicEntity_TopicTag($aRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetTopicVote($sTopicId,$sUserId) {
|
|
|
|
|
$sql = "SELECT * FROM ".DB_TABLE_TOPIC_VOTE." WHERE topic_id = ?d and user_voter_id = ?d ";
|
|
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sTopicId,$sUserId)) {
|
|
|
|
|
return new TopicEntity_TopicVote($aRow);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function increaseTopicCountComment($sTopicId) {
|
|
|
|
|
$sql = "UPDATE ".DB_TABLE_TOPIC."
|
|
|
|
|
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) {
|
|
|
|
|
$sql = "UPDATE ".DB_TABLE_TOPIC."
|
|
|
|
|
SET
|
|
|
|
|
blog_id= ?d,
|
2008-09-27 18:21:07 +03:00
|
|
|
|
topic_title= ?,
|
2008-09-21 09:36:57 +03:00
|
|
|
|
topic_tags= ?,
|
|
|
|
|
topic_date_edit = ?,
|
|
|
|
|
topic_user_ip= ?,
|
|
|
|
|
topic_publish= ? ,
|
2008-10-11 00:02:31 +03:00
|
|
|
|
topic_publish_index= ?,
|
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 = ? ,
|
|
|
|
|
topic_forbid_comment = ?
|
2008-09-21 09:36:57 +03:00
|
|
|
|
WHERE
|
|
|
|
|
topic_id = ?d
|
|
|
|
|
";
|
2008-10-25 23:31:29 +03:00
|
|
|
|
if ($this->oDb->query($sql,$oTopic->getBlogId(),$oTopic->getTitle(),$oTopic->getTags(),$oTopic->getDateEdit(),$oTopic->getUserIp(),$oTopic->getPublish(),$oTopic->getPublishIndex(),$oTopic->getRating(),$oTopic->getCountVote(),$oTopic->getCountRead(),$oTopic->getCountComment(),$oTopic->getCutText(),$oTopic->getForbidComment(),$oTopic->getId())) {
|
2008-09-27 18:21:07 +03:00
|
|
|
|
$this->UpdateTopicContent($oTopic);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function UpdateTopicContent(TopicEntity_Topic $oTopic) {
|
|
|
|
|
$sql = "UPDATE ".DB_TABLE_TOPIC_CONTENT."
|
|
|
|
|
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='';
|
2008-09-26 23:52:26 +03:00
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
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'])) {
|
|
|
|
|
$sWhere.=" AND t.blog_id = ".(int)$aFilter['blog_id'];
|
|
|
|
|
}
|
2008-09-26 23:52:26 +03:00
|
|
|
|
if (isset($aFilter['blog_type']) and is_array($aFilter['blog_type'])) {
|
|
|
|
|
$sWhere.=" AND b.blog_type in ('".join("','",$aFilter['blog_type'])."') ";
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
return $sWhere;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function AddFavouriteTopic(TopicEntity_FavouriteTopic $oFavouriteTopic) {
|
|
|
|
|
$sql = "INSERT INTO ".DB_TABLE_FAVOURITE_TOPIC."
|
|
|
|
|
(user_id,
|
2008-11-03 13:08:12 +02:00
|
|
|
|
topic_id,
|
|
|
|
|
topic_publish
|
2008-09-21 09:36:57 +03:00
|
|
|
|
)
|
2008-11-03 13:08:12 +02:00
|
|
|
|
VALUES(?d, ?d, ?d)
|
2008-09-21 09:36:57 +03:00
|
|
|
|
";
|
2008-11-03 13:08:12 +02:00
|
|
|
|
if ($this->oDb->query($sql,$oFavouriteTopic->getUserId(),$oFavouriteTopic->getTopicId(),$oFavouriteTopic->getTopicPublish())===0)
|
2008-09-21 09:36:57 +03:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function DeleteFavouriteTopic(TopicEntity_FavouriteTopic $oFavouriteTopic) {
|
|
|
|
|
$sql = "DELETE FROM ".DB_TABLE_FAVOURITE_TOPIC."
|
|
|
|
|
WHERE
|
|
|
|
|
user_id = ?d
|
|
|
|
|
AND
|
|
|
|
|
topic_id = ?d
|
|
|
|
|
";
|
|
|
|
|
if ($this->oDb->query($sql,$oFavouriteTopic->getUserId(),$oFavouriteTopic->getTopicId()))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-03 13:08:12 +02:00
|
|
|
|
public function SetFavouriteTopicPublish($sTopicId,$iPublish) {
|
|
|
|
|
$sql = "UPDATE ".DB_TABLE_FAVOURITE_TOPIC."
|
|
|
|
|
SET
|
|
|
|
|
topic_publish = ?d
|
|
|
|
|
WHERE
|
|
|
|
|
topic_id = ?d
|
|
|
|
|
";
|
|
|
|
|
return $this->oDb->query($sql,$iPublish,$sTopicId);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
public function GetFavouriteTopic($sTopicId,$sUserId) {
|
|
|
|
|
$sql = "SELECT * FROM ".DB_TABLE_FAVOURITE_TOPIC." WHERE topic_id = ?d and user_id = ?d ";
|
|
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sTopicId,$sUserId)) {
|
|
|
|
|
return new TopicEntity_FavouriteTopic($aRow);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetTopicsFavouriteByUserId($sUserId,&$iCount,$iCurrPage,$iPerPage) {
|
|
|
|
|
$iCurrentUserId=-1;
|
|
|
|
|
if (is_object($this->oUserCurrent)) {
|
|
|
|
|
$iCurrentUserId=$this->oUserCurrent->getId();
|
|
|
|
|
}
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
t.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
|
|
|
|
tv.vote_delta as user_vote_delta
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_FAVOURITE_TOPIC." as ft,
|
|
|
|
|
".DB_TABLE_TOPIC." as t
|
|
|
|
|
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tv ON tv.topic_id = t.topic_id,
|
|
|
|
|
|
|
|
|
|
".DB_TABLE_USER." as u,
|
|
|
|
|
".DB_TABLE_BLOG." as b
|
|
|
|
|
WHERE
|
|
|
|
|
ft.user_id = ?
|
|
|
|
|
AND
|
|
|
|
|
ft.topic_id=t.topic_id
|
|
|
|
|
AND
|
|
|
|
|
t.topic_publish = 1
|
|
|
|
|
AND
|
|
|
|
|
b.blog_type in ('personal','open')
|
|
|
|
|
AND
|
|
|
|
|
t.blog_id=b.blog_id
|
|
|
|
|
AND
|
|
|
|
|
t.user_id=u.user_id
|
|
|
|
|
ORDER BY t.topic_date_add desc
|
|
|
|
|
LIMIT ?d, ?d ;
|
|
|
|
|
";
|
2008-10-26 22:04:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql = " SELECT
|
|
|
|
|
t.*,
|
|
|
|
|
tc.*,
|
|
|
|
|
u.user_login as user_login,
|
|
|
|
|
b.blog_title as blog_title,
|
|
|
|
|
b.blog_type as blog_type,
|
|
|
|
|
b.blog_url as blog_url,
|
|
|
|
|
IF(tv.topic_id IS NULL,0,1) as user_is_vote,
|
|
|
|
|
tv.vote_delta as user_vote_delta,
|
|
|
|
|
IF(tqv.topic_id IS NULL,0,1) as user_question_is_vote
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_FAVOURITE_TOPIC."
|
|
|
|
|
WHERE
|
2008-11-03 13:08:12 +02:00
|
|
|
|
user_id = ?
|
|
|
|
|
and
|
|
|
|
|
topic_publish = 1
|
2008-10-26 22:04:05 +02:00
|
|
|
|
ORDER BY topic_id DESC
|
|
|
|
|
LIMIT ?d, ?d
|
|
|
|
|
) as tt
|
|
|
|
|
JOIN ".DB_TABLE_TOPIC." AS t ON tt.topic_id=t.topic_id
|
|
|
|
|
JOIN ".DB_TABLE_USER." AS u ON t.user_id=u.user_id
|
|
|
|
|
JOIN ".DB_TABLE_BLOG." AS b ON t.blog_id=b.blog_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id,
|
|
|
|
|
vote_delta
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tv ON tt.topic_id=tv.topic_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
topic_id
|
|
|
|
|
FROM ".DB_TABLE_TOPIC_QUESTION_VOTE."
|
|
|
|
|
WHERE user_voter_id = ?d
|
|
|
|
|
) AS tqv ON tt.topic_id=tqv.topic_id
|
|
|
|
|
LEFT JOIN ".DB_TABLE_TOPIC_CONTENT." AS tc ON tt.topic_id=tc.topic_id
|
2008-11-21 20:50:46 +02:00
|
|
|
|
order by t.topic_id DESC
|
2008-10-26 22:04:05 +02:00
|
|
|
|
;
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
$aTopics=array();
|
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId,($iCurrPage-1)*$iPerPage, $iPerPage,$iCurrentUserId,$iCurrentUserId)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
foreach ($aRows as $aTopic) {
|
|
|
|
|
$aTopics[]=new TopicEntity_Topic($aTopic);
|
|
|
|
|
}
|
2008-10-26 22:04:05 +02:00
|
|
|
|
$iCount=$this->GetCountTopicsFavouriteByUserId($sUserId);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
2008-10-26 22:04:05 +02:00
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
return $aTopics;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-26 22:04:05 +02:00
|
|
|
|
public function GetCountTopicsFavouriteByUserId($sUserId) {
|
|
|
|
|
$sql = "SELECT
|
|
|
|
|
count(topic_id) as count
|
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_FAVOURITE_TOPIC."
|
|
|
|
|
WHERE
|
2008-11-03 13:08:12 +02:00
|
|
|
|
user_id = ?
|
|
|
|
|
and
|
|
|
|
|
topic_publish = 1;
|
2008-10-26 22:04:05 +02:00
|
|
|
|
";
|
|
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sUserId)) {
|
|
|
|
|
return $aRow['count'];
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
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
|
|
|
|
|
".DB_TABLE_TOPIC_TAG."
|
|
|
|
|
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) {
|
|
|
|
|
$aReturn[]=new TopicEntity_TopicTag($aRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aReturn;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 11:54:59 +02:00
|
|
|
|
public function UpdateTopicRead(TopicEntity_TopicRead $oTopicRead) {
|
2008-12-28 12:51:59 +02:00
|
|
|
|
$sql = "UPDATE ".DB_TABLE_TOPIC_READ."
|
|
|
|
|
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) {
|
2008-12-28 12:51:59 +02:00
|
|
|
|
$sql = "INSERT INTO ".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-01-24 11:54:59 +02:00
|
|
|
|
public function GetTopicRead($sTopicId,$sUserId) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
$sql = "SELECT
|
2009-01-24 11:54:59 +02:00
|
|
|
|
*
|
2008-09-21 09:36:57 +03:00
|
|
|
|
FROM
|
|
|
|
|
".DB_TABLE_TOPIC_READ."
|
|
|
|
|
WHERE
|
|
|
|
|
topic_id = ?d
|
|
|
|
|
AND
|
|
|
|
|
user_id = ?d
|
|
|
|
|
;
|
|
|
|
|
";
|
|
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sTopicId,$sUserId)) {
|
2009-01-24 11:54:59 +02:00
|
|
|
|
return new TopicEntity_TopicRead($aRow);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-10-01 21:53:51 +03:00
|
|
|
|
|
|
|
|
|
public function AddTopicQuestionVote(TopicEntity_TopicQuestionVote $oTopicQuestionVote) {
|
|
|
|
|
$sql = "INSERT INTO ".DB_TABLE_TOPIC_QUESTION_VOTE."
|
|
|
|
|
(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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetTopicQuestionVote($sTopicId,$sUserId) {
|
|
|
|
|
$sql = "SELECT * FROM ".DB_TABLE_TOPIC_QUESTION_VOTE." WHERE topic_id = ?d and user_voter_id = ?d ";
|
|
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sTopicId,$sUserId)) {
|
|
|
|
|
return new TopicEntity_TopicQuestionVote($aRow);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
?>
|