|
22 | 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
23 | 23 | */
|
24 | 24 |
|
| 25 | +use mod_moodleoverflow\review; |
| 26 | + |
25 | 27 | defined('MOODLE_INTERNAL') || die;
|
26 | 28 |
|
27 | 29 | require_once("$CFG->libdir/externallib.php");
|
@@ -176,23 +178,34 @@ public static function review_approve_post($postid) {
|
176 | 178 | $postid = $params['postid'];
|
177 | 179 |
|
178 | 180 | $post = $DB->get_record('moodleoverflow_posts', ['id' => $postid], '*', MUST_EXIST);
|
179 |
| - $moodleoverflow = $DB->get_record_sql( |
180 |
| - 'SELECT m.* FROM {moodleoverflow} m ' . |
181 |
| - 'JOIN {moodleoverflow_discussions} d ON d.moodleoverflow = m.id ' . |
182 |
| - 'WHERE d.id = :discussionid', |
183 |
| - ['discussionid' => $post->discussion], MUST_EXIST |
184 |
| - ); |
| 181 | + $discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $post->discussion], '*', MUST_EXIST); |
| 182 | + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $discussion->moodleoverflow], '*', MUST_EXIST); |
| 183 | + |
185 | 184 | $cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id);
|
186 | 185 | $context = context_module::instance($cm->id);
|
187 | 186 |
|
188 | 187 | require_capability('mod/moodleoverflow:reviewpost', $context);
|
189 | 188 |
|
| 189 | + if ($post->reviewed) { |
| 190 | + throw new coding_exception('post was already approved!'); |
| 191 | + } |
| 192 | + |
| 193 | + if (!review::is_post_in_review_period($post)) { |
| 194 | + throw new coding_exception('post is not yet in review period!'); |
| 195 | + } |
| 196 | + |
190 | 197 | $post->reviewed = 1;
|
191 | 198 | $post->timereviewed = time();
|
192 | 199 |
|
193 | 200 | $DB->update_record('moodleoverflow_posts', $post);
|
194 | 201 |
|
195 |
| - return \mod_moodleoverflow\review::get_first_review_post($post->id); |
| 202 | + if ($post->modified > $discussion->timemodified) { |
| 203 | + $discussion->timemodified = $post->modified; |
| 204 | + $discussion->usermodified = $post->userid; |
| 205 | + $DB->update_record('moodleoverflow_discussions', $discussion); |
| 206 | + } |
| 207 | + |
| 208 | + return review::get_first_review_post($post->id); |
196 | 209 | }
|
197 | 210 |
|
198 | 211 | /**
|
@@ -239,8 +252,16 @@ public static function review_reject_post($postid, $reason = null) {
|
239 | 252 |
|
240 | 253 | require_capability('mod/moodleoverflow:reviewpost', $context);
|
241 | 254 |
|
| 255 | + if ($post->reviewed) { |
| 256 | + throw new coding_exception('post was already approved!'); |
| 257 | + } |
| 258 | + |
| 259 | + if (!review::is_post_in_review_period($post)) { |
| 260 | + throw new coding_exception('post is not yet in review period!'); |
| 261 | + } |
| 262 | + |
242 | 263 | // Has to be done before deleting the post.
|
243 |
| - $url = \mod_moodleoverflow\review::get_first_review_post($post->id); |
| 264 | + $url = review::get_first_review_post($post->id); |
244 | 265 |
|
245 | 266 | moodleoverflow_delete_post($post, true, $cm, $moodleoverflow);
|
246 | 267 |
|
|
0 commit comments