@@ -696,7 +696,7 @@ function moodleoverflow_user_can_see_discussion($moodleoverflow, $discussion, $c
696696 * Creates a new moodleoverflow discussion.
697697 *
698698 * @param stdClass $discussion The discussion object
699- * @param object $modulecontext
699+ * @param context_module $modulecontext
700700 * @param int $userid The user ID
701701 *
702702 * @return bool|int The id of the created discussion
@@ -737,7 +737,9 @@ function moodleoverflow_add_discussion($discussion, $modulecontext, $userid = nu
737737 $ post ->moodleoverflow = $ moodleoverflow ->id ;
738738 $ post ->course = $ moodleoverflow ->course ;
739739
740- if (review::get_review_level ($ moodleoverflow ) > review::QUESTIONS ) {
740+ // Set to not reviewed, if questions should be reviewed, and user is not a reviewer themselves.
741+ if (review::get_review_level ($ moodleoverflow ) > review::QUESTIONS &&
742+ !has_capability ('mod/moodleoverflow:reviewpost ' , $ modulecontext , $ userid )) {
741743 $ post ->reviewed = 0 ;
742744 }
743745
@@ -1562,10 +1564,11 @@ function moodleoverflow_add_attachment($post, $forum, $cm) {
15621564 * Adds a new post in an existing discussion.
15631565 *
15641566 * @param object $post The post object
1567+ * @param context_module $modulecontext
15651568 *
15661569 * @return bool|int The Id of the post if operation was successful
15671570 */
1568- function moodleoverflow_add_new_post ($ post ) {
1571+ function moodleoverflow_add_new_post ($ post, $ modulecontext ) {
15691572 global $ USER , $ DB ;
15701573
15711574 // We do not check if these variables exist because this function
@@ -1581,18 +1584,24 @@ function moodleoverflow_add_new_post($post) {
15811584 $ post ->totalscore = 0 ;
15821585 }
15831586
1584- if (review::get_review_level ($ moodleoverflow ) == review::EVERYTHING ) {
1587+ // Set to not reviewed, if posts should be reviewed, and user is not a reviewer themselves.
1588+ if (review::get_review_level ($ moodleoverflow ) == review::EVERYTHING &&
1589+ !has_capability ('mod/moodleoverflow:reviewpost ' , $ modulecontext )) {
15851590 $ post ->reviewed = 0 ;
1591+ } else {
1592+ $ post ->reviewed = 1 ;
15861593 }
15871594
15881595 // Add the post to the database.
15891596 $ post ->id = $ DB ->insert_record ('moodleoverflow_posts ' , $ post );
15901597 $ DB ->set_field ('moodleoverflow_posts ' , 'message ' , $ post ->message , array ('id ' => $ post ->id )); // ??
15911598 moodleoverflow_add_attachment ($ post , $ moodleoverflow , $ cm );
15921599
1593- // Update the discussion.
1594- $ DB ->set_field ('moodleoverflow_discussions ' , 'timemodified ' , $ post ->modified , array ('id ' => $ post ->discussion ));
1595- $ DB ->set_field ('moodleoverflow_discussions ' , 'usermodified ' , $ post ->userid , array ('id ' => $ post ->discussion ));
1600+ if ($ post ->reviewed ) {
1601+ // Update the discussion.
1602+ $ DB ->set_field ('moodleoverflow_discussions ' , 'timemodified ' , $ post ->modified , array ('id ' => $ post ->discussion ));
1603+ $ DB ->set_field ('moodleoverflow_discussions ' , 'usermodified ' , $ post ->userid , array ('id ' => $ post ->discussion ));
1604+ }
15961605
15971606 // Mark the created post as read if the user is tracking the discussion.
15981607 $ cantrack = \mod_moodleoverflow \readtracking::moodleoverflow_can_track_moodleoverflows ($ moodleoverflow );
@@ -1635,7 +1644,7 @@ function moodleoverflow_update_post($newpost) {
16351644 }
16361645 }
16371646
1638- if (isset ( $ newpost ->reviewed ) ? $ newpost -> reviewed : $ post ->reviewed ) {
1647+ if ($ newpost ->reviewed ?? $ post ->reviewed ) {
16391648 // Update the date and the user of the post and the discussion.
16401649 $ post ->modified = time ();
16411650 $ discussion ->timemodified = $ post ->modified ;
0 commit comments