2009-06-23 20:06:19 +03:00
< ? php
/*-------------------------------------------------------
*
* 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
*
---------------------------------------------------------
*/
2010-05-27 23:40:30 +03:00
class ModuleComment_MapperComment extends Mapper {
2009-06-23 20:06:19 +03:00
2010-03-28 22:40:51 +03:00
public function GetCommentsRatingByDate ( $sDate , $sTargetType , $iLimit , $aExcludeTarget = array (), $aExcludeParentTarget = array ()) {
2009-06-23 20:06:19 +03:00
$sql = " SELECT
comment_id
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.comment'). "
2009-06-23 20:06:19 +03:00
WHERE
2010-03-28 22:40:51 +03:00
target_type = ?
AND
comment_date >= ?
AND
comment_rating >= 0
2009-06-23 20:06:19 +03:00
AND
comment_delete = 0
AND
comment_publish = 1
2009-09-19 17:48:28 +03:00
{ AND target_id NOT IN ( ? a ) }
2010-03-28 22:40:51 +03:00
{ AND target_parent_id NOT IN ( ? a ) }
2009-06-23 20:06:19 +03:00
ORDER by comment_rating desc , comment_id desc
LIMIT 0 , ? d " ;
2009-09-19 17:48:28 +03:00
$aComments = array ();
if ( $aRows = $this -> oDb -> select (
$sql , $sTargetType , $sDate ,
( is_array ( $aExcludeTarget ) && count ( $aExcludeTarget )) ? $aExcludeTarget : DBSIMPLE_SKIP ,
2010-03-28 22:40:51 +03:00
( count ( $aExcludeParentTarget ) ? $aExcludeParentTarget : DBSIMPLE_SKIP ),
2009-09-19 17:48:28 +03:00
$iLimit
)
) {
2009-06-23 20:06:19 +03:00
foreach ( $aRows as $aRow ) {
$aComments [] = $aRow [ 'comment_id' ];
}
}
return $aComments ;
}
public function GetCommentUnique ( $sTargetId , $sTargetType , $sUserId , $sCommentPid , $sHash ) {
2009-08-20 15:50:14 +03:00
$sql = " SELECT comment_id FROM " . Config :: Get ( 'db.table.comment' ) . "
2009-06-23 20:06:19 +03:00
WHERE
target_id = ? d
AND
target_type = ?
AND
user_id = ? d
AND
(( comment_pid = ? ) or ( ? is NULL and comment_pid is NULL ))
AND
comment_text_hash = ?
" ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sTargetId , $sTargetType , $sUserId , $sCommentPid , $sCommentPid , $sHash )) {
return $aRow [ 'comment_id' ];
}
return null ;
}
2009-11-18 20:46:16 +02:00
public function GetCommentsAll ( $sTargetType , & $iCount , $iCurrPage , $iPerPage , $aExcludeTarget = array (), $aExcludeParentTarget = array ()) {
2009-06-23 20:06:19 +03:00
$sql = " SELECT
comment_id
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.comment'). "
2009-06-23 20:06:19 +03:00
WHERE
target_type = ?
AND
comment_delete = 0
AND
comment_publish = 1
2009-10-15 18:52:53 +03:00
{ AND target_id NOT IN ( ? a ) }
2009-11-18 20:46:16 +02:00
{ AND target_parent_id NOT IN ( ? a ) }
2009-06-23 20:06:19 +03:00
ORDER by comment_id desc
LIMIT ? d , ? d " ;
$aComments = array ();
2009-10-15 18:52:53 +03:00
if ( $aRows = $this -> oDb -> selectPage (
$iCount , $sql , $sTargetType ,
( count ( $aExcludeTarget ) ? $aExcludeTarget : DBSIMPLE_SKIP ),
2009-11-18 20:46:16 +02:00
( count ( $aExcludeParentTarget ) ? $aExcludeParentTarget : DBSIMPLE_SKIP ),
2009-10-15 18:52:53 +03:00
( $iCurrPage - 1 ) * $iPerPage , $iPerPage
)
) {
2009-06-23 20:06:19 +03:00
foreach ( $aRows as $aRow ) {
$aComments [] = $aRow [ 'comment_id' ];
}
}
return $aComments ;
}
public function GetCommentsByArrayId ( $aArrayId ) {
if ( ! is_array ( $aArrayId ) or count ( $aArrayId ) == 0 ) {
return array ();
}
$sql = " SELECT
*
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.comment'). "
2009-06-23 20:06:19 +03:00
WHERE
comment_id IN ( ? a )
ORDER by FIELD ( comment_id , ? a ) " ;
$aComments = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $aArrayId , $aArrayId )) {
foreach ( $aRows as $aRow ) {
2009-09-08 15:02:51 +03:00
$aComments [] = Engine :: GetEntity ( 'Comment' , $aRow );
2009-06-23 20:06:19 +03:00
}
}
return $aComments ;
}
2009-11-18 20:46:16 +02:00
public function GetCommentsOnline ( $sTargetType , $aExcludeTargets , $iLimit ) {
2009-06-23 20:06:19 +03:00
$sql = " SELECT
comment_id
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.comment_online'). "
2009-06-23 20:06:19 +03:00
WHERE
2009-09-19 03:43:00 +03:00
target_type = ?
2009-11-18 20:46:16 +02:00
{ AND target_parent_id NOT IN ( ? a ) }
2009-09-19 03:43:00 +03:00
ORDER by comment_online_id desc limit 0 , ? d ; " ;
2009-06-23 20:06:19 +03:00
$aComments = array ();
2009-09-19 03:43:00 +03:00
if ( $aRows = $this -> oDb -> select (
$sql , $sTargetType ,
2009-11-18 20:46:16 +02:00
( count ( $aExcludeTargets ) ? $aExcludeTargets : DBSIMPLE_SKIP ),
2009-09-19 03:43:00 +03:00
$iLimit
)
) {
2009-06-23 20:06:19 +03:00
foreach ( $aRows as $aRow ) {
$aComments [] = $aRow [ 'comment_id' ];
}
}
return $aComments ;
}
public function GetCommentsByTargetId ( $sId , $sTargetType ) {
$sql = " SELECT
comment_id ,
comment_id as ARRAY_KEY ,
comment_pid as PARENT_KEY
FROM
2009-11-18 20:46:16 +02:00
" .Config::Get('db.table.comment'). "
2009-06-23 20:06:19 +03:00
WHERE
target_id = ? d
AND
2009-11-18 20:46:16 +02:00
target_type = ?
2009-06-23 20:06:19 +03:00
ORDER by comment_id asc ;
" ;
if ( $aRows = $this -> oDb -> select ( $sql , $sId , $sTargetType )) {
return $aRows ;
}
return null ;
}
2010-09-19 00:58:52 +03:00
public function GetCommentsTreeByTargetId ( $sId , $sTargetType ) {
$sql = " SELECT
comment_id
FROM
" .Config::Get('db.table.comment'). "
WHERE
target_id = ? d
AND
target_type = ?
ORDER by comment_left asc ;
" ;
$aComments = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $sId , $sTargetType )) {
foreach ( $aRows as $aRow ) {
$aComments [] = $aRow [ 'comment_id' ];
}
}
return $aComments ;
}
public function GetCommentsTreePageByTargetId ( $sId , $sTargetType , & $iCount , $iPage , $iPerPage ) {
/**
* Сначала получаем корни и определяем границы выборки веток
*/
$sql = " SELECT
comment_left ,
comment_right
FROM
" .Config::Get('db.table.comment'). "
WHERE
target_id = ? d
AND
target_type = ?
AND
comment_pid IS NULL
2010-09-19 12:27:13 +03:00
ORDER by comment_left desc
2010-09-19 00:58:52 +03:00
LIMIT ? d , ? d ; " ;
$aComments = array ();
if ( $aRows = $this -> oDb -> selectPage ( $iCount , $sql , $sId , $sTargetType ,( $iPage - 1 ) * $iPerPage , $iPerPage )) {
2010-09-19 12:27:13 +03:00
$aCmt = array_pop ( $aRows );
2010-09-19 00:58:52 +03:00
$iLeft = $aCmt [ 'comment_left' ];
if ( $aRows ) {
2010-09-19 12:27:13 +03:00
$aCmt = array_shift ( $aRows );
2010-09-19 00:58:52 +03:00
}
$iRight = $aCmt [ 'comment_right' ];
} else {
return array ();
}
/**
* Теперь получаем полный список комментов
*/
$sql = " SELECT
comment_id
FROM
" .Config::Get('db.table.comment'). "
WHERE
target_id = ? d
AND
target_type = ?
AND
comment_left >= ? d
AND
comment_right <= ? d
ORDER by comment_left asc ;
" ;
$aComments = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $sId , $sTargetType , $iLeft , $iRight )) {
foreach ( $aRows as $aRow ) {
$aComments [] = $aRow [ 'comment_id' ];
}
}
return $aComments ;
}
public function GetCountCommentsRootByTargetId ( $sId , $sTargetType ) {
$sql = " SELECT
count ( comment_id ) as c
FROM
" .Config::Get('db.table.comment'). "
WHERE
target_id = ? d
AND
target_type = ?
AND
comment_pid IS NULL ; " ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sId , $sTargetType )) {
return $aRow [ 'c' ];
}
}
2010-09-19 12:27:13 +03:00
public function GetCountCommentsAfterByTargetId ( $sId , $sTargetType , $iLeft ) {
$sql = " SELECT
count ( comment_id ) as c
FROM
" .Config::Get('db.table.comment'). "
WHERE
target_id = ? d
AND
target_type = ?
AND
comment_pid IS NULL
AND
comment_left >= ? d ; " ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sId , $sTargetType , $iLeft )) {
return $aRow [ 'c' ];
}
}
public function GetCommentRootByTargetIdAndChildren ( $sId , $sTargetType , $iLeft ) {
$sql = " SELECT
*
FROM
" .Config::Get('db.table.comment'). "
WHERE
target_id = ? d
AND
target_type = ?
AND
comment_pid IS NULL
AND
comment_left < ? d
AND
comment_right > ? d
LIMIT 0 , 1 ; " ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sId , $sTargetType , $iLeft , $iLeft )) {
return Engine :: GetEntity ( 'Comment' , $aRow );
}
return null ;
}
2010-09-19 00:58:52 +03:00
2009-06-23 20:06:19 +03:00
public function GetCommentsNewByTargetId ( $sId , $sTargetType , $sIdCommentLast ) {
$sql = " SELECT
comment_id
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.comment'). "
2009-06-23 20:06:19 +03:00
WHERE
target_id = ? d
AND
target_type = ?
AND
comment_id > ? d
2009-06-24 00:35:20 +03:00
ORDER by comment_id asc ;
2009-06-23 20:06:19 +03:00
" ;
2009-06-24 00:35:20 +03:00
$aComments = array ();
2009-06-23 20:06:19 +03:00
if ( $aRows = $this -> oDb -> select ( $sql , $sId , $sTargetType , $sIdCommentLast )) {
2009-06-24 00:35:20 +03:00
foreach ( $aRows as $aRow ) {
$aComments [] = $aRow [ 'comment_id' ];
}
2009-06-23 20:06:19 +03:00
}
2009-06-24 00:35:20 +03:00
return $aComments ;
2009-06-23 20:06:19 +03:00
}
2009-11-18 20:46:16 +02:00
public function GetCommentsByUserId ( $sId , $sTargetType , & $iCount , $iCurrPage , $iPerPage , $aExcludeTarget = array (), $aExcludeParentTarget = array ()) {
2009-06-23 20:06:19 +03:00
$sql = " SELECT
comment_id
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.comment'). "
2009-06-23 20:06:19 +03:00
WHERE
user_id = ? d
AND
target_type = ?
AND
comment_delete = 0
AND
2009-09-18 23:36:07 +03:00
comment_publish = 1
{ AND target_id NOT IN ( ? a ) }
2009-11-18 20:46:16 +02:00
{ AND target_parent_id NOT IN ( ? a ) }
2009-06-23 20:06:19 +03:00
ORDER by comment_id desc
LIMIT ? d , ? d " ;
$aComments = array ();
2009-09-18 23:36:07 +03:00
if ( $aRows = $this -> oDb -> selectPage (
$iCount , $sql , $sId ,
$sTargetType ,
( count ( $aExcludeTarget ) ? $aExcludeTarget : DBSIMPLE_SKIP ),
2009-11-18 20:46:16 +02:00
( count ( $aExcludeParentTarget ) ? $aExcludeParentTarget : DBSIMPLE_SKIP ),
2009-09-18 23:36:07 +03:00
( $iCurrPage - 1 ) * $iPerPage , $iPerPage
)
) {
2009-06-23 20:06:19 +03:00
foreach ( $aRows as $aRow ) {
$aComments [] = $aRow [ 'comment_id' ];
}
}
return $aComments ;
}
2009-11-18 20:46:16 +02:00
public function GetCountCommentsByUserId ( $sId , $sTargetType , $aExcludeTarget = array (), $aExcludeParentTarget = array ()) {
2009-06-23 20:06:19 +03:00
$sql = " SELECT
count ( comment_id ) as count
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.comment'). "
2009-06-23 20:06:19 +03:00
WHERE
user_id = ? d
AND
target_type = ?
AND
comment_delete = 0
AND
comment_publish = 1
2009-09-18 23:36:07 +03:00
{ AND target_id NOT IN ( ? a ) }
2009-11-18 20:46:16 +02:00
{ AND target_parent_id NOT IN ( ? a ) }
2009-06-23 20:06:19 +03:00
" ;
2009-09-18 23:36:07 +03:00
if ( $aRow = $this -> oDb -> selectRow (
$sql , $sId , $sTargetType ,
2009-11-18 20:46:16 +02:00
( count ( $aExcludeTarget ) ? $aExcludeTarget : DBSIMPLE_SKIP ),
( count ( $aExcludeParentTarget ) ? $aExcludeParentTarget : DBSIMPLE_SKIP )
2009-09-18 23:36:07 +03:00
)
) {
2009-06-23 20:06:19 +03:00
return $aRow [ 'count' ];
}
return false ;
}
2010-05-27 18:16:20 +03:00
public function AddComment ( ModuleComment_EntityComment $oComment ) {
2009-08-20 15:50:14 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.comment' ) . "
2009-06-23 20:06:19 +03:00
( comment_pid ,
target_id ,
target_type ,
2009-11-18 20:46:16 +02:00
target_parent_id ,
2009-06-23 20:06:19 +03:00
user_id ,
comment_text ,
comment_date ,
comment_user_ip ,
2011-08-03 11:24:42 +03:00
comment_publish ,
2009-06-23 20:06:19 +03:00
comment_text_hash
)
2011-08-03 11:24:42 +03:00
VALUES ( ? , ? d , ? , ? d , ? d , ? , ? , ? , ? d , ? )
2009-06-23 20:06:19 +03:00
" ;
2011-08-03 11:24:42 +03:00
if ( $iId = $this -> oDb -> query ( $sql , $oComment -> getPid (), $oComment -> getTargetId (), $oComment -> getTargetType (), $oComment -> getTargetParentId (), $oComment -> getUserId (), $oComment -> getText (), $oComment -> getDate (), $oComment -> getUserIp (), $oComment -> getPublish (), $oComment -> getTextHash ()))
2009-06-23 20:06:19 +03:00
{
return $iId ;
2009-11-18 20:46:16 +02:00
}
2009-06-23 20:06:19 +03:00
return false ;
}
2010-09-19 00:58:52 +03:00
public function AddCommentTree ( ModuleComment_EntityComment $oComment ) {
$this -> oDb -> transaction ();
if ( $oComment -> getPid () and $oCommentParent = $this -> GetCommentsByArrayId ( array ( $oComment -> getPid ()))) {
$oCommentParent = $oCommentParent [ 0 ];
$iLeft = $oCommentParent -> getRight ();
$iLevel = $oCommentParent -> getLevel () + 1 ;
$sql = " UPDATE " . Config :: Get ( 'db.table.comment' ) . " SET comment_left=comment_left+2 WHERE target_id=?d and target_type=? and comment_left>? ; " ;
$this -> oDb -> query ( $sql , $oComment -> getTargetId (), $oComment -> getTargetType (), $iLeft - 1 );
$sql = " UPDATE " . Config :: Get ( 'db.table.comment' ) . " SET comment_right=comment_right+2 WHERE target_id=?d and target_type=? and comment_right>? ; " ;
$this -> oDb -> query ( $sql , $oComment -> getTargetId (), $oComment -> getTargetType (), $iLeft - 1 );
} else {
if ( $oCommentLast = $this -> GetCommentLast ( $oComment -> getTargetId (), $oComment -> getTargetType ())) {
$iLeft = $oCommentLast -> getRight () + 1 ;
} else {
$iLeft = 1 ;
}
$iLevel = 0 ;
}
if ( $iId = $this -> AddComment ( $oComment )) {
$sql = " UPDATE " . Config :: Get ( 'db.table.comment' ) . " SET comment_left = ?d, comment_right = ?d, comment_level = ?d WHERE comment_id = ? ; " ;
$this -> oDb -> query ( $sql , $iLeft , $iLeft + 1 , $iLevel , $iId );
$this -> oDb -> commit ();
return $iId ;
}
if ( strtolower ( Config :: Get ( 'db.tables.engine' )) == 'innodb' ) {
$this -> oDb -> rollback ();
}
return false ;
}
2009-06-23 20:06:19 +03:00
2010-09-19 00:58:52 +03:00
public function GetCommentLast ( $sTargetId , $sTargetType ) {
$sql = " SELECT * FROM " . Config :: Get ( 'db.table.comment' ) . "
WHERE
target_id = ? d
AND
target_type = ?
ORDER BY comment_right DESC
LIMIT 0 , 1
" ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sTargetId , $sTargetType )) {
return Engine :: GetEntity ( 'Comment' , $aRow );
}
return null ;
}
2009-06-23 20:06:19 +03:00
2010-05-27 18:16:20 +03:00
public function AddCommentOnline ( ModuleComment_EntityCommentOnline $oCommentOnline ) {
2009-08-20 15:50:14 +03:00
$sql = " REPLACE INTO " . Config :: Get ( 'db.table.comment_online' ) . "
2009-06-23 20:06:19 +03:00
SET
target_id = ? d ,
2009-11-18 20:46:16 +02:00
target_type = ? ,
target_parent_id = ? d ,
2009-06-23 20:06:19 +03:00
comment_id = ? d
" ;
2009-11-18 20:46:16 +02:00
if ( $iId = $this -> oDb -> query ( $sql , $oCommentOnline -> getTargetId (), $oCommentOnline -> getTargetType (), $oCommentOnline -> getTargetParentId (), $oCommentOnline -> getCommentId ()))
2009-06-23 20:06:19 +03:00
{
return $iId ;
}
return false ;
}
public function DeleteCommentOnlineByTargetId ( $sTargetId , $sTargetType ) {
2009-08-20 15:50:14 +03:00
$sql = " DELETE FROM " . Config :: Get ( 'db.table.comment_online' ) . " WHERE target_id = ?d and target_type = ? " ;
2009-06-23 20:06:19 +03:00
if ( $this -> oDb -> query ( $sql , $sTargetId , $sTargetType ))
{
return true ;
}
return false ;
}
2010-05-27 18:16:20 +03:00
public function UpdateComment ( ModuleComment_EntityComment $oComment ) {
2009-08-20 15:50:14 +03:00
$sql = " UPDATE " . Config :: Get ( 'db.table.comment' ) . "
2009-06-23 20:06:19 +03:00
SET
comment_text = ? ,
comment_rating = ? f ,
comment_count_vote = ? d ,
comment_delete = ? d ,
comment_publish = ? d ,
comment_text_hash = ?
WHERE
comment_id = ? d
" ;
if ( $this -> oDb -> query ( $sql , $oComment -> getText (), $oComment -> getRating (), $oComment -> getCountVote (), $oComment -> getDelete (), $oComment -> getPublish (), $oComment -> getTextHash (), $oComment -> getId ())) {
return true ;
}
return false ;
}
public function SetCommentsPublish ( $sTargetId , $sTargetType , $iPublish ) {
2009-08-20 15:50:14 +03:00
$sql = " UPDATE " . Config :: Get ( 'db.table.comment' ) . "
2009-06-23 20:06:19 +03:00
SET
comment_publish = ?
WHERE
target_id = ? d AND target_type = ?
" ;
if ( $this -> oDb -> query ( $sql , $iPublish , $sTargetId , $sTargetType )) {
return true ;
}
return false ;
}
2009-10-25 22:01:05 +02:00
public function DeleteCommentByTargetId ( $aTargetId , $sTargetType ) {
$sql = "
DELETE FROM " .Config::Get('db.table.comment'). "
WHERE
2010-03-28 22:40:51 +03:00
target_id IN ( ? a )
2009-10-25 22:01:05 +02:00
AND
2010-03-28 22:40:51 +03:00
target_type = ?
2009-10-25 22:01:05 +02:00
" ;
2010-03-28 22:40:51 +03:00
if ( $this -> oDb -> query ( $sql , $aTargetId , $sTargetType )) {
2009-10-25 22:01:05 +02:00
return true ;
}
return false ;
}
public function DeleteCommentOnlineByArrayId ( $aCommentId , $sTargetType ) {
$sql = "
DELETE FROM " .Config::Get('db.table.comment_online'). "
WHERE
comment_id IN ( ? a )
AND
target_type = ?
" ;
if ( $this -> oDb -> query ( $sql , $aCommentId , $sTargetType )) {
return true ;
}
return false ;
}
2009-11-18 21:46:21 +02:00
public function UpdateTargetParentByTargetId ( $sParentId , $sTargetType , $aTargetId ) {
$sql = "
UPDATE " .Config::Get('db.table.comment'). "
SET
target_parent_id = ? d
WHERE
target_id IN ( ? a )
AND
target_type = ?
" ;
if ( $this -> oDb -> query ( $sql , $sParentId , $aTargetId , $sTargetType )) {
return true ;
}
return false ;
}
public function UpdateTargetParentByTargetIdOnline ( $sParentId , $sTargetType , $aTargetId ) {
$sql = "
UPDATE " .Config::Get('db.table.comment_online'). "
SET
target_parent_id = ? d
WHERE
target_id IN ( ? a )
AND
target_type = ?
" ;
if ( $this -> oDb -> query ( $sql , $sParentId , $aTargetId , $sTargetType )) {
return true ;
}
return false ;
}
2010-04-17 20:55:22 +03:00
public function MoveTargetParent ( $sParentId , $sTargetType , $sParentIdNew ) {
$sql = "
UPDATE " .Config::Get('db.table.comment'). "
SET
target_parent_id = ? d
WHERE
target_parent_id = ? d
AND
target_type = ?
" ;
if ( $this -> oDb -> query ( $sql , $sParentIdNew , $sParentId , $sTargetType )) {
return true ;
}
return false ;
}
public function MoveTargetParentOnline ( $sParentId , $sTargetType , $sParentIdNew ) {
$sql = "
UPDATE " .Config::Get('db.table.comment_online'). "
SET
target_parent_id = ? d
WHERE
target_parent_id = ? d
AND
target_type = ?
" ;
if ( $this -> oDb -> query ( $sql , $sParentIdNew , $sParentId , $sTargetType )) {
return true ;
}
return false ;
}
2010-09-19 00:58:52 +03:00
public function RestoreTree ( $iPid , $iLft , $iLevel , $aTargetId , $sTargetType ) {
$iRgt = $iLft + 1 ;
$iLevel ++ ;
$sql = " SELECT comment_id FROM " . Config :: Get ( 'db.table.comment' ) . " WHERE target_id = ? and target_type = ? { and comment_pid = ? } { and comment_pid IS NULL and 1=?d}
ORDER BY comment_id ASC " ;
if ( $aRows = $this -> oDb -> select ( $sql , $aTargetId , $sTargetType , ! is_null ( $iPid ) ? $iPid : DBSIMPLE_SKIP , is_null ( $iPid ) ? 1 : DBSIMPLE_SKIP )) {
foreach ( $aRows as $aRow ) {
$iRgt = $this -> RestoreTree ( $aRow [ 'comment_id' ], $iRgt , $iLevel , $aTargetId , $sTargetType );
}
}
2010-09-19 13:09:31 +03:00
$iLevel -- ;
if ( ! is_null ( $iPid )) {
$sql = " UPDATE " . Config :: Get ( 'db.table.comment' ) . "
SET comment_left = ? d , comment_right = ? d , comment_level = ? d
WHERE comment_id = ? " ;
$this -> oDb -> query ( $sql , $iLft , $iRgt , $iLevel , $iPid );
}
2010-09-19 00:58:52 +03:00
return $iRgt + 1 ;
}
2010-09-19 13:09:31 +03:00
public function GetCommentTypes () {
$sql = " SELECT target_type FROM " . Config :: Get ( 'db.table.comment' ) . "
GROUP BY target_type " ;
$aTypes = array ();
if ( $aRows = $this -> oDb -> select ( $sql )) {
foreach ( $aRows as $aRow ) {
$aTypes [] = $aRow [ 'target_type' ];
}
}
return $aTypes ;
}
public function GetTargetIdByType ( $sTargetType , $iPage , $iPerPage ) {
$sql = " SELECT target_id FROM " . Config :: Get ( 'db.table.comment' ) . "
WHERE target_type = ? GROUP BY target_id ORDER BY target_id LIMIT ? d , ? d " ;
if ( $aRows = $this -> oDb -> select ( $sql , $sTargetType ,( $iPage - 1 ) * $iPerPage , $iPerPage )) {
return $aRows ;
}
return array ();
}
2009-06-23 20:06:19 +03:00
}
?>