public function prepare_message_for_edit($cm, $post)
 {
     $this->append_edited_by($post);
     $context = \context_module::instance($cm->id);
     $post = trusttext_pre_edit($post, 'message', $context);
     $itemid = file_get_submitted_draft_itemid('message');
     $message = file_prepare_draft_area($itemid, $context->id, 'mod_hsuforum', 'post', $post->id, \mod_hsuforum_post_form::editor_options($context, $post->id), $post->message);
     return array($message, $itemid);
 }
Esempio n. 2
0
        $formheading = get_string('yournewtopic', 'hsuforum');
    }
}
if (hsuforum_is_subscribed($USER->id, $forum->id)) {
    $subscribe = true;
} else {
    if (hsuforum_user_has_posted($forum->id, 0, $USER->id)) {
        $subscribe = false;
    } else {
        // user not posted yet - use subscription default specified in profile
        $subscribe = !empty($USER->autosubscribe);
    }
}
$postid = empty($post->id) ? null : $post->id;
$draftid_editor = file_get_submitted_draft_itemid('message');
$currenttext = file_prepare_draft_area($draftid_editor, $modcontext->id, 'mod_hsuforum', 'post', $postid, mod_hsuforum_post_form::editor_options($modcontext, $postid), $post->message);
$mform_post->set_data(array('attachments' => $draftitemid, 'subject' => $post->subject, 'message' => array('text' => $currenttext, 'format' => empty($post->messageformat) ? editors_get_preferred_format() : $post->messageformat, 'itemid' => $draftid_editor), 'subscribe' => $subscribe ? 1 : 0, 'mailnow' => !empty($post->mailnow), 'userid' => $post->userid, 'parent' => $post->parent, 'reveal' => $post->reveal, 'privatereply' => $post->privatereply, 'discussion' => $post->discussion, 'course' => $course->id) + $page_params + (isset($post->format) ? array('format' => $post->format) : array()) + (isset($discussion->timestart) ? array('timestart' => $discussion->timestart) : array()) + (isset($discussion->timeend) ? array('timeend' => $discussion->timeend) : array()) + (isset($post->groupid) ? array('groupid' => $post->groupid) : array()) + (isset($discussion->id) ? array('discussion' => $discussion->id) : array()));
if ($fromform = $mform_post->get_data()) {
    if (empty($SESSION->fromurl)) {
        $errordestination = "{$CFG->wwwroot}/mod/hsuforum/view.php?f={$forum->id}";
    } else {
        $errordestination = $SESSION->fromurl;
    }
    $fromform->itemid = $fromform->message['itemid'];
    $fromform->messageformat = $fromform->message['format'];
    $fromform->message = $fromform->message['text'];
    // WARNING: the $fromform->message array has been overwritten, do not use it anymore!
    $fromform->messagetrust = trusttext_trusted($modcontext);
    $contextcheck = isset($fromform->groupinfo) && has_capability('mod/hsuforum:movediscussions', $modcontext);
    if ($fromform->edit) {
        // Updating a post
Esempio n. 3
0
/**
 * Given an object containing all the necessary data,
 * create a new discussion and return the id
 *
 * @param object $post
 * @param mixed $mform
 * @param string $unused
 * @param int $userid
 * @param \mod_hsuforum\upload_file $uploader
 * @return object
 */
function hsuforum_add_discussion($discussion, $mform = null, $unused = null, $userid = null, \mod_hsuforum\upload_file $uploader = null)
{
    global $USER, $CFG, $DB;
    $timenow = time();
    if (is_null($userid)) {
        $userid = $USER->id;
    }
    // The first post is stored as a real post, and linked
    // to from the discuss entry.
    $forum = $DB->get_record('hsuforum', array('id' => $discussion->forum));
    $cm = get_coursemodule_from_instance('hsuforum', $forum->id);
    $post = new stdClass();
    $post->discussion = 0;
    $post->parent = 0;
    $post->userid = $userid;
    $post->created = $timenow;
    $post->modified = $timenow;
    $post->mailed = HSUFORUM_MAILED_PENDING;
    $post->subject = $discussion->name;
    $post->message = $discussion->message;
    $post->messageformat = $discussion->messageformat;
    $post->messagetrust = $discussion->messagetrust;
    $post->attachments = isset($discussion->attachments) ? $discussion->attachments : null;
    $post->forum = $forum->id;
    // speedup
    $post->course = $forum->course;
    // speedup
    $post->mailnow = $discussion->mailnow;
    $post->reveal = $discussion->reveal;
    if (!is_null($mform)) {
        $data = $mform->get_data();
        if (!empty($data->reveal)) {
            $post->reveal = 1;
        }
    }
    $post->id = $DB->insert_record("hsuforum_posts", $post);
    // TODO: Fix the calling code so that there always is a $cm when this function is called
    if (!empty($cm->id) && !empty($discussion->itemid)) {
        // In "single simple discussions" this may not exist yet
        $context = context_module::instance($cm->id);
        $text = file_save_draft_area_files($discussion->itemid, $context->id, 'mod_hsuforum', 'post', $post->id, mod_hsuforum_post_form::editor_options($context, null), $post->message);
        $DB->set_field('hsuforum_posts', 'message', $text, array('id' => $post->id));
    }
    // Now do the main entry for the discussion, linking to this first post
    $discussion->firstpost = $post->id;
    $discussion->timemodified = $timenow;
    $discussion->usermodified = $post->userid;
    $discussion->userid = $userid;
    $discussion->assessed = 0;
    $post->discussion = $DB->insert_record("hsuforum_discussions", $discussion);
    // Finally, set the pointer on the post.
    $DB->set_field("hsuforum_posts", "discussion", $post->discussion, array("id" => $post->id));
    if (!empty($cm->id)) {
        hsuforum_add_attachment($post, $forum, $cm, $mform, $unused, $uploader);
    }
    hsuforum_mark_post_read($post->userid, $post, $post->forum);
    // Let Moodle know that assessable content is uploaded (eg for plagiarism detection)
    if (!empty($cm->id)) {
        hsuforum_trigger_content_uploaded_event($post, $cm, 'hsuforum_add_discussion');
    }
    return $post->discussion;
}