Skip to content

Commit 19679de

Browse files
committed
Bell indicator for subscribed threads.
1 parent 0704193 commit 19679de

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

lib/src/UI/Lessons.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,15 +2045,20 @@ public function renderDiscussions($buffer=false)
20452045
// but for now we bypass the abstraction and go straight to the source...
20462046
$rows_dict = array();
20472047
if ( U::get($_SESSION,'context_id') > 0 ) {
2048-
$rows = $PDOX->allRowsDie("SELECT L.link_key, L.link_sha256, count(L.link_sha256) AS thread_count,
2048+
$current_user_id = U::loggedInUserId();
2049+
$rows = $PDOX->allRowsDie("SELECT L.link_key, L.link_sha256,
2050+
COUNT(T.thread_id) AS thread_count,
2051+
SUM(CASE WHEN COALESCE(UT.subscribe, 0) = 1 THEN 1 ELSE 0 END) AS subscribed_threads,
20492052
CONCAT(CONVERT_TZ(MAX(COALESCE(T.updated_at, T.created_at)), @@session.time_zone, '+00:00'), 'Z')
20502053
AS modified_at
20512054
FROM {$CFG->dbprefix}lti_link AS L
20522055
JOIN {$CFG->dbprefix}tdiscus_thread AS T ON T.link_id = L.link_id
2056+
LEFT JOIN {$CFG->dbprefix}tdiscus_user_thread AS UT
2057+
ON UT.thread_id = T.thread_id AND UT.user_id = :UID
20532058
WHERE L.context_id = :CID
2054-
GROUP BY L.link_sha256
2059+
GROUP BY L.link_id, L.link_key, L.link_sha256
20552060
ORDER BY L.link_sha256",
2056-
array(':CID' => U::get($_SESSION,'context_id'))
2061+
array(':CID' => U::get($_SESSION,'context_id'), ':UID' => $current_user_id)
20572062
);
20582063
$rows_dict = array();
20592064
foreach($rows as $row) {
@@ -2071,16 +2076,22 @@ public function renderDiscussions($buffer=false)
20712076
$launch_path = $rest_path->parent . '/' . $rest_path->controller . '_launch/' . $discussion->resource_link_id;
20722077
$info = "";
20732078
$row = U::get($rows_dict, $discussion->resource_link_id);
2079+
$subscribed_threads = intval(U::get($row, 'subscribed_threads', 0));
2080+
$bell_html = '';
2081+
if ( $subscribed_threads > 0 ) {
2082+
$bell_label = htmlentities(__('Subscribed threads').': '.$subscribed_threads);
2083+
$bell_html = ' <span style="color: #f0ad4e; font-size: 0.75em; vertical-align: middle;" title="'.$bell_label.'" aria-label="'.$bell_label.'">&#128276;</span>';
2084+
}
20742085
if ( $row ) {
20752086
$info = $row['thread_count'].' '.__('threads'). ' - '.__('last post').
20762087
' <time class="timeago" datetime="'.$row['modified_at'].'">'.$row['modified_at'].'</time>';
20772088
}
20782089

20792090
echo('<li typeof="oer:discussion" class="tsugi-lessons-module-discussion" data-resource-link-id="'.htmlspecialchars($discussion->resource_link_id).'">'."\n");
20802091
if ( $launchable ) {
2081-
echo('<a href="'.$launch_path.'">'.htmlentities($discussion->title).'</a>');
2092+
echo('<a href="'.$launch_path.'">'.htmlentities($discussion->title).$bell_html.'</a>');
20822093
} else {
2083-
echo(htmlentities($resource_link_title).' ('.__('Login Required').')');
2094+
echo(htmlentities($resource_link_title).$bell_html.' ('.__('Login Required').')');
20842095
}
20852096
echo('<span class="tsugi-discussion-rollup-badges" aria-live="polite"></span>');
20862097
if ( strlen($info) > 0 ) {
@@ -2141,7 +2152,6 @@ public function renderDiscussions($buffer=false)
21412152
var holder = node.querySelector('.tsugi-discussion-rollup-badges');
21422153
if (!holder) return;
21432154
holder.innerHTML = chip;
2144-
holder.appendChild(document.createComment(' dbg p=' + personal + ' t=' + participating + ' g=' + global + ' '));
21452155
});
21462156
})
21472157
.catch(function() {

0 commit comments

Comments
 (0)