Exemple #1
0
     $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}"));
 } else {
     // Display the prune form.
     $course = $DB->get_record('course', array('id' => $twf->course));
Exemple #2
0
 /**
  * Function to create a dummy post.
  *
  * @param array|stdClass $record
  * @return stdClass the post object
  */
 public function create_post($record = null)
 {
     global $DB;
     // Increment the twf post count.
     $this->twfpostcount++;
     // Variable to store time.
     $time = time() + $this->twfpostcount;
     $record = (array) $record;
     if (!isset($record['discussion'])) {
         throw new coding_exception('discussion must be present in phpunit_util::create_post() $record');
     }
     if (!isset($record['userid'])) {
         throw new coding_exception('userid must be present in phpunit_util::create_post() $record');
     }
     if (!isset($record['parent'])) {
         $record['parent'] = 0;
     }
     if (!isset($record['subject'])) {
         $record['subject'] = 'Forum post subject ' . $this->twfpostcount;
     }
     if (!isset($record['message'])) {
         $record['message'] = html_writer::tag('p', 'Forum message post ' . $this->twfpostcount);
     }
     if (!isset($record['created'])) {
         $record['created'] = $time;
     }
     if (!isset($record['modified'])) {
         $record['modified'] = $time;
     }
     if (!isset($record['mailed'])) {
         $record['mailed'] = 0;
     }
     if (!isset($record['messageformat'])) {
         $record['messageformat'] = 0;
     }
     if (!isset($record['messagetrust'])) {
         $record['messagetrust'] = 0;
     }
     if (!isset($record['attachment'])) {
         $record['attachment'] = "";
     }
     if (!isset($record['totalscore'])) {
         $record['totalscore'] = 0;
     }
     if (!isset($record['mailnow'])) {
         $record['mailnow'] = 0;
     }
     $record = (object) $record;
     // Add the post.
     $record->id = $DB->insert_record('twf_posts', $record);
     // Update the last post.
     twf_discussion_update_last_post($record->discussion);
     return $record;
 }
Exemple #3
0
/**
 * Deletes a single twf post.
 *
 * @global object
 * @param object $post Forum post object
 * @param mixed $children Whether to delete children. If false, returns false
 *   if there are any children (without deleting the post). If true,
 *   recursively deletes all children. If set to special value 'ignore', deletes
 *   post regardless of children (this is for use only when deleting all posts
 *   in a disussion).
 * @param object $course Course
 * @param object $cm Course-module
 * @param object $twf Forum
 * @param bool $skipcompletion True to skip updating completion state if it
 *   would otherwise be updated, i.e. when deleting entire twf anyway.
 * @return bool
 */
function twf_delete_post($post, $children, $course, $cm, $twf, $skipcompletion = false)
{
    global $DB, $CFG;
    require_once $CFG->libdir . '/completionlib.php';
    $context = context_module::instance($cm->id);
    if ($children !== 'ignore' && ($childposts = $DB->get_records('twf_posts', array('parent' => $post->id)))) {
        if ($children) {
            foreach ($childposts as $childpost) {
                twf_delete_post($childpost, true, $course, $cm, $twf, $skipcompletion);
            }
        } else {
            return false;
        }
    }
    // Delete ratings.
    require_once $CFG->dirroot . '/rating/lib.php';
    $delopt = new stdClass();
    $delopt->contextid = $context->id;
    $delopt->component = 'mod_twf';
    $delopt->ratingarea = 'post';
    $delopt->itemid = $post->id;
    $rm = new rating_manager();
    $rm->delete_ratings($delopt);
    // Delete attachments.
    $fs = get_file_storage();
    $fs->delete_area_files($context->id, 'mod_twf', 'attachment', $post->id);
    $fs->delete_area_files($context->id, 'mod_twf', 'post', $post->id);
    // Delete cached RSS feeds.
    if (!empty($CFG->enablerssfeeds)) {
        require_once $CFG->dirroot . '/mod/twf/rsslib.php';
        twf_rss_delete_file($twf);
    }
    if ($DB->delete_records("twf_posts", array("id" => $post->id))) {
        twf_tp_delete_read_records(-1, $post->id);
        // Just in case we are deleting the last post
        twf_discussion_update_last_post($post->discussion);
        // Update completion state if we are tracking completion based on number of posts
        // But don't bother when deleting whole thing
        if (!$skipcompletion) {
            $completion = new completion_info($course);
            if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && ($twf->completiondiscussions || $twf->completionreplies || $twf->completionposts)) {
                $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid);
            }
        }
        return true;
    }
    return false;
}