ModuleComment_MapperComment
Package | application.modules.comment |
---|---|
Inheritance | class ModuleComment_MapperComment » Mapper » LsObject |
Since | 1.0 |
Source Code | /application/classes/modules/comment/mapper/Comment.mapper.class.php |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
_aBehaviors | Список поведений в виде готовых объектов, формируется автоматически | LsObject | |
aBehaviors | array | Список поведений | LsObject |
oDb | DbSimple_Database | Объект подключения к базе данных | Mapper |
Public Methods
Method | Description | Defined By |
---|---|---|
AddBehaviorHook() | Добавляет хук поведения | LsObject |
AddComment() | Добавляет коммент | ModuleComment_MapperComment |
AddCommentOnline() | Добавляет новый коммент в прямой эфир | ModuleComment_MapperComment |
AddCommentTree() | Добавляет коммент в дерево nested set | ModuleComment_MapperComment |
AttachBehavior() | Присоединяет поведение к объекту | LsObject |
DeleteCommentByTargetId() | Удаляет комментарии из базы данных | ModuleComment_MapperComment |
DeleteCommentOnlineByArrayId() | Удаляет коммент из прямого эфира по массиву переданных идентификаторов | ModuleComment_MapperComment |
DeleteCommentOnlineByTargetId() | Удаляет коммент из прямого эфира | ModuleComment_MapperComment |
DetachBehavior() | Отсоединяет поведение от объекта | LsObject |
GetBehavior() | Возвращает объект поведения по его имени | LsObject |
GetBehaviors() | Возвращает все объекты поведения | LsObject |
GetCommentLast() | Возвращает последний комментарий | ModuleComment_MapperComment |
GetCommentRootByTargetIdAndChildren() | Возвращает корневой комментарий | ModuleComment_MapperComment |
GetCommentTypes() | Возвращает список всех используемых типов владельца | ModuleComment_MapperComment |
GetCommentUnique() | Получает уникальный коммент, это помогает спастись от дублей комментов | ModuleComment_MapperComment |
GetCommentsAll() | Получить все комменты | ModuleComment_MapperComment |
GetCommentsByArrayId() | Список комментов по ID | ModuleComment_MapperComment |
GetCommentsByFilter() | Получает список комментариев по фильтру | ModuleComment_MapperComment |
GetCommentsByTargetId() | Получить комменты по владельцу | ModuleComment_MapperComment |
GetCommentsByUserId() | Получить комменты по юзеру | ModuleComment_MapperComment |
GetCommentsNewByTargetId() | Получить новые комменты для владельца | ModuleComment_MapperComment |
GetCommentsOnline() | Получить все комменты сгрупированные по типу(для вывода прямого эфира) | ModuleComment_MapperComment |
GetCommentsRatingByDate() | Получить комменты по рейтингу и дате | ModuleComment_MapperComment |
GetCommentsTreeByTargetId() | Получает комменты используя nested set | ModuleComment_MapperComment |
GetCommentsTreePageByTargetId() | Получает комменты используя nested set | ModuleComment_MapperComment |
GetCountCommentsAfterByTargetId() | Возвращает количество комментариев | ModuleComment_MapperComment |
GetCountCommentsByUserId() | Получает количество комментариев одного пользователя | ModuleComment_MapperComment |
GetCountCommentsRootByTargetId() | Возвращает количество дочерних комментариев у корневого коммента | ModuleComment_MapperComment |
GetTargetIdByType() | Возвращает список ID владельцев | ModuleComment_MapperComment |
MoveTargetParent() | Меняет target parent на новый | ModuleComment_MapperComment |
MoveTargetParentOnline() | Меняет target parent на новый в прямом эфире | ModuleComment_MapperComment |
RecalculateFavourite() | Пересчитывает счетчик избранных комментариев | ModuleComment_MapperComment |
RemoveBehaviorHook() | Удаляет хук поведения | LsObject |
RestoreTree() | Перестраивает дерево комментариев | ModuleComment_MapperComment |
RunBehaviorHook() | Запускает хук поведения на выполнение | LsObject |
SetCommentsPublish() | Устанавливает publish у коммента | ModuleComment_MapperComment |
UpdateComment() | Обновляет коммент | ModuleComment_MapperComment |
UpdateTargetParentByTargetId() | Меняем target parent по массиву идентификаторов | ModuleComment_MapperComment |
UpdateTargetParentByTargetIdOnline() | Меняем target parent по массиву идентификаторов в таблице комментариев online | ModuleComment_MapperComment |
__call() | Ставим хук на вызов неизвестного метода и считаем что хотели вызвать метод какого либо модуля | LsObject |
__clone() | При клонировании сбрасываем поведения | LsObject |
__construct() | Передаем коннект к БД | Mapper |
__get() | Обработка доступа к объекты поведения | LsObject |
Protected Methods
Method | Description | Defined By |
---|---|---|
IsSuccessful() | Mapper | |
PrepareBehaviors() | Инициализация поведений | LsObject |
Method Details
public bool|int AddComment(ModuleComment_EntityComment $oComment)
| ||
$oComment | ModuleComment_EntityComment | Объект комментария |
{return} | bool|int |
public function AddComment(ModuleComment_EntityComment $oComment)
{
$sql = "INSERT INTO " . Config::Get('db.table.comment') . "
(comment_pid,
target_id,
target_type,
target_parent_id,
user_id,
comment_text,
comment_text_source,
comment_date,
comment_user_ip,
comment_publish,
comment_text_hash
)
VALUES(?, ?d, ?, ?d, ?d, ?, ?, ?, ?, ?d, ?)
";
if ($iId = $this->oDb->query($sql, $oComment->getPid(), $oComment->getTargetId(), $oComment->getTargetType(),
$oComment->getTargetParentId(), $oComment->getUserId(), $oComment->getText(), $oComment->getTextSource(),
$oComment->getDate(), $oComment->getUserIp(), $oComment->getPublish(), $oComment->getTextHash())
) {
return $iId;
}
return false;
}
Добавляет коммент
public bool|int AddCommentOnline(ModuleComment_EntityCommentOnline $oCommentOnline)
| ||
$oCommentOnline | ModuleComment_EntityCommentOnline | Объект онлайн комментария |
{return} | bool|int |
public function AddCommentOnline(ModuleComment_EntityCommentOnline $oCommentOnline)
{
$sql = "REPLACE INTO " . Config::Get('db.table.comment_online') . "
SET
target_id= ?d ,
target_type= ? ,
target_parent_id = ?d,
comment_id= ?d
";
if ($iId = $this->oDb->query($sql, $oCommentOnline->getTargetId(), $oCommentOnline->getTargetType(),
$oCommentOnline->getTargetParentId(), $oCommentOnline->getCommentId())
) {
return $iId;
}
return false;
}
Добавляет новый коммент в прямой эфир
public bool|int AddCommentTree(ModuleComment_EntityComment $oComment)
| ||
$oComment | ModuleComment_EntityComment | Объект комментария |
{return} | bool|int |
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;
}
Добавляет коммент в дерево nested set
public bool DeleteCommentByTargetId(array|int $aTargetId, string $sTargetType)
| ||
$aTargetId | array|int | Список ID владельцев |
$sTargetType | string | Тип владельцев |
{return} | bool |
public function DeleteCommentByTargetId($aTargetId, $sTargetType)
{
$sql = "
DELETE FROM " . Config::Get('db.table.comment') . "
WHERE
target_id IN (?a)
AND
target_type = ?
ORDER BY comment_id DESC
";
$res = $this->oDb->query($sql, $aTargetId, $sTargetType);
return $this->IsSuccessful($res);
}
Удаляет комментарии из базы данных
public bool DeleteCommentOnlineByArrayId(array|int $aCommentId, string $sTargetType)
| ||
$aCommentId | array|int | |
$sTargetType | string | Тип владельцев |
{return} | bool |
public function DeleteCommentOnlineByArrayId($aCommentId, $sTargetType)
{
$sql = "
DELETE FROM " . Config::Get('db.table.comment_online') . "
WHERE
comment_id IN (?a)
AND
target_type = ?
";
$res = $this->oDb->query($sql, $aCommentId, $sTargetType);
return $this->IsSuccessful($res);
}
Удаляет коммент из прямого эфира по массиву переданных идентификаторов
public bool DeleteCommentOnlineByTargetId(int $sTargetId, string $sTargetType)
| ||
$sTargetId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
{return} | bool |
public function DeleteCommentOnlineByTargetId($sTargetId, $sTargetType)
{
$sql = "DELETE FROM " . Config::Get('db.table.comment_online') . " WHERE target_id = ?d and target_type = ? ";
$res = $this->oDb->query($sql, $sTargetId, $sTargetType);
return $this->IsSuccessful($res);
}
Удаляет коммент из прямого эфира
public ModuleComment_EntityComment|null GetCommentLast(int $sTargetId, string $sTargetType)
| ||
$sTargetId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
{return} | ModuleComment_EntityComment|null |
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;
}
Возвращает последний комментарий
public ModuleComment_EntityComment|null GetCommentRootByTargetIdAndChildren(int $sId, string $sTargetType, int $iLeft)
| ||
$sId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
$iLeft | int | Значение left для дерева nested set |
{return} | ModuleComment_EntityComment|null |
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;
}
Возвращает корневой комментарий
public array GetCommentTypes()
| ||
{return} | array |
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 int|null GetCommentUnique(int $sTargetId, string $sTargetType, int $sUserId, int $sCommentPid, string $sHash)
| ||
$sTargetId | int | ID владельца комментария |
$sTargetType | string | Тип владельца комментария |
$sUserId | int | ID пользователя |
$sCommentPid | int | ID родительского комментария |
$sHash | string | Хеш строка текста комментария |
{return} | int|null |
public function GetCommentUnique($sTargetId, $sTargetType, $sUserId, $sCommentPid, $sHash)
{
$sql = "SELECT comment_id FROM " . Config::Get('db.table.comment') . "
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;
}
Получает уникальный коммент, это помогает спастись от дублей комментов
public array GetCommentsAll(string $sTargetType, int &$iCount, int $iCurrPage, int $iPerPage, array $aExcludeTarget=array (
), array $aExcludeParentTarget=array (
))
| ||
$sTargetType | string | Тип владельца комментария |
$iCount | int | Возвращает общее количество элементов |
$iCurrPage | int | Номер страницы |
$iPerPage | int | Количество элементов на страницу |
$aExcludeTarget | array | Список ID владельцев, которые необходимо исключить из выдачи |
$aExcludeParentTarget | array | Список ID родителей владельцев, которые необходимо исключить из выдачи, например, исключить комментарии топиков к определенным блогам(закрытым) |
{return} | array |
public function GetCommentsAll(
$sTargetType,
&$iCount,
$iCurrPage,
$iPerPage,
$aExcludeTarget = array(),
$aExcludeParentTarget = array()
) {
$sql = "SELECT
comment_id
FROM
" . Config::Get('db.table.comment') . "
WHERE
target_type = ?
AND
comment_delete = 0
AND
comment_publish = 1
{ AND target_id NOT IN(?a) }
{ AND target_parent_id NOT IN(?a) }
ORDER by comment_id desc
LIMIT ?d, ?d ";
$aComments = array();
if ($aRows = $this->oDb->selectPage(
$iCount, $sql, $sTargetType,
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP),
($iCurrPage - 1) * $iPerPage, $iPerPage
)
) {
foreach ($aRows as $aRow) {
$aComments[] = $aRow['comment_id'];
}
}
return $aComments;
}
Получить все комменты
public array GetCommentsByArrayId(array $aArrayId)
| ||
$aArrayId | array | Список ID комментариев |
{return} | array |
public function GetCommentsByArrayId($aArrayId)
{
if (!is_array($aArrayId) or count($aArrayId) == 0) {
return array();
}
$sql = "SELECT
*
FROM
" . Config::Get('db.table.comment') . "
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) {
$aComments[] = Engine::GetEntity('Comment', $aRow);
}
}
return $aComments;
}
Список комментов по ID
public array GetCommentsByFilter(array $aFilter, array $aOrder, int &$iCount, int $iCurrPage, int $iPerPage)
| ||
$aFilter | array | Фильтр выборки |
$aOrder | array | Сортировка |
$iCount | int | Возвращает общее количество элментов |
$iCurrPage | int | Номер текущей страницы |
$iPerPage | int | Количество элементов на одну страницу |
{return} | array |
public function GetCommentsByFilter($aFilter, $aOrder, &$iCount, $iCurrPage, $iPerPage)
{
$aOrderAllow = array('comment_id', 'comment_pid', 'comment_rating', 'comment_date');
$sOrder = '';
foreach ($aOrder as $key => $value) {
if (!in_array($key, $aOrderAllow)) {
unset($aOrder[$key]);
} elseif (in_array($value, array('asc', 'desc'))) {
$sOrder .= " {$key} {$value},";
}
}
$sOrder = trim($sOrder, ',');
if ($sOrder == '') {
$sOrder = ' comment_id desc ';
}
if (isset($aFilter['target_type']) and !is_array($aFilter['target_type'])) {
$aFilter['target_type'] = array($aFilter['target_type']);
}
$sql = "SELECT
comment_id
FROM
" . Config::Get('db.table.comment') . "
WHERE
1 = 1
{ AND comment_id = ?d }
{ AND user_id = ?d }
{ AND target_parent_id = ?d }
{ AND target_id = ?d }
{ AND target_type IN (?a) }
{ AND comment_delete = ?d }
{ AND comment_publish = ?d }
ORDER by {$sOrder}
LIMIT ?d, ?d ;
";
$aResult = array();
if ($aRows = $this->oDb->selectPage($iCount, $sql,
isset($aFilter['id']) ? $aFilter['id'] : DBSIMPLE_SKIP,
isset($aFilter['user_id']) ? $aFilter['user_id'] : DBSIMPLE_SKIP,
isset($aFilter['target_parent_id']) ? $aFilter['target_parent_id'] : DBSIMPLE_SKIP,
isset($aFilter['target_id']) ? $aFilter['target_id'] : DBSIMPLE_SKIP,
(isset($aFilter['target_type']) and count($aFilter['target_type'])) ? $aFilter['target_type'] : DBSIMPLE_SKIP,
isset($aFilter['delete']) ? $aFilter['delete'] : DBSIMPLE_SKIP,
isset($aFilter['publish']) ? $aFilter['publish'] : DBSIMPLE_SKIP,
($iCurrPage - 1) * $iPerPage, $iPerPage
)
) {
foreach ($aRows as $aRow) {
$aResult[] = $aRow['comment_id'];
}
}
return $aResult;
}
Получает список комментариев по фильтру
public array GetCommentsByTargetId(int $sId, string $sTargetType)
| ||
$sId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
{return} | array |
public function GetCommentsByTargetId($sId, $sTargetType)
{
$sql = "SELECT
comment_id,
comment_id as ARRAY_KEY,
comment_pid as PARENT_KEY
FROM
" . Config::Get('db.table.comment') . "
WHERE
target_id = ?d
AND
target_type = ?
ORDER by comment_id asc;
";
if ($aRows = $this->oDb->select($sql, $sId, $sTargetType)) {
return $aRows;
}
return null;
}
Получить комменты по владельцу
public array GetCommentsByUserId(int $sId, string $sTargetType, int &$iCount, int $iCurrPage, int $iPerPage, array $aExcludeTarget=array (
), array $aExcludeParentTarget=array (
))
| ||
$sId | int | ID пользователя |
$sTargetType | string | Тип владельца комментария |
$iCount | int | Возращает общее количество элементов |
$iCurrPage | int | Номер страницы |
$iPerPage | int | Количество элементов на страницу |
$aExcludeTarget | array | Список ID владельцев, которые необходимо исключить из выдачи |
$aExcludeParentTarget | array | Список ID родителей владельцев, которые необходимо исключить из выдачи |
{return} | array |
public function GetCommentsByUserId(
$sId,
$sTargetType,
&$iCount,
$iCurrPage,
$iPerPage,
$aExcludeTarget = array(),
$aExcludeParentTarget = array()
) {
$sql = "SELECT
comment_id
FROM
" . Config::Get('db.table.comment') . "
WHERE
user_id = ?d
AND
target_type= ?
AND
comment_delete = 0
AND
comment_publish = 1
{ AND target_id NOT IN (?a) }
{ AND target_parent_id NOT IN (?a) }
ORDER by comment_id desc
LIMIT ?d, ?d ";
$aComments = array();
if ($aRows = $this->oDb->selectPage(
$iCount, $sql, $sId,
$sTargetType,
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP),
($iCurrPage - 1) * $iPerPage, $iPerPage
)
) {
foreach ($aRows as $aRow) {
$aComments[] = $aRow['comment_id'];
}
}
return $aComments;
}
Получить комменты по юзеру
public array GetCommentsNewByTargetId(int $sId, string $sTargetType, int $sIdCommentLast)
| ||
$sId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
$sIdCommentLast | int | ID последнего прочитанного комментария |
{return} | array |
public function GetCommentsNewByTargetId($sId, $sTargetType, $sIdCommentLast)
{
$sql = "SELECT
comment_id
FROM
" . Config::Get('db.table.comment') . "
WHERE
target_id = ?d
AND
target_type = ?
AND
comment_id > ?d
ORDER by comment_id asc;
";
$aComments = array();
if ($aRows = $this->oDb->select($sql, $sId, $sTargetType, $sIdCommentLast)) {
foreach ($aRows as $aRow) {
$aComments[] = $aRow['comment_id'];
}
}
return $aComments;
}
Получить новые комменты для владельца
public array GetCommentsOnline(string $sTargetType, array $aExcludeTargets, int $iLimit)
| ||
$sTargetType | string | Тип владельца комментария |
$aExcludeTargets | array | Список ID владельцев для исключения |
$iLimit | int | Количество элементов |
{return} | array |
public function GetCommentsOnline($sTargetType, $aExcludeTargets, $iLimit)
{
$sql = "SELECT
comment_id
FROM
" . Config::Get('db.table.comment_online') . "
WHERE
target_type = ?
{ AND target_parent_id NOT IN(?a) }
ORDER by comment_online_id desc limit 0, ?d ; ";
$aComments = array();
if ($aRows = $this->oDb->select(
$sql, $sTargetType,
(count($aExcludeTargets) ? $aExcludeTargets : DBSIMPLE_SKIP),
$iLimit
)
) {
foreach ($aRows as $aRow) {
$aComments[] = $aRow['comment_id'];
}
}
return $aComments;
}
Получить все комменты сгрупированные по типу(для вывода прямого эфира)
public array GetCommentsRatingByDate(string $sDate, string $sTargetType, int $iLimit, array $aExcludeTarget=array (
), array $aExcludeParentTarget=array (
))
| ||
$sDate | string | Дата за которую выводить рейтинг |
$sTargetType | string | Тип владельца комментария |
$iLimit | int | Количество элементов |
$aExcludeTarget | array | Список ID владельцев, которые необходимо исключить из выдачи |
$aExcludeParentTarget | array | Список ID родителей владельцев, которые необходимо исключить из выдачи |
{return} | array |
public function GetCommentsRatingByDate(
$sDate,
$sTargetType,
$iLimit,
$aExcludeTarget = array(),
$aExcludeParentTarget = array()
) {
$sql = "SELECT
comment_id
FROM
" . Config::Get('db.table.comment') . "
WHERE
target_type = ?
AND
comment_date >= ?
AND
comment_rating >= 0
AND
comment_delete = 0
AND
comment_publish = 1
{ AND target_id NOT IN(?a) }
{ AND target_parent_id NOT IN (?a) }
ORDER by comment_rating desc, comment_id desc
LIMIT 0, ?d ";
$aComments = array();
if ($aRows = $this->oDb->select(
$sql, $sTargetType, $sDate,
(is_array($aExcludeTarget) && count($aExcludeTarget)) ? $aExcludeTarget : DBSIMPLE_SKIP,
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP),
$iLimit
)
) {
foreach ($aRows as $aRow) {
$aComments[] = $aRow['comment_id'];
}
}
return $aComments;
}
Получить комменты по рейтингу и дате
public array GetCommentsTreeByTargetId(int $sId, string $sTargetType)
| ||
$sId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
{return} | array |
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;
}
Получает комменты используя nested set
public array GetCommentsTreePageByTargetId(int $sId, string $sTargetType, int &$iCount, int $iPage, int $iPerPage)
| ||
$sId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
$iCount | int | Возвращает общее количество элементов |
$iPage | int | Номер страницы |
$iPerPage | int | Количество элементов на страницу |
{return} | array |
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
ORDER by comment_left desc
LIMIT ?d , ?d ;";
$aComments = array();
if ($aRows = $this->oDb->selectPage($iCount, $sql, $sId, $sTargetType, ($iPage - 1) * $iPerPage, $iPerPage)) {
$aCmt = array_pop($aRows);
$iLeft = $aCmt['comment_left'];
if ($aRows) {
$aCmt = array_shift($aRows);
}
$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;
}
Получает комменты используя nested set
public int GetCountCommentsAfterByTargetId(int $sId, string $sTargetType, int $iLeft)
| ||
$sId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
$iLeft | int | Значение left для дерева nested set |
{return} | int |
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 int GetCountCommentsByUserId(id $sId, string $sTargetType, array $aExcludeTarget=array (
), array $aExcludeParentTarget=array (
))
| ||
$sId | id | ID пользователя |
$sTargetType | string | Тип владельца комментария |
$aExcludeTarget | array | Список ID владельцев, которые необходимо исключить из выдачи |
$aExcludeParentTarget | array | Список ID родителей владельцев, которые необходимо исключить из выдачи |
{return} | int |
public function GetCountCommentsByUserId(
$sId,
$sTargetType,
$aExcludeTarget = array(),
$aExcludeParentTarget = array()
) {
$sql = "SELECT
count(comment_id) as count
FROM
" . Config::Get('db.table.comment') . "
WHERE
user_id = ?d
AND
target_type= ?
AND
comment_delete = 0
AND
comment_publish = 1
{ AND target_id NOT IN (?a) }
{ AND target_parent_id NOT IN (?a) }
";
if ($aRow = $this->oDb->selectRow(
$sql, $sId, $sTargetType,
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP)
)
) {
return $aRow['count'];
}
return false;
}
Получает количество комментариев одного пользователя
public int GetCountCommentsRootByTargetId(int $sId, string $sTargetType)
| ||
$sId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
{return} | int |
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'];
}
}
Возвращает количество дочерних комментариев у корневого коммента
public array GetTargetIdByType(string $sTargetType, int $iPage, int $iPerPage)
| ||
$sTargetType | string | Тип владельца |
$iPage | int | Номер страницы |
$iPerPage | int | Количество элементов на одну старницу |
{return} | array |
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();
}
Возвращает список ID владельцев
public bool MoveTargetParent(int $sParentId, string $sTargetType, int $sParentIdNew)
| ||
$sParentId | int | Прежний ID родителя владельца |
$sTargetType | string | Тип владельца |
$sParentIdNew | int | Новый ID родителя владельца |
{return} | bool |
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 = ?
";
$res = $this->oDb->query($sql, $sParentIdNew, $sParentId, $sTargetType);
return $this->IsSuccessful($res);
}
Меняет target parent на новый
public bool MoveTargetParentOnline(int $sParentId, string $sTargetType, int $sParentIdNew)
| ||
$sParentId | int | Прежний ID родителя владельца |
$sTargetType | string | Тип владельца |
$sParentIdNew | int | Новый ID родителя владельца |
{return} | bool |
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 = ?
";
$res = $this->oDb->query($sql, $sParentIdNew, $sParentId, $sTargetType);
return $this->IsSuccessful($res);
}
Меняет target parent на новый в прямом эфире
public bool RecalculateFavourite()
| ||
{return} | bool |
public function RecalculateFavourite()
{
$sql = "
UPDATE " . Config::Get('db.table.comment') . " c
SET c.comment_count_favourite = (
SELECT count(f.user_id)
FROM " . Config::Get('db.table.favourite') . " f
WHERE
f.target_id = c.comment_id
AND
f.target_publish = 1
AND
f.target_type = 'comment'
)
";
$res = $this->oDb->query($sql);
return $this->IsSuccessful($res);
}
Пересчитывает счетчик избранных комментариев
public int RestoreTree(int $iPid, int $iLft, int $iLevel, int $aTargetId, string $sTargetType)
| ||
$iPid | int | ID родителя |
$iLft | int | Значение left для дерева nested set |
$iLevel | int | Уровень |
$aTargetId | int | Список ID владельцев |
$sTargetType | string | Тип владельца |
{return} | int |
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);
}
}
$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);
}
return $iRgt + 1;
}
Перестраивает дерево комментариев Восстанавливает значения left, right и level
public bool SetCommentsPublish(int $sTargetId, string $sTargetType, int $iPublish)
| ||
$sTargetId | int | ID владельца коммента |
$sTargetType | string | Тип владельца комментария |
$iPublish | int | Статус отображать комментарии или нет |
{return} | bool |
public function SetCommentsPublish($sTargetId, $sTargetType, $iPublish)
{
$sql = "UPDATE " . Config::Get('db.table.comment') . "
SET
comment_publish= ?
WHERE
target_id = ?d AND target_type = ?
";
$res = $this->oDb->query($sql, $iPublish, $sTargetId, $sTargetType);
return $this->IsSuccessful($res);
}
Устанавливает publish у коммента
public bool UpdateComment(ModuleComment_EntityComment $oComment)
| ||
$oComment | ModuleComment_EntityComment | Объект комментария |
{return} | bool |
public function UpdateComment(ModuleComment_EntityComment $oComment)
{
$sql = "UPDATE " . Config::Get('db.table.comment') . "
SET
comment_text= ?,
comment_text_source= ?,
comment_rating= ?f,
comment_count_vote= ?d,
comment_count_favourite= ?d,
comment_count_edit= ?d,
comment_date_edit= ?,
comment_delete = ?d ,
comment_publish = ?d ,
comment_text_hash = ?
WHERE
comment_id = ?d
";
$res = $this->oDb->query($sql, $oComment->getText(), $oComment->getTextSource(), $oComment->getRating(),
$oComment->getCountVote(), $oComment->getCountFavourite(), $oComment->getCountEdit(),
$oComment->getDateEdit(), $oComment->getDelete(), $oComment->getPublish(), $oComment->getTextHash(),
$oComment->getId());
return $this->IsSuccessful($res);
}
Обновляет коммент
public bool UpdateTargetParentByTargetId(int $sParentId, string $sTargetType, array|int $aTargetId)
| ||
$sParentId | int | Новый ID родителя владельца |
$sTargetType | string | Тип владельца |
$aTargetId | array|int | Список ID владельцев |
{return} | bool |
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 = ?
";
$res = $this->oDb->query($sql, $sParentId, $aTargetId, $sTargetType);
return $this->IsSuccessful($res);
}
Меняем target parent по массиву идентификаторов
public bool UpdateTargetParentByTargetIdOnline(int $sParentId, string $sTargetType, array|int $aTargetId)
| ||
$sParentId | int | Новый ID родителя владельца |
$sTargetType | string | Тип владельца |
$aTargetId | array|int | Список ID владельцев |
{return} | bool |
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 = ?
";
$res = $this->oDb->query($sql, $sParentId, $aTargetId, $sTargetType);
return $this->IsSuccessful($res);
}
Меняем target parent по массиву идентификаторов в таблице комментариев online