Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
Fixed sending email to developer #15
Browse files Browse the repository at this point in the history
Signed-off-by: Roland Dalmulder <[email protected]>
  • Loading branch information
roland-d committed Jul 18, 2020
1 parent c20c637 commit 5258aa6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ public function sendMessage(): void
$body = $this->input->get('body', '', 'raw');
$messageId = $this->input->getInt('messageId');
$developerId = $this->input->getInt('developerId');
$extensionId = $this->input->getInt('extensionId');
$userId = $this->input->getInt('userId');

/** @var JedModelEmail $model */
$model = $this->getModel('Email', 'JedModel');
$model->sendEmail($body, $messageId, $developerId, $userId);
$model->sendEmail($body, $messageId, $developerId, $userId, $extensionId);
$message = Text::_('COM_JED_MESSAGE_SENT_TO_DEVELOPER');

$error = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ COM_JED_EXTENSIONS_SELECT_TEMPLATE="- Select Template -"
COM_JED_SEND_EMAIL="Send Email"
COM_JED_EXTENSIONS_MISSING_MESSAGE_ID="No message has been selected"
COM_JED_EXTENSIONS_MISSING_DEVELOPER_ID="No developer found for this extension"
COM_JED_EXTENSIONS_MISSING_EXTENSION_ID="The extension ID is missing"
COM_JED_EXTENSIONS_ERROR_DURING_SEND_EMAIL="An error occurred sending the email"
COM_JED_TRANSACTION_TYPE_EXTENSION="Extension"
COM_JED_EXTENSION_HISTORY_DATE="Date"
Expand All @@ -193,6 +194,7 @@ COM_JED_EXTENSION_HISTORY_MEMBER="Member"
COM_JED_EXTENSION_HISTORY_USER="User"
COM_JED_EXTENSION_HISTORY_LOG_MAIL="Email"
COM_JED_EXTENSION_HISTORY_LOG_ACTIONLOG="Action"
COM_JED_DEVELOPER_NOT_FOUND="Developer has not been found"

; Tabs
COM_JED_EXTENSIONS_GENERAL_TAB="General"
Expand Down
49 changes: 33 additions & 16 deletions public_html/administrator/components/com_jed/models/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getForm($data = [], $loadData = true)
['control' => 'jform', 'load_data' => $loadData]
);

if (!is_object($form))
if ( ! is_object($form))
{
return false;
}
Expand Down Expand Up @@ -83,11 +83,11 @@ public function testEmail(): array
$result['msg'] = '';
$result['state'] = 'error';

