Skip to content

Commit

Permalink
save picture in draft area correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaroWalter committed Jul 22, 2024
1 parent 70994d6 commit 8620c35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@ function moodleoverflow_add_discussion($discussion, $modulecontext, $userid = nu

// Submit the post to the database and get its id.
$post->id = $DB->insert_record('moodleoverflow_posts', $post);
$context = context_module::instance($cm->id);
$text = file_save_draft_area_files($discussion->draftitemid, $context->id, 'mod_moodleoverflow', 'post', $post->id,
mod_moodleoverflow_post_form::editor_options($context, null), $post->message);
$DB->set_field('moodleoverflow_posts', 'message', $text, ['id' => $post->id]);

// Create the discussion object.
$discussionobject = new stdClass();
Expand Down Expand Up @@ -1678,7 +1682,10 @@ function moodleoverflow_add_new_post($post) {

// Add the post to the database.
$post->id = $DB->insert_record('moodleoverflow_posts', $post);
$DB->set_field('moodleoverflow_posts', 'message', $post->message, ['id' => $post->id]);
$context = context_module::instance($cm->id);
$text = file_save_draft_area_files($post->draftitemid, $context->id, 'mod_moodleoverflow', 'post', $post->id,
mod_moodleoverflow_post_form::editor_options($context, null), $post->message);
$DB->set_field('moodleoverflow_posts', 'message', $text, ['id' => $post->id]);
moodleoverflow_add_attachment($post, $moodleoverflow, $cm);

if ($post->reviewed) {
Expand Down Expand Up @@ -1714,6 +1721,7 @@ function moodleoverflow_update_post($newpost) {
$post = $DB->get_record('moodleoverflow_posts', ['id' => $newpost->id]);
$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $post->discussion]);
$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $discussion->moodleoverflow]);
$cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id);

// Allowed modifiable fields.
$modifiablefields = [
Expand Down Expand Up @@ -1742,6 +1750,10 @@ function moodleoverflow_update_post($newpost) {

// Update the post and the corresponding discussion.
$DB->update_record('moodleoverflow_posts', $post);
$context = context_module::instance($cm->id);
$text = file_save_draft_area_files($newpost->draftitemid, $context->id, 'mod_moodleoverflow', 'post', $post->id,
mod_moodleoverflow_post_form::editor_options($context, null), $post->message);
$DB->set_field('moodleoverflow_posts', 'message', $text, ['id' => $post->id]);
$DB->update_record('moodleoverflow_discussions', $discussion);

$cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id);
Expand Down
3 changes: 2 additions & 1 deletion post.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@
}

// Is it submitted?
if ($fromform = $mformpost->get_data()) {
if ($mformpost->is_submitted() && $fromform = $mformpost->get_data()) {

// Redirect url in case of occuring errors.
if (empty($SESSION->fromurl)) {
Expand All @@ -596,6 +596,7 @@
}

// Format the submitted data.
$fromform->draftitemid = $fromform->message['itemid'];
$fromform->messageformat = $fromform->message['format'];
$fromform->message = $fromform->message['text'];
$fromform->messagetrust = trusttext_trusted($modulecontext);
Expand Down

0 comments on commit 8620c35

Please sign in to comment.