mirror of https://github.com/BOINC/boinc.git
Established a function to get the first unread comment for a given user and node
(DBOINCP-167)
This commit is contained in:
parent
8e33b034a0
commit
db181f42b5
|
@ -94,6 +94,28 @@ function boincuser_check_credit_requirements() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cid of the first comment the user has not seen on a given node
|
||||||
|
*/
|
||||||
|
function boincuser_get_first_unread_comment_id($nid, $uid = NULL) {
|
||||||
|
if (!$uid) {
|
||||||
|
global $user;
|
||||||
|
$uid = $user->uid;
|
||||||
|
}
|
||||||
|
return db_result(db_query("
|
||||||
|
SELECT c.cid
|
||||||
|
FROM {node} n
|
||||||
|
INNER JOIN {comments} c ON c.nid = n.nid
|
||||||
|
LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d
|
||||||
|
WHERE n.nid = %d
|
||||||
|
AND n.status = 1
|
||||||
|
AND c.timestamp > h.timestamp
|
||||||
|
ORDER BY c.timestamp ASC
|
||||||
|
LIMIT 1",
|
||||||
|
$uid, $nid
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the first unique name from a given base
|
* Determine the first unique name from a given base
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -472,24 +472,10 @@ function boinc_preprocess_comment(&$vars, $hook) {
|
||||||
*/
|
*/
|
||||||
function boinc_preprocess_forum_topic_list(&$variables) {
|
function boinc_preprocess_forum_topic_list(&$variables) {
|
||||||
if (!empty($variables['topics'])) {
|
if (!empty($variables['topics'])) {
|
||||||
global $user;
|
|
||||||
foreach ($variables['topics'] as $id => $topic) {
|
foreach ($variables['topics'] as $id => $topic) {
|
||||||
if ($topic->new_replies) {
|
if ($topic->new_replies) {
|
||||||
$cid = db_result(db_query("
|
$cid = boincuser_get_first_unread_comment_id($topic->nid);
|
||||||
SELECT c.cid
|
$variables['topics'][$id]->new_url = url("goto/comment/{$cid}");
|
||||||
FROM {node} n
|
|
||||||
INNER JOIN {comments} c ON c.nid = n.nid
|
|
||||||
LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d
|
|
||||||
WHERE n.nid = %d
|
|
||||||
AND n.status = 1
|
|
||||||
AND c.timestamp > h.timestamp
|
|
||||||
ORDER BY c.timestamp ASC
|
|
||||||
LIMIT 1",
|
|
||||||
$user->uid, $topic->nid
|
|
||||||
));
|
|
||||||
if ($cid) {
|
|
||||||
$variables['topics'][$id]->new_url = url("goto/comment/{$cid}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue