Files
kupshop/bundles/External/MSSQLBundle/Util/MappingTrait.php
2025-08-02 16:30:27 +02:00

52 lines
1.4 KiB
PHP

<?php
namespace External\MSSQLBundle\Util;
trait MappingTrait
{
public function getMoneyID($objectID, $type = null)
{
return $this->selectSQL($this->getTable($type), [$this->getIDField($type) => $objectID], ['id_money'])->fetchColumn();
}
public function getMapping($moneyID, $type = null)
{
return $this->selectSQL($this->getTable($type), ['id_money' => $moneyID], [$this->getIDField($type)])->fetchColumn();
}
public function createMapping($moneyID, $objectID, $type = null)
{
// delete mappings of item if we are creating new one
$this->deleteSQL($this->getTable($type), [$this->getIDField($type) => $objectID]);
// create new mapping
$this->insertSQL($this->getTable($type), ['id_money' => $moneyID, $this->getIDField($type) => $objectID]);
}
private function getTable($type = null)
{
if (!$type) {
$type = $this->getTypeFromClassName();
}
return 'money_'.$type.'s';
}
private function getIDField($type = null)
{
if (!$type) {
$type = $this->getTypeFromClassName();
}
return 'id_'.$type;
}
private function getTypeFromClassName()
{
$type = explode('\\', get_called_class());
$type = str_replace('Synchronizer', '', $type);
$type = strtolower(end($type));
return $type;
}
}