2022-07-01 11:48:44 +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-01 11:48:44 +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-01 11:48:44 +02:00
|
|
|
*/
|
|
|
|
|
2022-07-13 13:21:52 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-07-01 11:48:44 +02:00
|
|
|
namespace D3\Linkmobility4OXID\Application\Model;
|
|
|
|
|
|
|
|
use Assert\Assert;
|
2022-07-18 00:27:49 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\Order;
|
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
2022-07-01 11:48:44 +02:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
|
|
|
|
class Configuration
|
|
|
|
{
|
2022-07-27 08:47:20 +02:00
|
|
|
public const GENERAL_APITOKEN = "d3linkmobility_apitoken";
|
|
|
|
public const GENERAL_DEBUG = "d3linkmobility_debug";
|
2022-07-18 00:27:49 +02:00
|
|
|
|
2022-07-27 08:47:20 +02:00
|
|
|
public const ORDER_RECFIELDS = "d3linkmobility_smsOrderRecipientsFields";
|
|
|
|
public const USER_RECFIELDS = "d3linkmobility_smsUserRecipientsFields";
|
2022-07-18 00:27:49 +02:00
|
|
|
|
2022-07-27 08:47:20 +02:00
|
|
|
public const SMS_SENDERNR = "d3linkmobility_smsSenderNumber";
|
|
|
|
public const SMS_SENDERCOUNTRY = "d3linkmobility_smsSenderCountry";
|
2022-07-18 00:27:49 +02:00
|
|
|
|
2022-07-27 08:47:20 +02:00
|
|
|
public const SENDBY_ORDERED = "d3linkmobility_orderActive";
|
|
|
|
public const SENDBY_SENDEDNOW = "d3linkmobility_sendedNowActive";
|
|
|
|
public const SENDBY_CANCELED = "d3linkmobility_cancelOrderActive";
|
2022-07-18 00:27:49 +02:00
|
|
|
|
2022-07-27 08:47:20 +02:00
|
|
|
public const ARGS_CHECKKEYS = "checkKeys";
|
|
|
|
public const ARGS_CHECKCLASS = "checkClassName";
|
2022-07-18 00:27:49 +02:00
|
|
|
|
2022-07-01 11:48:44 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getApiToken(): string
|
|
|
|
{
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string $token */
|
|
|
|
$token = Registry::getConfig()->getConfigParam(self::GENERAL_APITOKEN);
|
|
|
|
$token = trim($token);
|
2022-07-01 11:48:44 +02:00
|
|
|
|
|
|
|
Assert::that($token)->string()->notEmpty();
|
|
|
|
|
|
|
|
return $token;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getTestMode(): bool
|
|
|
|
{
|
2022-07-18 00:27:49 +02:00
|
|
|
return (bool) Registry::getConfig()->getConfigParam(self::GENERAL_DEBUG);
|
2022-07-01 11:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-14 09:38:59 +02:00
|
|
|
* @return string|null
|
2022-07-01 11:48:44 +02:00
|
|
|
*/
|
2022-07-14 09:38:59 +02:00
|
|
|
public function getSmsSenderNumber()
|
2022-07-01 11:48:44 +02:00
|
|
|
{
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string $number */
|
|
|
|
$number = Registry::getConfig()->getConfigParam(self::SMS_SENDERNR);
|
|
|
|
$number = trim($number);
|
2022-07-01 11:48:44 +02:00
|
|
|
|
2022-07-14 09:38:59 +02:00
|
|
|
return strlen($number) ? $number : null;
|
2022-07-01 11:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-14 09:38:59 +02:00
|
|
|
* @return string|null
|
2022-07-01 11:48:44 +02:00
|
|
|
*/
|
2022-07-27 09:27:59 +02:00
|
|
|
public function getSmsSenderCountry(): ?string
|
2022-07-01 11:48:44 +02:00
|
|
|
{
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string $country */
|
|
|
|
$country = Registry::getConfig()->getConfigParam(self::SMS_SENDERCOUNTRY);
|
|
|
|
$country = trim($country);
|
2022-07-14 09:38:59 +02:00
|
|
|
$country = strlen($country) ? strtoupper($country) : null;
|
2022-07-01 11:48:44 +02:00
|
|
|
|
2022-07-14 16:04:26 +02:00
|
|
|
Assert::that($country)->nullOr()->string()->length(2);
|
2022-07-01 11:48:44 +02:00
|
|
|
|
2022-07-14 09:38:59 +02:00
|
|
|
return $country;
|
2022-07-01 11:48:44 +02:00
|
|
|
}
|
2022-07-18 00:27:49 +02:00
|
|
|
|
|
|
|
/**
|
2022-07-27 09:27:59 +02:00
|
|
|
* @return string[]
|
2022-07-18 00:27:49 +02:00
|
|
|
*/
|
|
|
|
public function getOrderRecipientFields(): array
|
|
|
|
{
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string[] $customFields */
|
2022-07-18 00:27:49 +02:00
|
|
|
$customFields = Registry::getConfig()->getConfigParam(self::ORDER_RECFIELDS);
|
|
|
|
|
|
|
|
array_walk(
|
|
|
|
$customFields,
|
|
|
|
[$this, 'checkFieldExists'],
|
|
|
|
[self::ARGS_CHECKKEYS => true, self::ARGS_CHECKCLASS => Order::class]
|
|
|
|
);
|
|
|
|
$customFields = array_filter($customFields);
|
|
|
|
|
|
|
|
Assert::that($customFields)->isArray();
|
|
|
|
|
|
|
|
return $customFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-27 09:27:59 +02:00
|
|
|
* @return string[]
|
2022-07-18 00:27:49 +02:00
|
|
|
*/
|
|
|
|
public function getUserRecipientFields(): array
|
|
|
|
{
|
2022-07-27 09:27:59 +02:00
|
|
|
/** @var string[] $customFields */
|
2022-07-18 00:27:49 +02:00
|
|
|
$customFields = Registry::getConfig()->getConfigParam(self::USER_RECFIELDS);
|
|
|
|
|
|
|
|
array_walk(
|
|
|
|
$customFields,
|
|
|
|
[$this, 'checkFieldExists'],
|
|
|
|
[self::ARGS_CHECKKEYS => false, self::ARGS_CHECKCLASS => User::class]
|
|
|
|
);
|
|
|
|
$customFields = array_filter($customFields);
|
|
|
|
|
|
|
|
Assert::that($customFields)->isArray();
|
|
|
|
|
|
|
|
return $customFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-27 09:27:59 +02:00
|
|
|
* @template T
|
|
|
|
* @param string $checkPhoneFieldName
|
|
|
|
* @param string $checkCountryFieldName
|
|
|
|
* @param array{checkKeys: bool, checkClassName: class-string<T>} $args
|
2022-07-18 00:27:49 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-07-27 09:27:59 +02:00
|
|
|
protected function checkFieldExists(string &$checkPhoneFieldName, string $checkCountryFieldName, array $args): void
|
2022-07-18 00:27:49 +02:00
|
|
|
{
|
|
|
|
$checkCountryFieldName = $args[self::ARGS_CHECKKEYS] ? trim($checkCountryFieldName) : $checkCountryFieldName;
|
|
|
|
$checkPhoneFieldName = trim($checkPhoneFieldName);
|
|
|
|
$allFieldNames = oxNew($args[self::ARGS_CHECKCLASS])->getFieldNames();
|
|
|
|
|
|
|
|
array_walk($allFieldNames, function (&$value) {
|
|
|
|
$value = strtolower($value);
|
|
|
|
});
|
|
|
|
|
|
|
|
$checkPhoneFieldName = in_array(strtolower($checkPhoneFieldName), $allFieldNames) && (
|
|
|
|
false === $args[self::ARGS_CHECKKEYS] ||
|
|
|
|
in_array(strtolower($checkCountryFieldName), $allFieldNames)
|
|
|
|
) ? $checkPhoneFieldName : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function sendOrderFinishedMessage(): bool
|
|
|
|
{
|
|
|
|
return (bool) Registry::getConfig()->getConfigParam(self::SENDBY_ORDERED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function sendOrderSendedNowMessage(): bool
|
|
|
|
{
|
|
|
|
return (bool) Registry::getConfig()->getConfigParam(self::SENDBY_SENDEDNOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function sendOrderCanceledMessage(): bool
|
|
|
|
{
|
|
|
|
return (bool) Registry::getConfig()->getConfigParam(self::SENDBY_CANCELED);
|
|
|
|
}
|
2022-07-13 13:23:48 +02:00
|
|
|
}
|