if (!$cids || !$email)
if ( ! $cids || ! $email)
{
$result['msg'] = Text::_('COM_JED_NO_EMAILS_FOUND');

if (!$email)
if ( ! $email)
{
$result['msg'] = Text::_('COM_JED_MISSING_EMAIL_ADDRESS');
}
Expand Down Expand Up @@ -116,7 +116,10 @@ public function testEmail(): array
{
$mail->clearAddresses();

if ($mail->sendMail($from, $fromName, $email, $details->subject, $details->body, true))
if ($mail->sendMail(
$from, $fromName, $email, $details->subject, $details->body,
true
))
{
$result['msg'] = Text::_('COM_JED_TESTEMAIL_SENT');
$result['state'] = '';
Expand All @@ -134,18 +137,27 @@ public function testEmail(): array
* @param int $messageId The message details to use for sending
* @param int $developerId The developer to send the message to
* @param int $userId The JED member sending the message
* @param int $extensionId The extension ID the message is about
*
* @return void
*
* @since 4.0.0
*
* @throws Exception
*/
public function sendEmail(string $body, int $messageId, int $developerId, int $userId): void
{
public function sendEmail(string $body, int $messageId, int $developerId,
int $userId, int $extensionId
): void {
// Get the developer details
$developer = User::getInstance($developerId);
$sender = User::getInstance($userId);

if ($developer->get('id', null) === null)
{
throw new InvalidArgumentException(
Text::_('COM_JED_DEVELOPER_NOT_FOUND')
);
}

$sender = User::getInstance($userId);

// Get the mail details
$mail = $this->getItem($messageId);
Expand All @@ -171,7 +183,7 @@ public function sendEmail(string $body, int $messageId, int $developerId, int $u
throw new RuntimeException($result->getMessage());
}

$this->storeEmail($subject, $body, $developer, $sender);
$this->storeEmail($extensionId, $subject, $body, $developer, $sender);
}

/**
Expand All @@ -195,20 +207,23 @@ private function setupMailer(string $fromName): void
/**
* Store the sent email.
*
* @param string $subject The message subject
* @param string $body The message body
* @param User $developer The developer details
* @param User $sender The JED member details
* @param int $extensionId The extension ID the message is about
* @param string $subject The message subject
* @param string $body The message body
* @param User $developer The developer details
* @param User $sender The JED member details
*
* @return void
*
* @since 4.0.0
*/
private function storeEmail(string $subject, string $body, User $developer, User $sender): void
{
private function storeEmail(int $extensionId, string $subject, string $body,
User $developer, User $sender
): void {
$emailTable = Table::getInstance('Emaillog', 'Table');
$emailTable->save(
[
'extension_id' => $extensionId,
'subject' => $subject,
'body' => $body,
'developer_id' => $developer->get('id'),
Expand All @@ -232,7 +247,9 @@ private function storeEmail(string $subject, string $body, User $developer, User
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = Factory::getApplication()->getUserState('com_jed.edit.email.data', []);
$data = Factory::getApplication()->getUserState(
'com_jed.edit.email.data', []
);

if (0 === count($data))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,13 @@ public function getHistory(int $extensionId): array
'actionLogs.message_language_key',
'actionLogs.message',
'actionLogs.log_date',
'users.name'
'users.name',
],
[
'message_language_key',
'message',
'logDate',
'name'
'name',
]
)
)
Expand Down Expand Up @@ -571,6 +571,7 @@ public function getHistory(int $extensionId): array
'emailLogs.developer_email',
'emailLogs.created_by',
'emailLogs.created',
'emailLogs.developer_id',
'users.name'
],
[
Expand All @@ -581,6 +582,7 @@ public function getHistory(int $extensionId): array
'developerEmail',
'created_by',
'logDate',
'developerId',
'memberName'
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Text::script('COM_JED_EXTENSIONS_ERROR_DURING_SEND_EMAIL', true);
Text::script('COM_JED_EXTENSIONS_MISSING_MESSAGE_ID', true);
Text::script('COM_JED_EXTENSIONS_MISSING_DEVELOPER_ID', true);
Text::script('COM_JED_EXTENSIONS_MISSING_EXTENSION_ID', true);

$extensionUrl = Uri::root() . 'extension/' . $this->item->alias;
$downloadUrl = 'index.php?option=com_jed&task=extension.download&id=' . $this->item->id;
Expand Down Expand Up @@ -180,7 +181,7 @@
<?php
foreach ($this->item->history as $history):
?><tr><?php
?><td><?php echo $history->logDate; ?></td><?php
?><td><?php echo HTMLHelper::_('date', $history->logDate, Text::_('DATE_FORMAT_LC6')); ?></td><?php
?><td><?php echo Text::_('COM_JED_EXTENSION_HISTORY_LOG_' . $history->type); ?></td><?php

if ($history->type === 'mail')
Expand All @@ -190,12 +191,12 @@
<?php echo $history->body; ?>
</td><?php
?><td><?php echo $history->memberName; ?></td><?php
?><td><?php echo $history->developerName; ?> &lt;<?php echo $history->developerEmail; ?>&gt;</td><?php
?><td><?php echo HTMLHelper::_('link', 'index.php?option=com_users&task=user.edit&id=' . $history->developerId, $history->developerName); ?> &lt;<?php echo $history->developerEmail; ?>&gt;</td><?php
}
elseif ($history->type === 'actionLog')
{
?><td><?php echo ActionlogsHelper::getHumanReadableLogMessage($history); ?></td><?php
?><td><?php echo $history->name; ?></td><?php
?><td><?php echo $history->name; ?></td><?php
?><td></td><?php
}
?></tr><?php
Expand Down
11 changes: 9 additions & 2 deletions public_html/media/com_jed/js/jed.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const jed = (function () {
*/
jed.sendMessage = () => {
const messageId = document.getElementById('jform_template').value,
developerId = document.getElementById('jform_created_by_id').value;
developerId = document.getElementById('jform_created_by_id').value,
extensionId = document.getElementById('jform_id').value;

// Check if we have any values
if (isNaN(parseInt(messageId)) === true) {
Expand All @@ -71,12 +72,18 @@ const jed = (function () {
return false;
}

if (isNaN(parseInt(extensionId)) === true) {
renderMessage(Joomla.JText._('COM_JED_EXTENSIONS_MISSING_EXTENSION_ID'), 'error');
return false;
}

let data = new FormData();
data.append('option', 'com_jed');
data.append('task', 'ajax.sendMessage');
data.append('body', tinyMCE.activeEditor.getContent());
data.append('messageId', messageId);
data.append('developerId', developerId);
data.append('extensionId', extensionId);
data.append('userId', Joomla.getOptions('joomla.userId'));
data.append('format', 'json');

Expand Down Expand Up @@ -152,4 +159,4 @@ const jed = (function () {

// Return the public parts
return jed;
}());
}());

0 comments on commit 5258aa6

Please sign in to comment.