@@ -78,32 +78,34 @@ public static function get_short_review_info_for_discussion(int $discussionid) {
78
78
}
79
79
80
80
/**
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.
82
83
* @return string|null
83
84
*/
84
- public static function get_first_review_post ($ afterpostid = null ) {
85
+ public static function get_first_review_post ($ moodleoverflowid , $ afterpostid = null ) {
85
86
global $ DB ;
86
87
87
- $ params = [];
88
+ $ params = [' moodleoverflowid ' => $ moodleoverflowid ];
88
89
$ orderby = '' ;
89
90
$ addwhere = '' ;
90
91
91
92
if ($ afterpostid ) {
92
93
$ afterdiscussionid = $ DB ->get_field ('moodleoverflow_posts ' , 'discussion ' , ['id ' => $ afterpostid ],
93
94
MUST_EXIST );
94
95
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, ' ;
96
97
$ params ['afterdiscussionid ' ] = $ afterdiscussionid ;
97
98
$ params ['afterdiscussionid2 ' ] = $ afterdiscussionid ;
98
99
$ params ['afterpostid ' ] = $ afterpostid ;
99
100
100
- $ addwhere = ' AND id != :notpostid ' ;
101
+ $ addwhere = ' AND p. id != :notpostid ' ;
101
102
$ params ['notpostid ' ] = $ afterpostid ;
102
103
}
103
104
$ 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 " .
107
109
'LIMIT 1 ' ,
108
110
$ params
109
111
);
0 commit comments