if (!$post->parent) { print_error('alreadyfirstpost', 'hsuforum'); } if (!($cm = get_coursemodule_from_instance("hsuforum", $forum->id, $forum->course))) { // For the logs print_error('invalidcoursemodule'); } else { $modcontext = context_module::instance($cm->id); } if (!has_capability('mod/hsuforum:splitdiscussions', $modcontext)) { print_error('cannotsplit', 'hsuforum'); } if (!empty($name) && confirm_sesskey()) { // User has confirmed the prune // Make sure post name does not go beyond 255 chars. $name = \mod_hsuforum\local::shorten_post_name($name); $newdiscussion = new stdClass(); $newdiscussion->course = $discussion->course; $newdiscussion->forum = $discussion->forum; $newdiscussion->name = $name; $newdiscussion->firstpost = $post->id; $newdiscussion->userid = $discussion->userid; $newdiscussion->groupid = $discussion->groupid; $newdiscussion->assessed = $discussion->assessed; $newdiscussion->usermodified = $post->userid; $newdiscussion->timestart = $discussion->timestart; $newdiscussion->timeend = $discussion->timeend; $newid = $DB->insert_record('hsuforum_discussions', $newdiscussion); $newpost = new stdClass(); $newpost->id = $post->id; $newpost->parent = 0;
/** * Creates the post object to be saved. * * @param object $discussion * @param object $parent The parent post * @param \context_module $context * @param array $options These override default post values, EG: set the post message with this * @return \stdClass */ public function create_post_object($discussion, $parent, $context, array $options = array()) { $post = new \stdClass(); $post->course = $discussion->course; $post->forum = $discussion->forum; $post->discussion = $discussion->id; $post->parent = $parent->id; $post->reveal = 0; $post->privatereply = 0; $post->mailnow = 0; $post->subject = $parent->subject; $post->attachment = ''; $post->message = ''; $post->messageformat = FORMAT_MOODLE; $post->messagetrust = trusttext_trusted($context); $post->itemid = 0; // For text editor stuffs. $post->groupid = $discussion->groupid == -1 ? 0 : $discussion->groupid; $post->flags = null; $strre = get_string('re', 'hsuforum'); if (!(\core_text::substr($post->subject, 0, \core_text::strlen($strre)) == $strre)) { $post->subject = $strre . ' ' . $post->subject; } // Make sure post subject does not go beyond 255 chars. $post->subject = \mod_hsuforum\local::shorten_post_name($post->subject); foreach ($options as $name => $value) { if (property_exists($post, $name)) { $post->{$name} = $value; } } return $post; }