Files
2025-08-02 16:30:27 +02:00

85 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace External\HannahBundle\Admin\Tabs;
use External\HannahBundle\SAP\Synchronizer\UserSynchronizer;
use External\HannahBundle\SAP\Util\SAPUtil;
use KupShop\AdminBundle\Admin\WindowTab;
use Query\Operator;
class UsersOCTab extends WindowTab
{
protected $title = 'flapUsersOC';
protected $template = 'window/users.oc.tpl';
/** @required */
public SAPUtil $SAPUtil;
public static function getTypes()
{
return [
'users' => 0,
];
}
public function getVars($smarty_tpl_vars)
{
if (!$this->getID()) {
return [];
}
$userSapId = sqlQueryBuilder()
->select('id_sap')
->from('sap_users')
->where(Operator::equals(['id_user' => $this->getID()]))
->execute()->fetchOne() ?: null;
$user = \User::createFromId($this->getID());
$sap = $user->getCustomData()['sap'] ?? [];
$sapCards = $sap['cards'] ?? [];
return [
'sapId' => $userSapId,
'sap' => $sap,
'sapCards' => !is_array($sapCards) ? [] : $sapCards,
];
}
public function handleUpdate()
{
if (!$this->getID()) {
return;
}
$data = $this->getData();
if ($this->getAction() === 'add' && !empty($data['sap_id'])) {
try {
$this->SAPUtil->createMapping(
UserSynchronizer::getType(),
$data['sap_id'],
(int) $this->getID()
);
} catch (\Throwable $e) {
}
}
$cards = array_map(fn ($x) => trim($x), explode(',', $data['sap_cards'] ?? ''));
if ($user = \User::createFromId($this->getID())) {
$sapData = $user->getCustomData()['sap'] ?? [];
$sapData['cards'] = $cards;
$user->setCustomData('sap', $sapData);
}
}
public function getLabel()
{
return 'OC';
}
}