Comments/Replies

* also show replies on latest-comments utility page
 * sort replies by score DESC
This commit is contained in:
Sarjuuk
2023-06-08 14:16:03 +02:00
parent 0d6a6e163c
commit e71da620c6
4 changed files with 45 additions and 22 deletions

View File

@@ -51,7 +51,7 @@ class CommunityContent
GROUP BY GROUP BY
c.id c.id
ORDER BY ORDER BY
rating ASC `date` ASC
'; ';
private static string $ssQuery = ' private static string $ssQuery = '
@@ -92,11 +92,7 @@ class CommunityContent
LEFT JOIN LEFT JOIN
?_comments c2 ON c.replyTo = c2.id ?_comments c2 ON c.replyTo = c2.id
WHERE WHERE
{c.userId = ?d AND} %s
{c.replyTo <> ?d AND}
{c.replyTo = ?d AND}
{ur.entry IS ?n AND}
{(c.flags & ?d) AND}
((c.flags & ?d) = 0 OR c.userId = ?d OR ?d) ((c.flags & ?d) = 0 OR c.userId = ?d OR ?d)
GROUP BY GROUP BY
c.id c.id
@@ -129,22 +125,32 @@ class CommunityContent
} }
} }
public static function getCommentPreviews(array $params = [], ?int &$nFound = 0, bool $dateFmt = true) : array public static function getCommentPreviews(array $opt = [], ?int &$nFound = 0, bool $dateFmt = true) : array
{ {
/* /*
purged:0, <- doesnt seem to be used anymore purged:0, <- doesnt seem to be used anymore
domain:'live' <- irrelevant for our case domain:'live' <- irrelevant for our case
*/ */
// add default values
$opt += ['user' => 0, 'unrated' => 0, 'comments' => 0, 'replies' => 0];
$w = [];
if ($opt['user'])
$w[] = sprintf('c.userId = %d AND', $opt['user']);
if ($opt['unrated'])
$w[] = 'ur.entry IS NULL AND';
if ($opt['comments'] && !$opt['replies'])
$w[] = 'c.replyTo = 0 AND';
else if (!$opt['comments'] && $opt['replies'])
$w[] = 'c.replyTo <> 0 AND';
// else
// pick both and no extra constraint needed for that
$comments = DB::Aowow()->selectPage( $comments = DB::Aowow()->selectPage(
$nFound, $nFound,
self::$previewQuery, sprintf(self::$previewQuery, implode(' ', $w)),
CC_FLAG_DELETED, CC_FLAG_DELETED,
empty($params['user']) ? DBSIMPLE_SKIP : $params['user'],
empty($params['replies']) ? DBSIMPLE_SKIP : 0, // i dont know, how to switch the sign around
!empty($params['replies']) ? DBSIMPLE_SKIP : 0,
empty($params['unrated']) ? DBSIMPLE_SKIP : null,
empty($params['flags']) ? DBSIMPLE_SKIP : $params['flags'],
CC_FLAG_DELETED, CC_FLAG_DELETED,
User::$id, User::$id,
User::isInGroup(U_GROUP_COMMENTS_MODERATOR), User::isInGroup(U_GROUP_COMMENTS_MODERATOR),

View File

@@ -251,7 +251,7 @@ class AccountPage extends GenericPage
} }
// comments // comments
if ($_ = CommunityContent::getCommentPreviews(['user' => User::$id, 'replies' => false])) if ($_ = CommunityContent::getCommentPreviews(['user' => User::$id, 'comments' => true]))
{ {
// needs foundCount for params // needs foundCount for params
// _totalCount: 377, // _totalCount: 377,

View File

@@ -151,7 +151,7 @@ class UserPage extends GenericPage
} }
// Comments // Comments
if ($_ = CommunityContent::getCommentPreviews(['user' => $this->user['id'], 'replies' => false], $nFound)) if ($_ = CommunityContent::getCommentPreviews(['user' => $this->user['id'], 'comments' => true], $nFound))
{ {
$tabData = array( $tabData = array(
'data' => $_, 'data' => $_,

View File

@@ -75,11 +75,25 @@ class UtilityPage extends GenericPage
header('Location: ?'.Type::getFileString($type).'='.$typeId, true, 302); header('Location: ?'.Type::getFileString($type).'='.$typeId, true, 302);
die(); die();
case 'latest-comments': // rss case 'latest-comments': // rss
$data = CommunityContent::getCommentPreviews(dateFmt: false); $comments = CommunityContent::getCommentPreviews(['comments' => true, 'replies' => false], $i, false);
$replies = CommunityContent::getCommentPreviews(['comments' => false, 'replies' => true], $i, false);
if ($this->rss) if ($this->rss)
{ {
foreach ($data as $d) foreach ($comments as $d)
{
// todo (low): preview should be html-formated
$this->feedData[] = array(
'title' => [true, [], Lang::typeName($d['type']).Lang::main('colon').htmlentities($d['subject'])],
'link' => [false, [], HOST_URL.'/?go-to-comment&amp;id='.$d['id']],
'description' => [true, [], htmlentities($d['preview'])."<br /><br />".Lang::main('byUser', [$d['user'], '']) . Util::formatTimeDiff($d['date'], true)],
'pubDate' => [false, [], date(DATE_RSS, $d['date'])],
'guid' => [false, [], HOST_URL.'/?go-to-comment&amp;id='.$d['id']]
// 'domain' => [false, [], null]
);
}
foreach ($replies as $d)
{ {
// todo (low): preview should be html-formated // todo (low): preview should be html-formated
$this->feedData[] = array( $this->feedData[] = array(
@@ -94,8 +108,11 @@ class UtilityPage extends GenericPage
} }
else else
{ {
array_walk($data, fn(&$d) => $d['date'] = date(Util::$dateFormatInternal, $d['date'])); array_walk($comments, fn(&$d) => $d['date'] = date(Util::$dateFormatInternal, $d['date']));
$this->lvTabs[] = ['commentpreview', ['data' => $data]]; $this->lvTabs[] = ['commentpreview', ['data' => $comments]];
array_walk($replies, fn(&$d) => $d['date'] = date(Util::$dateFormatInternal, $d['date']));
$this->lvTabs[] = ['commentpreview', ['data' => $replies]];
} }
break; break;
@@ -162,10 +179,10 @@ class UtilityPage extends GenericPage
break; break;
case 'unrated-comments': case 'unrated-comments':
if ($_ = CommunityContent::getCommentPreviews(['unrated' => true])) $this->lvTabs[] = ['commentpreview', [
$this->lvTabs[] = ['commentpreview', ['data' => $_]]; 'data' => CommunityContent::getCommentPreviews(['unrated' => true, 'comments' => true])
]];
$this->lvTabs[] = ['commentpreview', ['data' => []]];
break; break;
case 'missing-screenshots': case 'missing-screenshots':
// limit to 200 entries each (it generates faster, consumes less memory and should be enough options) // limit to 200 entries each (it generates faster, consumes less memory and should be enough options)