/** * Save the discussion to the DB * * @param object $discussion * @param upload_file $uploader */ public function save_discussion($discussion, upload_file $uploader) { $message = ''; $discussion->id = hsuforum_add_discussion($discussion, null, $message); $file = $uploader->process_file_upload($discussion->firstpost); if (!is_null($file)) { $this->db->set_field('hsuforum_posts', 'attachment', 1, array('id' => $discussion->firstpost)); } }
/** * If successful, this function returns the name of the file * * @global object * @param object $post is a full post record, including course and forum * @param object $forum * @param object $cm * @param mixed $mform * @param string $unused * @param \mod_hsuforum\upload_file $uploader * @return bool */ function hsuforum_add_attachment($post, $forum, $cm, $mform = null, $unused = null, \mod_hsuforum\upload_file $uploader = null) { global $DB; if ($uploader instanceof \mod_hsuforum\upload_file) { $files = $uploader->process_file_upload($post->id); $DB->set_field('hsuforum_posts', 'attachment', empty($files) ? 0 : 1, array('id' => $post->id)); return true; } if (empty($mform)) { return false; } if (empty($post->attachments)) { return true; // Nothing to do } $context = context_module::instance($cm->id); $info = file_get_draft_area_info($post->attachments); $present = $info['filecount'] > 0 ? '1' : ''; file_save_draft_area_files($post->attachments, $context->id, 'mod_hsuforum', 'attachment', $post->id, mod_hsuforum_post_form::attachment_options($forum)); $DB->set_field('hsuforum_posts', 'attachment', $present, array('id' => $post->id)); return true; }