Comments/Date

* add missing elapsed value to comment and reply rows to make them sortable
This commit is contained in:
Sarjuuk
2024-07-09 14:41:05 +02:00
parent c14d53067b
commit 81078bcf3d

View File

@@ -21,86 +21,62 @@ class CommunityContent
private static array $jsGlobals = []; private static array $jsGlobals = [];
private static array $subjCache = []; private static array $subjCache = [];
private static string $coQuery = ' private static string $coQuery =
SELECT 'SELECT c.*,
c.*, a1.`displayName` AS `user`,
a1.displayName AS user, a2.`displayName` AS `editUser`,
a2.displayName AS editUser, a3.`displayName` AS `deleteUser`,
a3.displayName AS deleteUser, a4.`displayName` AS `responseUser`,
a4.displayName AS responseUser, IFNULL(SUM(ur.`value`), 0) AS `rating`,
IFNULL(SUM(ur.value), 0) AS rating, SUM(IF(ur.`userId` > 0 AND ur.`userId` = ?d, ur.`value`, 0)) AS `userRating`,
SUM(IF(ur.userId > 0 AND ur.userId = ?d, ur.value, 0)) AS userRating, IF(r.`id` IS NULL, 0, 1) AS `userReported`
SUM(IF( r.userId > 0 AND r.userId = ?d, 1, 0)) AS userReported FROM ?_comments c
FROM JOIN ?_account a1 ON c.`userId` = a1.`id`
?_comments c LEFT JOIN ?_account a2 ON c.`editUserId` = a2.`id`
JOIN LEFT JOIN ?_account a3 ON c.`deleteUserId` = a3.`id`
?_account a1 ON c.userId = a1.id LEFT JOIN ?_account a4 ON c.`responseUserId` = a4.`id`
LEFT JOIN LEFT JOIN ?_user_ratings ur ON c.`id` = ur.`entry` AND ur.`type` = ?d
?_account a2 ON c.editUserId = a2.id LEFT JOIN ?_reports r ON r.`subject` = c.`id` AND r.`mode` = ?d AND r.`userId` = ?d
LEFT JOIN WHERE c.`replyTo` = ?d AND c.`type` = ?d AND c.`typeId` = ?d AND
?_account a3 ON c.deleteUserId = a3.id ((c.`flags` & ?d) = 0 OR c.`userId` = ?d OR ?d)
LEFT JOIN GROUP BY c.`id`
?_account a4 ON c.responseUserId = a4.id ORDER BY `date` ASC';
LEFT JOIN
?_user_ratings ur ON c.id = ur.entry AND ur.type = ?d
LEFT JOIN
?_reports r ON r.subject = c.id AND r.mode = 1 AND r.reason = 19
WHERE
c.replyTo = ?d AND c.type = ?d AND c.typeId = ?d AND
((c.flags & ?d) = 0 OR c.userId = ?d OR ?d)
GROUP BY
c.id
ORDER BY
`date` ASC
';
private static string $ssQuery = ' private static string $ssQuery =
SELECT s.id AS ARRAY_KEY, s.id, a.displayName AS user, s.date, s.width, s.height, s.caption, IF(s.status & ?d, 1, 0) AS "sticky", s.type, s.typeId 'SELECT s.`id` AS ARRAY_KEY, s.`id`, a.`displayName` AS `user`, s.`date`, s.`width`, s.`height`, s.`caption`, IF(s.`status` & ?d, 1, 0) AS "sticky", s.`type`, s.`typeId`
FROM ?_screenshots s FROM ?_screenshots s
LEFT JOIN ?_account a ON s.userIdOwner = a.id LEFT JOIN ?_account a ON s.`userIdOwner` = a.`id`
WHERE {s.userIdOwner = ?d AND }{s.type = ? AND }{s.typeId = ? AND }s.status & ?d AND (s.status & ?d) = 0 WHERE { s.`userIdOwner` = ?d AND }{ s.`type` = ? AND }{ s.`typeId` = ? AND } s.`status` & ?d AND (s.`status` & ?d) = 0
{ORDER BY ?# DESC} { ORDER BY ?# DESC }
{LIMIT ?d} { LIMIT ?d }';
';
private static string $viQuery = ' private static string $viQuery =
SELECT v.id AS ARRAY_KEY, v.id, a.displayName AS user, v.date, v.videoId, v.caption, IF(v.status & ?d, 1, 0) AS "sticky", v.type, v.typeId 'SELECT v.`id` AS ARRAY_KEY, v.`id`, a.`displayName` AS `user`, v.`date`, v.`videoId`, v.`caption`, IF(v.`status` & ?d, 1, 0) AS "sticky", v.`type`, v.`typeId`
FROM ?_videos v FROM ?_videos v
LEFT JOIN ?_account a ON v.userIdOwner = a.id LEFT JOIN ?_account a ON v.`userIdOwner` = a.`id`
WHERE {v.userIdOwner = ?d AND }{v.type = ? AND }{v.typeId = ? AND }v.status & ?d AND (v.status & ?d) = 0 WHERE { v.`userIdOwner` = ?d AND }{ v.`type` = ? AND }{ v.`typeId` = ? AND } v.`status` & ?d AND (v.`status` & ?d) = 0
{ORDER BY ?# DESC} { ORDER BY ?# DESC }
{LIMIT ?d} { LIMIT ?d }';
';
private static string $previewQuery = ' private static string $previewQuery =
SELECT 'SELECT c.`id`,
c.id, c.`body` AS `preview`,
c.body AS preview, c.`date`,
c.date, c.`replyTo` AS `commentid`,
c.replyTo AS commentid, IF(c.`flags` & ?d, 1, 0) AS `deleted`,
IF(c.flags & ?d, 1, 0) AS deleted, IF(c.`type` <> 0, c.`type`, c2.`type`) AS `type`,
IF(c.type <> 0, c.type, c2.type) AS type, IF(c.`typeId` <> 0, c.`typeId`, c2.`typeId`) AS `typeId`,
IF(c.typeId <> 0, c.typeId, c2.typeId) AS typeId, IFNULL(SUM(ur.`value`), 0) AS `rating`,
IFNULL(SUM(ur.value), 0) AS rating, a.`displayName` AS `user`
a.displayName AS user FROM ?_comments c
FROM JOIN ?_account a ON c.`userId` = a.`id`
?_comments c LEFT JOIN ?_user_ratings ur ON ur.`entry` = c.`id` AND ur.`userId` <> 0 AND ur.`type` = 1
JOIN LEFT JOIN ?_comments c2 ON c.`replyTo` = c2.`id`
?_account a ON c.userId = a.id WHERE %s
LEFT JOIN ((c.`flags` & ?d) = 0 OR c.`userId` = ?d OR ?d)
?_user_ratings ur ON ur.entry = c.id AND ur.userId <> 0 AND ur.`type` = 1 GROUP BY c.`id`
LEFT JOIN ORDER BY `date` DESC
?_comments c2 ON c.replyTo = c2.id LIMIT ?d';
WHERE
%s
((c.flags & ?d) = 0 OR c.userId = ?d OR ?d)
GROUP BY
c.id
ORDER BY
date DESC
LIMIT
?d
';
private static function addSubject(int $type, int $typeId) : void private static function addSubject(int $type, int $typeId) : void
{ {
@@ -170,7 +146,8 @@ class CommunityContent
$c['subject'] = self::$subjCache[$c['type']][$c['typeId']]; $c['subject'] = self::$subjCache[$c['type']][$c['typeId']];
// format date // format date
$c['date'] = $dateFmt ? date(Util::$dateFormatInternal, $c['date']) : intVal($c['date']); $c['elapsed'] = time() - $c['date'];
$c['date'] = $dateFmt ? date(Util::$dateFormatInternal, $c['date']) : intVal($c['date']);
// remove commentid if not looking for replies // remove commentid if not looking for replies
if (empty($params['replies'])) if (empty($params['replies']))
@@ -195,7 +172,7 @@ class CommunityContent
$query = $limit > 0 ? self::$coQuery.' LIMIT '.$limit : self::$coQuery; $query = $limit > 0 ? self::$coQuery.' LIMIT '.$limit : self::$coQuery;
// get replies // get replies
$results = DB::Aowow()->selectPage($nFound, $query, User::$id, User::$id, RATING_COMMENT, $commentId, 0, 0, CC_FLAG_DELETED, User::$id, User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); $results = DB::Aowow()->selectPage($nFound, $query, User::$id, RATING_COMMENT, Report::MODE_COMMENT, User::$id, $commentId, 0, 0, CC_FLAG_DELETED, User::$id, User::isInGroup(U_GROUP_COMMENTS_MODERATOR));
foreach ($results as $r) foreach ($results as $r)
{ {
(new Markup($r['body']))->parseGlobalsFromText(self::$jsGlobals); (new Markup($r['body']))->parseGlobalsFromText(self::$jsGlobals);
@@ -351,7 +328,7 @@ class CommunityContent
public static function getComments(int $type, int $typeId) : array public static function getComments(int $type, int $typeId) : array
{ {
$results = DB::Aowow()->query(self::$coQuery, User::$id, User::$id, RATING_COMMENT, 0, $type, $typeId, CC_FLAG_DELETED, User::$id, (int)User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); $results = DB::Aowow()->query(self::$coQuery, User::$id, RATING_COMMENT, Report::MODE_COMMENT, User::$id, 0, $type, $typeId, CC_FLAG_DELETED, User::$id, (int)User::isInGroup(U_GROUP_COMMENTS_MODERATOR));
$comments = []; $comments = [];
// additional informations // additional informations