Beispiel #1
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 quora_change_discussionid($postid, $discussionid)
{
    global $DB;
    $DB->set_field('quora_posts', 'discussion', $discussionid, array('id' => $postid));
    if ($posts = $DB->get_records('quora_posts', array('parent' => $postid))) {
        foreach ($posts as $post) {
            quora_change_discussionid($post->id, $discussionid);
        }
    }
    return true;
}
Beispiel #2
0
 $newdiscussion->quora = $discussion->quora;
 $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('quora_discussions', $newdiscussion);
 $newpost = new stdClass();
 $newpost->id = $post->id;
 $newpost->parent = 0;
 $newpost->subject = $name;
 $DB->update_record("quora_posts", $newpost);
 quora_change_discussionid($post->id, $newid);
 // Update last post in each discussion.
 quora_discussion_update_last_post($discussion->id);
 quora_discussion_update_last_post($newid);
 // Fire events to reflect the split..
 $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'other' => array('quoraid' => $quora->id));
 $event = \mod_quora\event\discussion_updated::create($params);
 $event->trigger();
 $params = array('context' => $modcontext, 'objectid' => $newid, 'other' => array('quoraid' => $quora->id));
 $event = \mod_quora\event\discussion_created::create($params);
 $event->trigger();
 $params = array('context' => $modcontext, 'objectid' => $post->id, 'other' => array('discussionid' => $newid, 'quoraid' => $quora->id, 'quoratype' => $quora->type));
 $event = \mod_quora\event\post_updated::create($params);
 $event->add_record_snapshot('quora_discussions', $discussion);
 $event->trigger();
 redirect(quora_go_back_to("discuss.php?d={$newid}"));