This commit is contained in:
Dennis Eichhorn 2024-02-04 20:34:12 +00:00
parent cbf1212b2b
commit 1ba2133d85
10 changed files with 396 additions and 61 deletions

View File

@ -0,0 +1,23 @@
[
{
"type": "email_template",
"from": "",
"to": "",
"cc": "",
"bcc": "",
"ishtml": true,
"l11n": {
"en": {
"subject": "Ticket Notification #{ticket_id}",
"body": "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Ticket Notification</title></head><body style=\"font-family: Arial, sans-serif; font-size: 14px; line-height: 1.5;\"><div class=\"container\" style=\"max-width: 600px; margin: 20px auto; padding: 20px; background-color: #fff;\"><h1 style=\"color: #333;\">Ticket Notification</h1><p>Hello {use_name},</p><p>Your ticket has been [created/updated] successfully. Below are the details:</p><div class=\"ticket-details\" style=\"margin-top: 20px; padding: 10px; background-color: #f9f9f9; border-radius: 5px;\"><h2 style=\"color: #333;\">Ticket Information</h2><p><strong>Ticket ID:</strong> {ticket_id}</p><p><strong>Status:</strong> {ticket_status}</p><p><strong>Subject:</strong> {ticket_subject}</p></div><p style=\"margin-top: 40px;\">Jingga e.K. - www.jingga.app - CEO Dennis Eichhorn - Amtsgericht Friedberg HRA 5058</p></td></tr></table></td></tr></table></body></html>",
"bodyalt": "Dear {user_name},\n\nYour ticket has been [created/updated] successfully. Below are the details:\n\nTicket ID: {ticket_id}\nStatus: {ticket_status}\nSubject: {ticket_subject}\n\n\nJingga e.K. - www.jingga.app - CEO Dennis Eichhorn - Amtsgericht Friedberg HRA 5058"
},
"de": {
"subject": "Ticket Benachrichtigung #{ticket_id}",
"body": "<!DOCTYPE html><html lang=\"de\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Ticket Benachrichtigung</title></head><body style=\"font-family: Arial, sans-serif; font-size: 14px; line-height: 1.5;\"><div class=\"container\" style=\"max-width: 600px; margin: 20px auto; padding: 20px; background-color: #fff;\"><h1 style=\"color: #333;\">Ticket Benachrichtigung</h1><p>Hallo {use_name},</p><p>Ihr Ticket wurde erfolgreich [erstellt/upgedated]. Im Folgenden finden Sie die Details:</p><div class=\"ticket-details\" style=\"margin-top: 20px; padding: 10px; background-color: #f9f9f9; border-radius: 5px;\"><h2 style=\"color: #333;\">Ticket Information</h2><p><strong>Ticket ID:</strong> {ticket_id}</p><p><strong>Status:</strong> {ticket_status}</p><p><strong>Betreff:</strong> {ticket_subject}</p></div><p style=\"margin-top: 40px;\">Jingga e.K. - www.jingga.app - CEO Dennis Eichhorn - Amtsgericht Friedberg HRA 5058</p></td></tr></table></td></tr></table></body></html>",
"bodyalt": "Sehr geehrte/r {user_name},\n\nIhr Ticket wurde erfolgreich [erstellt/upgedated]. Im Folgenden finden Sie die Details:\n\nTicket ID: {ticket_id}\nStatus: {ticket_status}\nBetreff: {ticket_subject}\n\n\nJingga e.K. - www.jingga.app - CEO Dennis Eichhorn - Amtsgericht Friedberg HRA 5058"
}
},
"send": false
}
]

View File

