99 lines
2.8 KiB
PHP
99 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\AgeVerifyBundle\Utils;
|
|
|
|
use Doctrine\DBAL\Exception;
|
|
use KupShop\KupShopBundle\Context\UserContext;
|
|
use KupShop\KupShopBundle\Views\Traits\MessagesTrait;
|
|
use Query\Operator;
|
|
|
|
class AgeVerifyUtil
|
|
{
|
|
use MessagesTrait;
|
|
|
|
/** @required */
|
|
public UserContext $userContext;
|
|
|
|
public static array $VERIFICATION_TYPES = [
|
|
'bankId' => 'Bankovní identita',
|
|
'store' => 'Prodejna',
|
|
'package' => 'Balík',
|
|
'veriface' => 'Veriface',
|
|
'mojeid' => 'MojeID',
|
|
'adulto' => 'Adulto',
|
|
];
|
|
|
|
/**
|
|
* @param $legalAge string Y/N
|
|
* @param string $type bankId/store/package/veriface/adulto
|
|
* @param int|null $userId \User
|
|
*
|
|
* @return void
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function setVerificationData(string $legalAge, string $type, ?string $birthdate = null, ?int $userId = null, ?string $data = null): bool
|
|
{
|
|
if (empty($userId) && empty($userId = $this->userContext->getActiveId())) {
|
|
return false;
|
|
}
|
|
|
|
if (!empty($birthdate)) {
|
|
sqlQueryBuilder()->update('users')
|
|
->directValues([
|
|
'birthdate' => $birthdate,
|
|
'figure' => 'Y',
|
|
])
|
|
->where(Operator::equals(['id' => $userId]))
|
|
->execute();
|
|
}
|
|
|
|
sqlQueryBuilder()->insert('users_age_verification')
|
|
->directValues([
|
|
'id_user' => $userId,
|
|
'legal_age' => $legalAge,
|
|
'verification_type' => $type,
|
|
'data' => $data,
|
|
])
|
|
->onDuplicateKeyUpdate([
|
|
'id_user',
|
|
'legal_age',
|
|
'verification_type',
|
|
'data',
|
|
])
|
|
->execute();
|
|
|
|
if (!isAdministration()) {
|
|
if ($legalAge == 'Y') {
|
|
$this->addSuccessMessage('Ověření plnoletosti proběhlo úspěšně.');
|
|
} else {
|
|
$this->addErrorMessage('Ověření plnoletosti se nezdařilo.'); // TODO: uživatel není plnoletý??
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function isLegalAged($userId): bool
|
|
{
|
|
if (empty($userId)) {
|
|
return false;
|
|
}
|
|
|
|
$data = sqlQueryBuilder()->select('legal_age')->from('users_age_verification')
|
|
->where(Operator::equals(['id_user' => $userId]))->execute()->fetchOne();
|
|
|
|
return $data == 'Y';
|
|
}
|
|
|
|
public function getVerificationData($userId)
|
|
{
|
|
return sqlQueryBuilder()->select('legal_age, verification_type, id_order')
|
|
->from('users_age_verification')
|
|
->where(Operator::equals(['id_user' => $userId]))
|
|
->execute()->fetchAllAssociative()[0] ?? [];
|
|
}
|
|
}
|