/** * Save the locked state for a post * * @return result array. */ public function save_posts_locked_from_submit() { global $DB; // Ensure that post exists and get the right courseid. $postid = required_param('postid', PARAM_INT); if (!($post = $DB->get_record('format_socialwall_posts', array('id' => $postid)))) { print_error('invalidpostid', 'format_socialwall'); } // ... check capability. $coursecontext = \context_course::instance($post->courseid); if (!has_capability('format/socialwall:lockcomment', $coursecontext)) { print_error('missingcaplockcomment', 'format_socialwall'); } $locked = optional_param('locked', '0', PARAM_INT); if ($post->locked != $locked) { $post->locked = $locked; $post->timemodified = time(); $DB->update_record('format_socialwall_posts', $post); // We use a instant enqueueing, if needed you might use events here. notification::enqueue_post_locked($post); } return array('error' => '0', 'message' => 'postsaved', 'postid' => $post->id, 'locked' => "{$post->locked}"); }