@ -0,0 +1,66 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Support\Admin\Install
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Support\Admin\Install;
use Modules\Support\Models\SettingsEnum;
use phpOMS\Application\ApplicationAbstract;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\HttpResponse;
/**
* Media class.
*
* @package Modules\Support\Admin\Install
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class Messages
{
/**
* Install media providing
*
* @param ApplicationAbstract $app Application
* @param string $path Module path
*
* @return void
*
* @since 1.0.0
*/
public static function install(ApplicationAbstract $app, string $path) : void
{
$messages = \Modules\Messages\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Messages.install.json']);
/** @var \Modules\Admin\Controller\ApiController $module */
$module = $app->moduleManager->get('Admin');
$settings = [
[
'id' => null,
'name' => SettingsEnum::SUPPORT_EMAIL_TEMPLATE,
'content' => (string) $messages['email_template'][0]['id'],
'module' => 'Support',
],
];
$response = new HttpResponse();
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('settings', \json_encode($settings));
$module->apiSettingsSet($request, $response);
}
}

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace Modules\Support\Controller;
use Modules\Admin\Models\AccountMapper;
use Modules\Admin\Models\ContactType;
use Modules\Support\Models\NullSupportApp;
use Modules\Support\Models\SupportApp;
use Modules\Support\Models\SupportAppMapper;
@ -27,6 +29,9 @@ use Modules\Tasks\Models\TaskType;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use Modules\Admin\Models\SettingsEnum as AdminSettingsEnum;
use Modules\Messages\Models\EmailMapper;
use Modules\Support\Models\SettingsEnum;
/**
* Api controller for the tickets module.
@ -83,9 +88,133 @@ final class ApiController extends Controller
$ticket = $this->createTicketFromRequest($request);
$this->createModel($request->header->account, $ticket, TicketMapper::class, 'ticket', $request->getOrigin());
$this->notifyEmail($ticket, $response->header->l11n->language);
$this->createStandardCreateResponse($request, $response, $ticket);
}
public function notifyEmail(Ticket $ticket, string $language) : void
{
// @todo decide what to send via email
// status changes, redirects, answers?
// Careful, don't notify own changes and internal changes (e.g. internal note)
$email = '';
$account = null;
if ($this->app->moduleManager->isActive('ClientManagement')) {
$client = \Modules\ClientManagement\Models\ClientMapper::get()
->with('attributes')
->with('attributes/types')
->with('attributes/value')
->with('account/contacts')
->where('account', $ticket->task->for->id)
->where('attributes/types/name', ['support_emails', 'support_email_address'], 'IN')
->execute();
if ($client->getAttribute('support_emails')->value->getValue() === false) {
return;
}
// @todo should this really be a string? Shouldn't this be a contact element? Same goes for billing.
$email = $client->getAttribute('support_email_address')->value->getValue();
$account = $client->account;
}
if ($email === '' || $email === null) {
$supplier = null;
if ($this->app->moduleManager->isActive('SupplierManagement')) {
$supplier = \Modules\SupplierManagement\Models\SupplierMapper::get()
->with('attributes')
->with('attributes/types')
->with('attributes/value')
->with('account/contacts')
->where('account', $ticket->task->for->id)
->where('attributes/types/name', ['support_emails', 'support_email_address'], 'IN')
->execute();
}
if ($supplier->getAttribute('support_emails')->value->getValue() === false) {
return;
}
// @todo should this really be a string? Shouldn't this be a contact element? Same goes for billing.
$email = $supplier->getAttribute('support_email_address')->value->getValue();
$account = $supplier->account;
}
if ($email === '' || $email === null) {
$account = AccountMapper::get()
->with('contacts')
->where('id', $ticket->task->for->id)
->execute();
$email = $account->getContactByType(ContactType::EMAIL)->content;
}
if ($email === '' || $email === null) {
return;
}
$handler = $this->app->moduleManager->get('Admin', 'Api')->setUpServerMailHandler();
/** @var \Model\Setting $emailFrom */
$emailFrom = $this->app->appSettings->get(
names: AdminSettingsEnum::MAIL_SERVER_ADDR,
module: 'Admin'
);
if (empty($emailFrom->content)) {
return;
}
/** @var \Model\Setting $billingTemplate */
$supportTemplate = $this->app->appSettings->get(
names: SettingsEnum::SUPPORT_EMAIL_TEMPLATE,
module: 'Support'
);
$baseEmail = EmailMapper::get()
->with('l11n')
->where('id', (int) $supportTemplate->content)
->execute();
$mail = clone $baseEmail;
$mail->setFrom($emailFrom->content);
$mail->addTo($email);
// @todo probably needs to be changed to messageId = \uniqid() . '-' . $ticket->id ?!
// Careful, uniqueid is overwritten in the email class, will need check for if empty
$mail->addCustomHeader('ticket_id', (string) $ticket->id);
$mailL11n = $baseEmail->getL11nByLanguage($language);
if ($mailL11n->id === 0) {
$mailL11n = $baseEmail->getL11nByLanguage($language = $this->app->l11nServer->language);
}
if ($mailL11n->id === 0) {
$mailL11n = $baseEmail->getL11nByLanguage($language = 'en');
}
$mail->subject = $mailL11n->subject;
$mail->body = $mailL11n->body;
$mail->bodyAlt = $mailL11n->bodyAlt;
$lang = include __DIR__ . '/../../Tasks/Theme/Backend/Lang/' . $language . '.lang.php';
$mail->template = [
'{user_name}' => $account->login,
'{ticket_id}' => $ticket->id,
'{ticket_status}' => $lang['Tasks']['S' . $ticket->task->status],
'{ticket_subject}' => $ticket->task->title,
];
$handler->send($mail);
}
/**
* Method to create ticket from request.
*
@ -143,10 +272,17 @@ final class ApiController extends Controller
public function apiTicketSet(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
{
/** @var \Modules\Support\Models\Ticket $old */
$old = TicketMapper::get()->where('id', (int) $request->getData('id'))->execute();
$old = TicketMapper::get()
->with('task')
->where('id', (int) $request->getData('id'))
->execute();
$new = $this->updateTicketFromRequest($request, clone $old);
$this->updateModel($request->header->account, $old, $new, TicketMapper::class, 'ticket', $request->getOrigin());
$this->notifyEmail($new, $response->header->l11n->language);
$this->createStandardUpdateResponse($request, $response, $new);
}
@ -210,7 +346,11 @@ final class ApiController extends Controller
}
/** @var \Modules\Support\Models\Ticket $ticket */
$ticket = TicketMapper::get()->with('task')->where('id', (int) ($request->getData('ticket')))->execute();
$ticket = TicketMapper::get()
->with('task')
->where('id', (int) ($request->getData('ticket')))
->execute();
$element = $this->createTicketElementFromRequest($request, $ticket);
$old = clone $ticket->task;
@ -219,8 +359,13 @@ final class ApiController extends Controller
$ticket->task->priority = $element->taskElement->priority;
$ticket->task->due = $element->taskElement->due;
$this->createModel($request->header->account, $element, TicketElementMapper::class, 'ticketelement', $request->getOrigin());
$this->createModel($request->header->account, $element, TicketElementMapper::class, 'ticket_element', $request->getOrigin());
$this->updateModel($request->header->account, $old, $ticket->task, TaskMapper::class, 'ticket', $request->getOrigin());
$ticket->task->taskElements[] = $element;
$this->notifyEmail($ticket, $response->header->l11n->language);
$this->createStandardCreateResponse($request, $response, $element);
}
@ -282,7 +427,14 @@ final class ApiController extends Controller
/** @var \Modules\Support\Models\TicketElement $old */
$old = TicketElementMapper::get()->where('id', (int) $request->getData('id'))->execute();
$new = $this->updateTicketElementFromRequest($request, $response, clone $old);
$this->updateModel($request->header->account, $old, $new, TicketElementMapper::class, 'ticketelement', $request->getOrigin());
$this->updateModel($request->header->account, $old, $new, TicketElementMapper::class, 'ticket_element', $request->getOrigin());
$ticket = TicketMapper::get()
->with('task')
->where('task', $new->taskElement->task)
->execute();
$this->notifyEmail($ticket, $response->header->l11n->language);
//$this->updateModel($request->header->account, $ticket, $ticket, TicketMapper::class, 'ticket', $request->getOrigin());
$this->createStandardUpdateResponse($request, $response, $new);

