/** * @return bool True if read tracking is enabled for this discussion * (it is not too old, and read tracking is turned on globally) */ public function is_read_tracked() { $this->check_full(); return forum::enabled_read_tracking() && $this->discussionfields->timemodified >= forum::get_read_tracking_deadline(); }
/** * Splits this post to become a new discussion * @param $newsubject * @param bool $log True to log action * @return int ID of new discussion */ function split($newsubject, $log = true) { global $CFG; $this->require_children(); // Begin a transaction forum_utils::start_transaction(); $olddiscussion = $this->get_discussion(); // Create new discussion $newest = null; $this->find_newest_child($newest); $newdiscussionid = $olddiscussion->clone_for_split($this->get_id(), $newest->get_id()); // Update all child posts $list = array(); $this->list_child_ids($list); unset($list[0]); // Don't include this post itself if (count($list) > 0) { $inorequals = forum_utils::in_or_equals($list); forum_utils::execute_sql("\nUPDATE\n {$CFG->prefix}forumng_posts\nSET\n discussionid = {$newdiscussionid}\nWHERE\n id {$inorequals}"); } // Update this post $changes = new stdClass(); $changes->id = $this->get_id(); $changes->subject = addslashes($newsubject); $changes->parentpostid = null; //When split the post, reset the important to 0 so that it is not highlighted. $changes->important = 0; // Note don't update modified time, or it makes this post unread, // which isn't very helpful $changes->discussionid = $newdiscussionid; forum_utils::update_record('forumng_posts', $changes); // Update read data if relevant if (forum::enabled_read_tracking() && $newest->get_modified() >= forum::get_read_tracking_deadline()) { $rs = forum_utils::get_recordset_sql("\nSELECT\n userid, time\nFROM\n {$CFG->prefix}forumng_read\nWHERE\n discussionid = " . $olddiscussion->get_id() . "\n AND time >= " . $this->get_created()); while ($rec = rs_fetch_next_record($rs)) { $rec->discussionid = $newdiscussionid; forum_utils::insert_record('forumng_read', $rec); } rs_close($rs); } $olddiscussion->possible_lastpost_change(); // Move attachments $olddiscussionfolder = $olddiscussion->get_attachment_folder(); $newdiscussionfolder = $olddiscussion->get_attachment_folder(0, 0, $newdiscussionid); if (is_dir($olddiscussionfolder)) { // Put this post back on the list $list[0] = $this->get_id(); // Loop through all posts; move attachments if present $madenewfolder = false; foreach ($list as $id) { $oldfolder = $olddiscussionfolder . '/' . $id; $newfolder = $newdiscussionfolder . '/' . $id; if (is_dir($oldfolder)) { if (!$madenewfolder) { check_dir_exists($newfolder, true, true); $madenewfolder = true; } forum_utils::rename($oldfolder, $newfolder); } } } if ($log) { $this->log('split post'); } forum_utils::finish_transaction(); $this->get_discussion()->uncache(); // If discussion-based completion is turned on, this may enable someone // to complete if ($this->get_forum()->get_completion_discussions()) { $this->update_completion(true); } return $newdiscussionid; }