コード例 #1
0
 /**
  * @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 mod_forumng::enabled_read_tracking() && $this->discussionfields->timemodified >= mod_forumng::get_read_tracking_deadline();
 }
コード例 #2
0
 /**
  * Splits this post to become a new discussion
  * @param $newsubject
  * @param bool $log True to log action
  * @return int ID of new discussion
  */
 public function split($newsubject, $log = true)
 {
     global $DB;
     $this->require_children();
     // Begin a transaction
     $transaction = $DB->start_delegated_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) {
         list($listsql, $listparams) = mod_forumng_utils::get_in_array_sql('id', $list);
         $DB->execute("\nUPDATE\n    {forumng_posts}\nSET\n    discussionid = ?\nWHERE\n    {$listsql}", array_merge(array($newdiscussionid), $listparams));
     }
     // Update any edited posts in this discussion. Edited posts are
     // not included in the child id list above because they are not
     // loaded as children, but they are conceptually stored as children
     // of one of the posts being moved.
     $parentlist = $list;
     $parentlist[] = $this->get_id();
     list($parentlistsql, $parentlistparams) = mod_forumng_utils::get_in_array_sql('parentpostid', $parentlist);
     $DB->execute("\nUPDATE\n    {forumng_posts}\nSET\n    discussionid = ?\nWHERE\n    oldversion = 1 AND {$parentlistsql}", array_merge(array($newdiscussionid), $parentlistparams));
     // Update this post
     $changes = new stdClass();
     $changes->id = $this->get_id();
     $changes->subject = $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;
     $DB->update_record('forumng_posts', $changes);
     // Update read data if relevant
     if (mod_forumng::enabled_read_tracking() && $newest->get_modified() >= mod_forumng::get_read_tracking_deadline()) {
         $rs = $DB->get_recordset_sql("\nSELECT\n    userid, time\nFROM\n    {forumng_read}\nWHERE\n    discussionid = ? AND time >= ?", array($olddiscussion->get_id(), $this->get_created()));
         foreach ($rs as $rec) {
             $rec->discussionid = $newdiscussionid;
             $DB->insert_record('forumng_read', $rec);
         }
         $rs->close();
     }
     $olddiscussion->possible_lastpost_change();
     if ($log) {
         $this->log('split post');
     }
     $transaction->allow_commit();
     $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;
 }