View File

@ -15,14 +15,17 @@ declare(strict_types=1);
namespace Modules\Support\Controller;
use Model\SettingMapper;
use Modules\Media\Models\MediaMapper;
use Modules\Support\Models\SupportAppMapper;
use Modules\Support\Models\TicketMapper;
use Modules\Support\Views\TicketView;
use phpOMS\Asset\AssetType;
use phpOMS\Contract\RenderableInterface;
use phpOMS\DataStorage\Database\Query\OrderType;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Views\View;
use Modules\Profile\Models\SettingsEnum as ProfileSettingsEnum;
/**
* Support controller class.
@ -128,12 +131,17 @@ final class BackendController extends Controller
->with('app')
->where('task/tags/title/language', $request->header->l11n->language);
/** @var \Modules\Support\Models\Ticket $ticket */
$ticket = $request->hasData('for')
/** @var \Modules\Support\Models\Ticket */
$view->data['ticket'] = $request->hasData('for')
? $mapperQuery->where('task', (int) $request->getData('for'))->execute()
: $mapperQuery->where('id', (int) $request->getData('id'))->execute();
$view->data['ticket'] = $ticket;
/** @var \Model\Setting $profileImage */
$profileImage = $this->app->appSettings->get(names: ProfileSettingsEnum::DEFAULT_PROFILE_IMAGE, module: 'Profile');
/** @var \Modules\Media\Models\Media $image */
$image = MediaMapper::get()->where('id', (int) $profileImage->content)->execute();
$view->defaultProfileImage = $image;
$accGrpSelector = new \Modules\Profile\Theme\Backend\Components\AccountGroupSelector\BaseView($this->app->l11nManager, $request, $response);
$view->data['accGrpSelector'] = $accGrpSelector;
@ -141,6 +149,28 @@ final class BackendController extends Controller
$editor = new \Modules\Editor\Theme\Backend\Components\Editor\BaseView($this->app->l11nManager, $request, $response);
$view->data['editor'] = $editor;
$view->data['tickets'] = TicketMapper::getAll()
->with('task')
->where('task/for', $view->data['ticket']->task->for->id)
->sort('createdAt', OrderType::DESC)
->offset(1)
->limit(5)
->execute();
$dt = new \DateTime();
$view->data['hasContractManagement'] = $this->app->moduleManager->isActive('ContractManagement');
if ($view->data['hasContractManagement']) {
$view->data['contracts'] = \Modules\ContractManagement\Models\ContractMapper::getAll()
->where('account', $view->data['ticket']->task->for->id)
->where('end', $dt, '>=') // @todo consider to also allow $end === null
->sort('createdAt', OrderType::DESC)
->limit(5)
->execute();
} else {
$view->data['contracts'] = [];
}
return $view;
}

