add backend controller for users
This commit is contained in:
parent
ed1a0a15b8
commit
7db6fce401
117
src/Application/Controller/Admin/AdminUser.php
Normal file
117
src/Application/Controller/Admin/AdminUser.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
|
||||
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
||||
use D3\Linkmobility4OXID\Application\Model\Sms;
|
||||
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
|
||||
use OxidEsales\Eshop\Application\Model\Remark;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class AdminUser extends AdminController
|
||||
{
|
||||
protected $_sThisTemplate = 'd3adminuser.tpl';
|
||||
|
||||
/**
|
||||
* @var Sms
|
||||
*/
|
||||
protected $sms;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->user = $user = oxNew(User::class);
|
||||
$user->load($this->getEditObjectId());
|
||||
|
||||
$this->sms = oxNew(Sms::class);
|
||||
|
||||
$this->addTplParam('recipient', $this->getRecipientFromCurrentUser());
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Recipient|false
|
||||
*/
|
||||
public function getRecipientFromCurrentUser()
|
||||
{
|
||||
try {
|
||||
return oxNew( UserRecipients::class, $this->user )->getSmsRecipient();
|
||||
} catch (noRecipientFoundException $e) {
|
||||
Registry::getUtilsView()->addErrorToDisplay(
|
||||
Registry::getLang()->translateString($e->getMessage())
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$messageBody = Registry::getRequest()->getRequestEscapedParameter( 'messagebody' );
|
||||
|
||||
if (strlen($messageBody) <= 1) {
|
||||
Registry::getUtilsView()->addErrorToDisplay(
|
||||
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$user = oxNew(User::class);
|
||||
$user->load($this->getEditObjectId());
|
||||
|
||||
$sms = oxNew(Sms::class);
|
||||
if ($sms->sendUserAccountMessage($user, $messageBody)) {
|
||||
$this->setRemark( $messageBody );
|
||||
Registry::getUtilsView()->addErrorToDisplay(
|
||||
sprintf(
|
||||
Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'),
|
||||
$sms->getResponse()->getSmsCount()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
Registry::getUtilsView()->addErrorToDisplay(
|
||||
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $messageBody
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function setRemark( $messageBody )
|
||||
{
|
||||
$remark = oxNew( Remark::class );
|
||||
$remark->assign( [
|
||||
'oxtype' => 'LMSMS',
|
||||
'oxparentid' => $this->getEditObjectId(),
|
||||
'oxtext' => $messageBody
|
||||
] );
|
||||
$remark->save();
|
||||
}
|
||||
}
|
@ -15,7 +15,13 @@
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Model\Exceptions;
|
||||
|
||||
class noRecipientFoundException implements abortSendingExceptionInterface
|
||||
{
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
|
||||
class noRecipientFoundException extends StandardException implements abortSendingExceptionInterface
|
||||
{
|
||||
public function __construct( $sMessage = "D3LM_EXC_NO_RECIPIENT_SET", $iCode = 0, Exception $previous = null )
|
||||
{
|
||||
parent::__construct( $sMessage, $iCode, $previous );
|
||||
}
|
||||
}
|
@ -16,9 +16,11 @@
|
||||
namespace D3\Linkmobility4OXID\Application\Model;
|
||||
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\abortSendingExceptionInterface;
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
||||
use D3\Linkmobility4OXID\Modules\Application\Model\RequestFactory;
|
||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
use D3\LinkmobilityClient\SMS\RequestFactory;
|
||||
use D3\LinkmobilityClient\Response\ResponseInterface;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
@ -26,6 +28,8 @@ use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class Sms
|
||||
{
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param $message
|
||||
@ -33,6 +37,27 @@ class Sms
|
||||
* @return bool
|
||||
*/
|
||||
public function sendUserAccountMessage(User $user, $message): bool
|
||||
{
|
||||
try {
|
||||
return $this->sendCustomRecipientMessage(
|
||||
[ oxNew( UserRecipients::class, $user )->getSmsRecipient() ],
|
||||
$message
|
||||
);
|
||||
} catch (noRecipientFoundException $e) {
|
||||
Registry::getLogger()->warning($e->getMessage());
|
||||
Registry::getUtilsView()->addErrorToDisplay($e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $recipientsArray
|
||||
* @param $message
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendCustomRecipientMessage(array $recipientsArray, $message): bool
|
||||
{
|
||||
try {
|
||||
$configuration = oxNew( Configuration::class );
|
||||
@ -42,9 +67,13 @@ class Sms
|
||||
$request->setTestMode( $configuration->getTestMode() )->setMethod( RequestInterface::METHOD_POST )->setSenderAddress( oxNew( Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry() ) )->setSenderAddressType( RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL );
|
||||
|
||||
$recipientsList = $request->getRecipientsList();
|
||||
$recipientsList->add(oxNew( UserRecipients::class, $user )->getSmsRecipient());
|
||||
foreach ($recipientsArray as $recipient) {
|
||||
$recipientsList->add( $recipient );
|
||||
}
|
||||
$response = $client->request( $request );
|
||||
|
||||
$this->response = $response;
|
||||
|
||||
return $response->isSuccessful();
|
||||
} catch (abortSendingExceptionInterface $e) {
|
||||
Registry::getLogger()->warning($e->getMessage());
|
||||
@ -62,4 +91,12 @@ class Sms
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface|null
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
}
|
@ -24,5 +24,16 @@ $aLang = [
|
||||
|
||||
'SHOP_MODULE_GROUP_d3linkmobility_general' => 'Grundeinstellungen',
|
||||
'SHOP_MODULE_d3linkmobility_debug' => 'Debug-Modus',
|
||||
'SHOP_MODULE_d3linkmobility_apitoken' => 'API-Token'
|
||||
'SHOP_MODULE_d3linkmobility_apitoken' => 'API-Token',
|
||||
|
||||
'D3LM_ADMIN_USER_RECIPIENT' => 'Empfängernummer',
|
||||
'D3LM_ADMIN_USER_MESSAGE' => 'Nachricht',
|
||||
'D3LM_ADMIN_SEND' => 'versenden',
|
||||
|
||||
'D3LM_EXC_MESSAGE_NO_LENGTH' => 'Die Mitteilung muss Inhalt haben',
|
||||
'D3LM_EXC_SMS_SUCC_SENT' => 'Die Mitteilung wurde erfolgreich versendet. (%1$s Nachricht(en) verwendet)',
|
||||
'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'Beim Versenden der Nachricht(en) ist ein unerwarteter Fehler aufgetreten.',
|
||||
'D3LM_EXC_NO_RECIPIENT_SET' => 'Kein (verwendbarer) Empfänger gesetzt.',
|
||||
|
||||
'tbcluser_linkmobility' => 'SMS-Versand'
|
||||
];
|
||||
|
51
src/Application/views/admin/tpl/adminuser.tpl
Normal file
51
src/Application/views/admin/tpl/adminuser.tpl
Normal file
@ -0,0 +1,51 @@
|
||||
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]
|
||||
|
||||
<form name="transfer" id="transfer" action="[{$oViewConf->getSelfLink()}]" method="post">
|
||||
[{$oViewConf->getHiddenSid()}]
|
||||
<input type="hidden" name="oxid" value="[{$oxid}]">
|
||||
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
|
||||
</form>
|
||||
|
||||
[{if $recipient}]
|
||||
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post">
|
||||
[{$oViewConf->getHiddenSid()}]
|
||||
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
|
||||
<input type="hidden" name="fnc" value="">
|
||||
<input type="hidden" name="oxid" value="[{$oxid}]">
|
||||
|
||||
<table cellspacing="0" cellpadding="0" border="0" width="98%">
|
||||
<tr>
|
||||
<!-- Anfang linke Seite -->
|
||||
<td valign="top" class="edittext" align="left" width="100%">
|
||||
<table cellspacing="0" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td class="edittext">
|
||||
<label for="recipient">[{oxmultilang ident="D3LM_ADMIN_USER_RECIPIENT"}]</label>
|
||||
</td>
|
||||
<td class="edittext">
|
||||
<input type="text" id="recipient" name="recipient" class="editinput" size="60" value="[{$oView->getRecipientFromCurrentUser()}]" readonly disabled>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="edittext">
|
||||
<label for="messagebody">[{oxmultilang ident="D3LM_ADMIN_USER_MESSAGE"}]</label>
|
||||
</td>
|
||||
<td class="edittext">
|
||||
<textarea id="messagebody" name="messagebody" class="editinput" cols="60" rows="5" [{$readonly}]></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="edittext">
|
||||
</td>
|
||||
<td class="edittext"><br>
|
||||
<input type="submit" class="edittext" name="save" value="[{oxmultilang ident="D3LM_ADMIN_SEND"}]" onClick="document.myedit.fnc.value='send'"" [{$readonly}]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
[{/if}]
|
||||
|
||||
[{include file="bottomitem.tpl"}]
|
38
src/Modules/Application/Model/RequestFactory.php
Normal file
38
src/Modules/Application/Model/RequestFactory.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\Linkmobility4OXID\Modules\Application\Model;
|
||||
|
||||
use D3\Linkmobility4OXID\Application\Model\Configuration;
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
use D3\LinkmobilityClient\SMS\SmsRequestInterface;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
|
||||
class RequestFactory extends \D3\LinkmobilityClient\SMS\RequestFactory
|
||||
{
|
||||
public function getSmsRequest(): SmsRequestInterface
|
||||
{
|
||||
$configuration = oxNew( Configuration::class );
|
||||
|
||||
$request = parent::getSmsRequest();
|
||||
$request->setTestMode($configuration->getTestMode())
|
||||
->setSenderAddress(
|
||||
oxNew( Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry() )
|
||||
)
|
||||
->setSenderAddressType( RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL );
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
10
src/menu.xml
Normal file
10
src/menu.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<OX>
|
||||
<OXMENU id="NAVIGATION_ESHOPADMIN">
|
||||
<MAINMENU id="mxuadmin">
|
||||
<SUBMENU id="mxusers" cl="admin_user" list="user_list">
|
||||
<TAB id="tbcluser_linkmobility" cl="d3linkmobility_user" />
|
||||
</SUBMENU>
|
||||
</MAINMENU>
|
||||
</OXMENU>
|
||||
</OX>
|
@ -2,9 +2,12 @@
|
||||
/**
|
||||
* Metadata version
|
||||
*/
|
||||
|
||||
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
|
||||
|
||||
$sMetadataVersion = '2.1';
|
||||
$sModuleId = 'd3linkmobility';
|
||||
$sD3Logo = '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="height:1em;width:1em"> ';
|
||||
$sModuleId = 'd3linkmobility';
|
||||
$sD3Logo = '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="height:1em;width:1em"> ';
|
||||
|
||||
/**
|
||||
* Module information
|
||||
@ -25,8 +28,12 @@ $aModule = [
|
||||
\OxidEsales\Eshop\Application\Controller\StartController::class => \D3\Linkmobility4OXID\Modules\Application\Controller\StartController::class,
|
||||
\OxidEsales\Eshop\Application\Controller\ContactController::class => \D3\Linkmobility4OXID\Modules\Application\Controller\ContactController::class
|
||||
],
|
||||
'controllers' => [],
|
||||
'templates' => [],
|
||||
'controllers' => [
|
||||
'd3linkmobility_user' => AdminUser::class
|
||||
],
|
||||
'templates' => [
|
||||
'd3adminuser.tpl' => 'd3/linkmobility/Application/views/admin/tpl/adminuser.tpl'
|
||||
],
|
||||
'events' => [],
|
||||
'settings' => [
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user