Skip to content

Commit

Permalink
save drafts and send emails with images
Browse files Browse the repository at this point in the history
still requires duplication/broadcast/and other features. Just giving a starter.
  • Loading branch information
Syxton committed Dec 14, 2022
1 parent 9927522 commit c2f3e1c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
37 changes: 37 additions & 0 deletions classes/messenger/messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ public static function compose($user, $course, $formdata, $draftmessage = null,
// Get a message instance for this type, either from draft or freshly created.
$message = self::get_message_instance('compose', $user, $course, $transformeddata, $draftmessage, false);

// TODO: Handle posted file attachments (moodle).
$coursecontext = \context_course::instance($course->id);
$transformeddata->message = file_save_draft_area_files($transformeddata->message_draftitem_id,
$coursecontext->id,
'block_quickmail',
'message_editor',
$message->get('id'),
block_quickmail_config::get_filemanager_options(),
$transformeddata->message);
$message->set('body', $transformeddata->message);
$message->update();

// Get only the resolved recipient user ids.
$recipientuserids = user_repo::get_unique_course_user_ids_from_selected_entities(
$course,
Expand Down Expand Up @@ -234,6 +246,16 @@ public static function save_compose_draft($user, $course, $formdata, $draftmessa
$message = self::get_message_instance('compose', $user, $course, $transformeddata, $draftmessage, true);

// TODO: Handle posted file attachments (moodle).
$coursecontext = \context_course::instance($course->id);
$transformeddata->message = file_save_draft_area_files($transformeddata->message_draftitem_id,
$coursecontext->id,
'block_quickmail',
'message_editor',
$message->get('id'),
block_quickmail_config::get_filemanager_options(),
$transformeddata->message);
$message->set('body', $transformeddata->message);
$message->update();

// Clear any existing draft recipients, and add those that have been recently submitted.
$message->sync_compose_draft_recipients($transformeddata->included_entity_ids, $transformeddata->excluded_entity_ids);
Expand Down Expand Up @@ -338,6 +360,9 @@ public static function duplicate_draft($draftid, $user) {
'usermodified' => $user->id
]);

// TODO: Duplicate files.


// Duplicate the message recipients.
foreach ($originaldraft->get_message_recipients() as $recipient) {
message_recipient::create_new([
Expand Down Expand Up @@ -530,6 +555,18 @@ public function send() {
* @return bool
*/
public function send_to_recipient($recipient) {
$coursecontext = \context_course::instance($this->message->get("course_id"));
$body = file_rewrite_pluginfile_urls($this->message->get("body"),
'pluginfile.php',
$coursecontext->id,
'block_quickmail',
'message_editor',
$this->message->get('id'),
[
'includetoken' => true,
]);
$this->message->set("body", $body);

// Instantiate recipient_send_factory.
$recipientsendfactory = recipient_send_factory::make(
$this->message,
Expand Down
11 changes: 11 additions & 0 deletions classes/requests/transformers/compose_transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function transform_form_data() {
$this->transformed_data->alternate_email_id = $this->get_transformed_alternate_email_id();
$this->transformed_data->to_send_at = $this->get_transformed_to_send_at();
$this->transformed_data->attachments_draftitem_id = $this->get_transformed_attachments_draftitem_id();
$this->transformed_data->message_draftitem_id = $this->get_transformed_message_draftitem_id();
$this->transformed_data->no_reply = $this->get_transformed_no_reply();
}

Expand Down Expand Up @@ -155,6 +156,16 @@ public function get_transformed_attachments_draftitem_id() {
return !$this->form_data->attachments ? 0 : (int) $this->form_data->attachments;
}


/**
* Returns ...
*
* @return int
*/
public function get_transformed_message_draftitem_id() {
return !$this->form_data->message_editor["itemid"] ? 0 : (int) $this->form_data->message_editor["itemid"];
}

/**
* Returns a sanitized no_reply value from the form post data
*
Expand Down
14 changes: 14 additions & 0 deletions compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@
block_quickmail_config::get_filemanager_options()
);

$messagedraftitemid = file_get_submitted_draft_itemid('message_editor');
$messagebody = $draftmessage ? $draftmessage->get('body') : "";
$messagebody = file_prepare_draft_area($messagedraftitemid,
$coursecontext->id,
'block_quickmail',
'message_editor',
$pageparams['draftid'] ?: null,
block_quickmail_config::get_filemanager_options(),
$messagebody);

if ($draftmessage) {
$draftmessage->set('body', $messagebody);
}

// Instantiate the form.
$composeform = \block_quickmail\forms\compose_message_form::make(
$coursecontext,
Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function block_quickmail_pluginfile($course, $cm, $context, $filearea, $args, $f
}

// Make sure the filearea is one of those used by the plugin.
if ($filearea !== 'attachments') {
if ($filearea !== 'attachments' && $filearea !== 'message_editor') {
send_file_not_found();
}

Expand Down

0 comments on commit c2f3e1c

Please sign in to comment.