// For the logs print_error('invalidcoursemodule'); } $modcontext = context_module::instance($cm->id); require_login($course, false, $cm); if (isguestuser()) { // just in case print_error('noguest'); } if (!isset($twf->maxattachments)) { // TODO - delete this once we add a field to the twf table $twf->maxattachments = 3; } $thresholdwarning = twf_check_throttling($twf, $cm); //var_dump($syx_newdiscussion);die; $mform_post = new mod_twf_post_form('post.php', array('course' => $course, 'cm' => $cm, 'coursecontext' => $coursecontext, 'modcontext' => $modcontext, 'twf' => $twf, 'post' => $post, 'subscribe' => \mod_twf\subscriptions::is_subscribed($USER->id, $twf, null, $cm), 'thresholdwarning' => $thresholdwarning, 'edit' => $edit, 'syx_newdiscussion' => $syx_newdiscussion, 'syx_instance' => $syx_instance, 'syx_phase' => $syx_phase, 'syx_teamwork' => $syx_teamwork), 'post', '', array('id' => 'mformtwf')); $draftitemid = file_get_submitted_draft_itemid('attachments'); file_prepare_draft_area($draftitemid, $modcontext->id, 'mod_twf', 'attachment', empty($post->id) ? null : $post->id, mod_twf_post_form::attachment_options($twf)); //load data into form NOW! if ($USER->id != $post->userid) { // Not the original author, so add a message to the end $data = new stdClass(); $data->date = userdate($post->modified); if ($post->messageformat == FORMAT_HTML) { $data->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $USER->id . '&course=' . $post->course . '">' . fullname($USER) . '</a>'; $post->message .= '<p><span class="edited">(' . get_string('editedby', 'twf', $data) . ')</span></p>'; } else { $data->name = fullname($USER); $post->message .= "\n\n(" . get_string('editedby', 'twf', $data) . ')'; } unset($data);
/** * 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 * @return object */ function twf_add_discussion($discussion, $mform = null, $unused = null, $userid = 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. $twf = $DB->get_record('twf', array('id' => $discussion->twf)); $cm = get_coursemodule_from_instance('twf', $twf->id); $post = new stdClass(); $post->discussion = 0; $post->parent = 0; $post->userid = $userid; $post->created = $timenow; $post->modified = $timenow; $post->mailed = FORUM_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->twf = $twf->id; // speedup $post->course = $twf->course; // speedup $post->mailnow = $discussion->mailnow; $post->id = $DB->insert_record("twf_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_twf', 'post', $post->id, mod_twf_post_form::editor_options($context, null), $post->message); $DB->set_field('twf_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("twf_discussions", $discussion); // Finally, set the pointer on the post. $DB->set_field("twf_posts", "discussion", $post->discussion, array("id" => $post->id)); if (!empty($cm->id)) { twf_add_attachment($post, $twf, $cm, $mform, $unused); } if (twf_tp_can_track_twfs($twf) && twf_tp_is_tracked($twf)) { twf_tp_mark_post_read($post->userid, $post, $post->twf); } // Let Moodle know that assessable content is uploaded (eg for plagiarism detection) if (!empty($cm->id)) { twf_trigger_content_uploaded_event($post, $cm, 'twf_add_discussion'); } return $post->discussion; }