Skip to content

Commit c66da01

Browse files
Show label in course if there are posts waiting for review; Only count posts in review period
1 parent 1b747e7 commit c66da01

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

classes/review.php

+24-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ public static function get_short_review_info_for_discussion(int $discussionid) {
6868
global $DB;
6969

7070
return $DB->get_record_sql(
71-
'SELECT COUNT(*) as count, MIN(id) AS first ' .
71+
'SELECT COUNT(*) as count, MIN(id) AS first ' .
7272
'FROM {moodleoverflow_posts} ' .
73-
'WHERE discussion = :discussionid AND reviewed = 0',
74-
['discussionid' => $discussionid]
73+
'WHERE discussion = :discussionid AND reviewed = 0 AND created < :cutofftime', [
74+
'discussionid' => $discussionid,
75+
'cutofftime' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime')
76+
]
7577
);
7678
}
7779

@@ -138,5 +140,24 @@ public static function is_post_in_review_period($post): bool {
138140
return time() - $post->created > get_config('moodleoverflow', 'reviewpossibleaftertime');
139141
}
140142

143+
/**
144+
* Count outstanding reviews in the moodleoverflow.
145+
*
146+
* @param $moodleoverflowid
147+
* @return int
148+
*/
149+
public static function count_outstanding_reviews_in_moodleoverflow($moodleoverflowid): int {
150+
global $DB;
151+
return $DB->count_records_sql(
152+
'SELECT COUNT(*) ' .
153+
'FROM {moodleoverflow_posts} p ' .
154+
'JOIN {moodleoverflow_discussions} d ON d.id = p.discussion ' .
155+
'WHERE d.moodleoverflow = :moodleoverflowid AND p.created < :cutofftime AND reviewed = 0', [
156+
'moodleoverflowid' => $moodleoverflowid,
157+
'cutofftime' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime')
158+
]
159+
);
160+
}
161+
141162

142163
}

lib.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -1080,19 +1080,30 @@ function moodleoverflow_minimise_user_record(stdClass $user) {
10801080
function moodleoverflow_cm_info_view(cm_info $cm) {
10811081

10821082
$cantrack = \mod_moodleoverflow\readtracking::moodleoverflow_can_track_moodleoverflows();
1083+
$out = "";
1084+
if (has_capability('mod/moodleoverflow:reviewpost', $cm->context)) {
1085+
$reviewcount = \mod_moodleoverflow\review::count_outstanding_reviews_in_moodleoverflow($cm->instance);
1086+
if ($reviewcount) {
1087+
$out .= '<span class="mod_moodleoverflow-label-review"><a href="' . $cm->url . '">';
1088+
$out .= get_string('amount_waiting_for_review', 'mod_moodleoverflow', $reviewcount);
1089+
$out .= '</a></span> ';
1090+
}
1091+
}
10831092
if ($cantrack) {
10841093
$unread = \mod_moodleoverflow\readtracking::moodleoverflow_count_unread_posts_moodleoverflow($cm);
10851094
if ($unread) {
1086-
$out = '<span class="unread"> <a href="' . $cm->url . '">';
1095+
$out .= '<span class="mod_moodleoverflow-label-unread"> <a href="' . $cm->url . '">';
10871096
if ($unread == 1) {
10881097
$out .= get_string('unreadpostsone', 'moodleoverflow');
10891098
} else {
10901099
$out .= get_string('unreadpostsnumber', 'moodleoverflow', $unread);
10911100
}
10921101
$out .= '</a></span>';
1093-
$cm->set_after_link($out);
10941102
}
10951103
}
1104+
if ($out) {
1105+
$cm->set_after_link($out);
1106+
}
10961107
}
10971108

10981109
/**

styles.css

+12-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@
233233
}
234234

235235
.moodleoverflowpost.unread .row.header,
236-
span.unread {
237-
background-color: #ffd;
236+
.mod_moodleoverflow-label-unread {
237+
background-color: #fff38a;
238238
}
239239

240240
.moodleoverflowpost.unread .row.header {
@@ -470,4 +470,14 @@ span.unread {
470470
font-size: 2em;
471471
width: 32px;
472472
height: 32px;
473+
}
474+
475+
.mod_moodleoverflow-label-review,
476+
.mod_moodleoverflow-label-unread {
477+
padding: 4px;
478+
border-radius: 8px;
479+
}
480+
481+
.mod_moodleoverflow-label-review {
482+
background-color: #ffd3d3;
473483
}

templates/discussion_list.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165

166166
{{! There are unread messages }}
167167
{{#unread}}
168-
<span class="unread">
168+
<span class="mod_moodleoverflow-label-unread">
169169
<a href="{{ unreadlink }}">{{ unreadamount }}</a>
170170
<a href="{{ markreadlink }}">
171171
{{# pix}} t/markasread, core, {{#str}}markread, moodleoverflow{{/str}} {{/ pix}}

0 commit comments

Comments
 (0)