Skip to content

Commit 7d05c7c

Browse files
Add jump to first review button on discussion list page; fix comment post action menu
1 parent c66da01 commit 7d05c7c

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

classes/review.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,34 @@ public static function get_short_review_info_for_discussion(int $discussionid) {
7878
}
7979

8080
/**
81-
* @param $afterpostid
81+
* @param int $moodleoverflowid ID of moodleoverflow to look in.
82+
* @param int $afterpostid ID of post after which to look for the first post to review.
8283
* @return string|null
8384
*/
84-
public static function get_first_review_post($afterpostid = null) {
85+
public static function get_first_review_post($moodleoverflowid, $afterpostid = null) {
8586
global $DB;
8687

87-
$params = [];
88+
$params = ['moodleoverflowid' => $moodleoverflowid];
8889
$orderby = '';
8990
$addwhere = '';
9091

9192
if ($afterpostid) {
9293
$afterdiscussionid = $DB->get_field('moodleoverflow_posts', 'discussion', ['id' => $afterpostid],
9394
MUST_EXIST);
9495

95-
$orderby = 'CASE WHEN (discussion > :afterdiscussionid OR (discussion = :afterdiscussionid2 AND id > :afterpostid)) THEN 0 ELSE 1 END, ';
96+
$orderby = 'CASE WHEN (p.discussion > :afterdiscussionid OR (p.discussion = :afterdiscussionid2 AND p.id > :afterpostid)) THEN 0 ELSE 1 END, ';
9697
$params['afterdiscussionid'] = $afterdiscussionid;
9798
$params['afterdiscussionid2'] = $afterdiscussionid;
9899
$params['afterpostid'] = $afterpostid;
99100

100-
$addwhere = ' AND id != :notpostid ';
101+
$addwhere = ' AND p.id != :notpostid ';
101102
$params['notpostid'] = $afterpostid;
102103
}
103104
$record = $DB->get_record_sql(
104-
'SELECT id as postid, discussion as discussionid FROM {moodleoverflow_posts} ' .
105-
"WHERE reviewed = 0 $addwhere " .
106-
"ORDER BY $orderby discussion, id " .
105+
'SELECT p.id as postid, p.discussion as discussionid FROM {moodleoverflow_posts} p ' .
106+
'JOIN {moodleoverflow_discussions} d ON d.id = p.discussion ' .
107+
"WHERE p.reviewed = 0 AND d.moodleoverflow = :moodleoverflowid $addwhere " .
108+
"ORDER BY $orderby p.discussion, p.id " .
107109
'LIMIT 1',
108110
$params
109111
);

externallib.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public static function review_approve_post($postid) {
206206
$DB->update_record('moodleoverflow_discussions', $discussion);
207207
}
208208

209-
return review::get_first_review_post($post->id);
209+
return review::get_first_review_post($moodleoverflow->id, $post->id);
210210
}
211211

212212
/**
@@ -293,7 +293,7 @@ public static function review_reject_post($postid, $reason = null) {
293293
$OUTPUT->render_from_template('mod_moodleoverflow/email_rejected_html', $htmlcontext)
294294
);
295295

296-
$url = review::get_first_review_post($post->id);
296+
$url = review::get_first_review_post($moodleoverflow->id, $post->id);
297297

298298
if (!$post->parent) {
299299
// Delete discussion, if this is the question.

locallib.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = -
141141
$buttontext = get_string('addanewdiscussion', 'moodleoverflow');
142142
$buttonurl = new moodle_url('/mod/moodleoverflow/post.php', ['moodleoverflow' => $moodleoverflow->id]);
143143
$button = new single_button($buttonurl, $buttontext, 'get');
144-
$button->class = 'singlebutton moodleoverflowaddnew';
144+
$button->class = 'singlebutton align-middle m-2';
145145
$button->formid = 'newdiscussionform';
146146
echo $OUTPUT->render($button);
147147
}

templates/comment.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
{{/statusstarter}}
101101
<div class="post-info">
102102
<div class="leftbox {{ questioner }}"><span class="text-muted">{{{ byname }}} - {{ byshortdate }}</span></div>
103-
<div class="rightbox">{{{ commands }}}</div>
103+
<div class="rightbox post-menu">{{{ commands }}}</div>
104104
</div>
105105
</div>
106106
</div>

view.php

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@
105105
echo $OUTPUT->box(format_module_intro('moodleoverflow', $moodleoverflow, $cm->id), 'generalbox', 'intro');
106106
}
107107

108+
if (has_capability('mod/moodleoverflow:reviewpost', $context)) {
109+
$reviewpost = \mod_moodleoverflow\review::get_first_review_post($moodleoverflow->id);
110+
111+
if ($reviewpost) {
112+
echo html_writer::link($reviewpost, get_string('review_needed', 'mod_moodleoverflow'), ['class' => 'btn btn-danger']);
113+
}
114+
}
115+
108116
// Return here after posting, etc.
109117
$SESSION->fromdiscussion = qualified_me();
110118

0 commit comments

Comments
 (0)