30
Models/SettingsEnum.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Support\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Support\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Module settings enum.
*
* @package Modules\Support\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
abstract class SettingsEnum extends Enum
{
public const SUPPORT_EMAIL_TEMPLATE = '1002900001'; // Email template for support tickets
}

View File

@ -20,6 +20,7 @@ return ['Support' => [
'AverageProcessTime' => 'Durchschn. Prozess Zeit',
'Closed' => 'Geschlossen',
'Completion' => 'Abgeschlossen',
'Advanced' => 'Fortgeschritten',
'Created' => 'Erstellt',
'Creator' => 'Ersteller',
'Day' => 'Tag',

View File

@ -20,6 +20,7 @@ return ['Support' => [
'AverageProcessTime' => 'Avg. Process Time',
'Closed' => 'Closed',
'Completion' => 'Completion',
'Advanced' => 'Advanced',
'Created' => 'Created',
'Creator' => 'Creator',
'Day' => 'Day',

View File

@ -62,26 +62,6 @@ echo $this->data['nav']->render(); ?>
</div>
<div class="col-xs-12 col-md-3">
<!-- @todo necessary?
<section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Settings'); ?></div>
<div class="portlet-body">
<form>
<table class="layout wf-100">
<tr><td><label for="iIntervarl"><?= $this->getHtml('Interval'); ?></label>
<tr><td><select id="iIntervarl" name="interval">
<option><?= $this->getHtml('All'); ?>
<option><?= $this->getHtml('Day'); ?>
<option><?= $this->getHtml('Week'); ?>
<option selected><?= $this->getHtml('Month'); ?>
<option><?= $this->getHtml('Year'); ?>
</select>
</table>
</form>
</div>
</section>
-->
<section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Stats'); ?></div>
<div class="portlet-body">

View File

@ -58,8 +58,7 @@ echo $this->data['nav']->render(); ?>
</div>
</template>
<?php endif; ?>
<div class="portlet-head">
<div class="row middle-xs">
<div class="portlet-head middle-xs">
<span class="col-xs-0">
<img class="profile-image" loading="lazy" alt="<?= $this->getHtml('User', '0', '0'); ?>" src="<?= $this->getAccountImage($task->createdBy->id); ?>">
</span>
@ -72,7 +71,6 @@ echo $this->data['nav']->render(); ?>
</span>
</span>
</div>
</div>
<div class="portlet-body">
<span class="task-title" data-tpl-text="/title" data-tpl-value="/title" data-value=""><?= $this->printHtml($task->title); ?></span>
<article class="task-content"
@ -347,13 +345,14 @@ echo $this->data['nav']->render(); ?>
<?= $this->getData('accGrpSelector')->render('iReceiver', 'to', true); ?>
</div>
<div class="more-container">
<div class="form-group wf-100">
<div class="more-container wf-100">
<input id="more-customer-sales" type="checkbox" name="more-container">
<label for="more-customer-sales">
<span>Advanced</span>
<span><?= $this->getHtml('Advanced'); ?></span>
<i class="g-icon expand">chevron_right</i>
</label>
<div>
<div class="form-group">
<label for="iPriority"><?= $this->getHtml('Priority'); ?></label>
<select id="iPriority" name="priority">
@ -372,13 +371,13 @@ echo $this->data['nav']->render(); ?>
empty($elements) ? $task->due->format('Y-m-d\TH:i:s') : \end($elements)->taskElement->due->format('Y-m-d\TH:i:s')
); ?>">
</div>
</div>
<div class="form-group">
<label for="iCompletion"><?= $this->getHtml('Completion'); ?></label>
<input id="iCompletion" name="completion" type="number" min="0" max="100">
</div>
</div>
</div>
<div class="form-group">
<label for="iMedia"><?= $this->getHtml('Media'); ?></label>
@ -399,5 +398,57 @@ echo $this->data['nav']->render(); ?>
</div>
</form>
</div>
<section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Tickets'); ?></div>
<div class="slider">
<table id="iTicketList" class="default sticky">
<thead>
<tr>
<td class="wf-100"><?= $this->printHtml('Title'); ?>
<td><?= $this->printHtml('Created'); ?>
<tbody>
<?php
$count = 0;
foreach ($this->data['tickets'] as $value) :
++$count;
?>
<tr>
<td><?= $this->printHtml($value->task->title); ?>
<td><?= $value->task->createdAt->format('Y-m-d'); ?>
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="2" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
</div>
</section>
<?php if ($this->data['hasContractManagement']) : ?>
<section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Contracts', 'ContractManagement'); ?></div>
<div class="slider">
<table id="iContractList" class="default sticky">
<thead>
<tr>
<td class="wf-100"><?= $this->printHtml('Title'); ?>
<td><?= $this->printHtml('Created'); ?>
<tbody>
<?php
$count = 0;
foreach ($this->data['contracts'] as $value) :
++$count;
?>
<tr>
<td><?= $this->printHtml($value->title); ?>
<td><?= $value->createdAt->format('Y-m-d'); ?>
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="2" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
</div>
</section>
<?php endif; ?>
</div>
</div>

View File

@ -21,7 +21,8 @@
"Tasks": "1.0.0"
},
"providing": {
"Navigation": "*"
"Navigation": "*",
"Messages": "*"
},
"load": [
{