2022-07-04 09:13:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2022-07-13 13:21:52 +02:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
2022-07-04 09:13:36 +02:00
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
2022-07-13 13:21:52 +02:00
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
2022-07-04 09:13:36 +02:00
|
|
|
*/
|
|
|
|
|
2022-07-13 13:21:52 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-07-04 09:13:36 +02:00
|
|
|
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
|
|
|
|
|
|
|
|
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
2022-07-15 22:46:52 +02:00
|
|
|
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
2022-07-04 09:13:36 +02:00
|
|
|
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
|
2022-07-13 15:38:53 +02:00
|
|
|
use D3\LinkmobilityClient\Response\ResponseInterface;
|
2022-07-04 09:13:36 +02:00
|
|
|
use D3\LinkmobilityClient\ValueObject\Recipient;
|
|
|
|
use Exception;
|
|
|
|
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
|
|
|
|
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->addTplParam('recipient', $this->getRecipientFromCurrentUser());
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Recipient|false
|
|
|
|
*/
|
|
|
|
public function getRecipientFromCurrentUser()
|
|
|
|
{
|
|
|
|
try {
|
2022-07-13 13:23:48 +02:00
|
|
|
return oxNew(UserRecipients::class, $this->user)->getSmsRecipient();
|
2022-07-04 09:13:36 +02:00
|
|
|
} catch (noRecipientFoundException $e) {
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string $message */
|
|
|
|
$message = Registry::getLang()->translateString($e->getMessage());
|
|
|
|
Registry::getUtilsView()->addErrorToDisplay($message);
|
2022-07-04 09:13:36 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-27 09:27:59 +02:00
|
|
|
* @return void
|
2022-07-04 09:13:36 +02:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
2022-07-27 09:27:59 +02:00
|
|
|
public function send(): void
|
2022-07-04 09:13:36 +02:00
|
|
|
{
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string $messageBody */
|
2022-07-13 13:23:48 +02:00
|
|
|
$messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody');
|
2022-07-04 09:13:36 +02:00
|
|
|
|
|
|
|
if (strlen($messageBody) <= 1) {
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string $message */
|
|
|
|
$message = Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH');
|
|
|
|
Registry::getUtilsView()->addErrorToDisplay($message);
|
2022-07-04 09:13:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = oxNew(User::class);
|
|
|
|
$user->load($this->getEditObjectId());
|
|
|
|
|
2022-07-08 15:13:05 +02:00
|
|
|
$sms = oxNew(Sms::class, $messageBody);
|
|
|
|
if ($sms->sendUserAccountMessage($user)) {
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string $format */
|
|
|
|
$format = Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT');
|
|
|
|
$smsCount = $sms->getResponse() ? $sms->getResponse()->getSmsCount() : 0;
|
|
|
|
Registry::getUtilsView()->addErrorToDisplay(sprintf($format, $smsCount));
|
2022-07-04 09:13:36 +02:00
|
|
|
} else {
|
2022-07-13 15:38:53 +02:00
|
|
|
$errorMsg = $sms->getResponse() instanceof ResponseInterface ? $sms->getResponse()->getErrorMessage() : 'no response';
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string $format */
|
|
|
|
$format = Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND');
|
|
|
|
Registry::getUtilsView()->addErrorToDisplay(sprintf($format, $errorMsg));
|
2022-07-04 09:13:36 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-13 13:23:48 +02:00
|
|
|
}
|