mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Comments/Date
* add missing elapsed value to comment and reply rows to make them sortable
This commit is contained in:
@@ -21,86 +21,62 @@ class CommunityContent
|
||||
private static array $jsGlobals = [];
|
||||
private static array $subjCache = [];
|
||||
|
||||
private static string $coQuery = '
|
||||
SELECT
|
||||
c.*,
|
||||
a1.displayName AS user,
|
||||
a2.displayName AS editUser,
|
||||
a3.displayName AS deleteUser,
|
||||
a4.displayName AS responseUser,
|
||||
IFNULL(SUM(ur.value), 0) AS rating,
|
||||
SUM(IF(ur.userId > 0 AND ur.userId = ?d, ur.value, 0)) AS userRating,
|
||||
SUM(IF( r.userId > 0 AND r.userId = ?d, 1, 0)) AS userReported
|
||||
FROM
|
||||
?_comments c
|
||||
JOIN
|
||||
?_account a1 ON c.userId = a1.id
|
||||
LEFT JOIN
|
||||
?_account a2 ON c.editUserId = a2.id
|
||||
LEFT JOIN
|
||||
?_account a3 ON c.deleteUserId = a3.id
|
||||
LEFT JOIN
|
||||
?_account a4 ON c.responseUserId = a4.id
|
||||
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 $coQuery =
|
||||
'SELECT c.*,
|
||||
a1.`displayName` AS `user`,
|
||||
a2.`displayName` AS `editUser`,
|
||||
a3.`displayName` AS `deleteUser`,
|
||||
a4.`displayName` AS `responseUser`,
|
||||
IFNULL(SUM(ur.`value`), 0) AS `rating`,
|
||||
SUM(IF(ur.`userId` > 0 AND ur.`userId` = ?d, ur.`value`, 0)) AS `userRating`,
|
||||
IF(r.`id` IS NULL, 0, 1) AS `userReported`
|
||||
FROM ?_comments c
|
||||
JOIN ?_account a1 ON c.`userId` = a1.`id`
|
||||
LEFT JOIN ?_account a2 ON c.`editUserId` = a2.`id`
|
||||
LEFT JOIN ?_account a3 ON c.`deleteUserId` = a3.`id`
|
||||
LEFT JOIN ?_account a4 ON c.`responseUserId` = a4.`id`
|
||||
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` = ?d AND r.`userId` = ?d
|
||||
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 = '
|
||||
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
|
||||
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
|
||||
{ORDER BY ?# DESC}
|
||||
{LIMIT ?d}
|
||||
';
|
||||
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`
|
||||
FROM ?_screenshots s
|
||||
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
|
||||
{ ORDER BY ?# DESC }
|
||||
{ LIMIT ?d }';
|
||||
|
||||
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
|
||||
FROM ?_videos v
|
||||
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
|
||||
{ORDER BY ?# DESC}
|
||||
{LIMIT ?d}
|
||||
';
|
||||
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`
|
||||
FROM ?_videos v
|
||||
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
|
||||
{ ORDER BY ?# DESC }
|
||||
{ LIMIT ?d }';
|
||||
|
||||
private static string $previewQuery = '
|
||||
SELECT
|
||||
c.id,
|
||||
c.body AS preview,
|
||||
c.date,
|
||||
c.replyTo AS commentid,
|
||||
IF(c.flags & ?d, 1, 0) AS deleted,
|
||||
IF(c.type <> 0, c.type, c2.type) AS type,
|
||||
IF(c.typeId <> 0, c.typeId, c2.typeId) AS typeId,
|
||||
IFNULL(SUM(ur.value), 0) AS rating,
|
||||
a.displayName AS user
|
||||
FROM
|
||||
?_comments c
|
||||
JOIN
|
||||
?_account a ON c.userId = a.id
|
||||
LEFT JOIN
|
||||
?_user_ratings ur ON ur.entry = c.id AND ur.userId <> 0 AND ur.`type` = 1
|
||||
LEFT JOIN
|
||||
?_comments c2 ON c.replyTo = c2.id
|
||||
WHERE
|
||||
%s
|
||||
((c.flags & ?d) = 0 OR c.userId = ?d OR ?d)
|
||||
GROUP BY
|
||||
c.id
|
||||
ORDER BY
|
||||
date DESC
|
||||
LIMIT
|
||||
?d
|
||||
';
|
||||
private static string $previewQuery =
|
||||
'SELECT c.`id`,
|
||||
c.`body` AS `preview`,
|
||||
c.`date`,
|
||||
c.`replyTo` AS `commentid`,
|
||||
IF(c.`flags` & ?d, 1, 0) AS `deleted`,
|
||||
IF(c.`type` <> 0, c.`type`, c2.`type`) AS `type`,
|
||||
IF(c.`typeId` <> 0, c.`typeId`, c2.`typeId`) AS `typeId`,
|
||||
IFNULL(SUM(ur.`value`), 0) AS `rating`,
|
||||
a.`displayName` AS `user`
|
||||
FROM ?_comments c
|
||||
JOIN ?_account a ON c.`userId` = a.`id`
|
||||
LEFT JOIN ?_user_ratings ur ON ur.`entry` = c.`id` AND ur.`userId` <> 0 AND ur.`type` = 1
|
||||
LEFT JOIN ?_comments c2 ON c.`replyTo` = c2.`id`
|
||||
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
|
||||
{
|
||||
@@ -170,7 +146,8 @@ class CommunityContent
|
||||
$c['subject'] = self::$subjCache[$c['type']][$c['typeId']];
|
||||
|
||||
// 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
|
||||
if (empty($params['replies']))
|
||||
@@ -195,7 +172,7 @@ class CommunityContent
|
||||
$query = $limit > 0 ? self::$coQuery.' LIMIT '.$limit : self::$coQuery;
|
||||
|
||||
// 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)
|
||||
{
|
||||
(new Markup($r['body']))->parseGlobalsFromText(self::$jsGlobals);
|
||||
@@ -351,7 +328,7 @@ class CommunityContent
|
||||
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 = [];
|
||||
|
||||
// additional informations
|
||||
|
||||
Reference in New Issue
Block a user