Exemplo n.º 1
0
 $newdiscussion->twf = $discussion->twf;
 $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('twf_discussions', $newdiscussion);
 $newpost = new stdClass();
 $newpost->id = $post->id;
 $newpost->parent = 0;
 $newpost->subject = $name;
 $DB->update_record("twf_posts", $newpost);
 twf_change_discussionid($post->id, $newid);
 // Update last post in each discussion.
 twf_discussion_update_last_post($discussion->id);
 twf_discussion_update_last_post($newid);
 // Fire events to reflect the split..
 $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'other' => array('twfid' => $twf->id));
 $event = \mod_twf\event\discussion_updated::create($params);
 $event->trigger();
 $params = array('context' => $modcontext, 'objectid' => $newid, 'other' => array('twfid' => $twf->id));
 $event = \mod_twf\event\discussion_created::create($params);
 $event->trigger();
 $params = array('context' => $modcontext, 'objectid' => $post->id, 'other' => array('discussionid' => $newid, 'twfid' => $twf->id, 'twftype' => $twf->type));
 $event = \mod_twf\event\post_updated::create($params);
 $event->add_record_snapshot('twf_discussions', $discussion);
 $event->trigger();
 redirect(twf_go_back_to("discuss.php?d={$newid}"));
Exemplo n.º 2
0
/**
 * recursively sets the discussion field to $discussionid on $postid and all its children
 * used when pruning a post
 *
 * @global object
 * @param int $postid
 * @param int $discussionid
 * @return bool
 */
function twf_change_discussionid($postid, $discussionid)
{
    global $DB;
    $DB->set_field('twf_posts', 'discussion', $discussionid, array('id' => $postid));
    if ($posts = $DB->get_records('twf_posts', array('parent' => $postid))) {
        foreach ($posts as $post) {
            twf_change_discussionid($post->id, $discussionid);
        }
    }
    return true;
}