Files
kupshop/bundles/External/ZNZBundle/Overrides/Translation/BlocksTranslation.php
2025-08-02 16:30:27 +02:00

75 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace External\ZNZBundle\Overrides\Translation;
use External\ZNZBundle\Util\ZNZBlockUpdater;
use Query\Operator;
use Symfony\Contracts\Service\Attribute\Required;
class BlocksTranslation extends \KupShop\I18nBundle\Translations\BlocksTranslation
{
#[Required]
public ZNZBlockUpdater $blockUpdater;
public function saveSingleObject(string $languageID, $objectID, array $values, ?string $sourceLanguageID = null): bool
{
$result = parent::saveSingleObject($languageID, $objectID, $values, $sourceLanguageID);
if ($objectInfo = $this->getBlockObjectInfo($objectID)) {
try {
$this->blockUpdater->update(
$objectInfo['type'],
$objectInfo['id'],
[$languageID]
);
} catch (\Throwable $e) {
if (isLocalDevelopment()) {
throw $e;
}
}
}
return $result;
}
private function getBlockObjectInfo(int $blockId): ?array
{
// najdu si ID root blocku
$rootId = sqlQueryBuilder()
->select('id_root')
->from('blocks')
->where(Operator::equals(['id' => $blockId]))
->execute()->fetchOne();
if (!$rootId) {
return null;
}
$unions = [];
foreach (ZNZBlockUpdater::TYPES as $type) {
$unions[] = sqlQueryBuilder()
->select('id, id_block, "'.$type.'" as type')
->from($type);
}
// ted potrebuju najit objekt, u ktereho je root block prirazen
$data = sqlQueryBuilder()
->select('*')
->from(Operator::union($unions), 't')
->where(Operator::equals(['t.id_block' => $rootId]))
->execute()->fetchAllAssociative();
$data = reset($data);
if (!$data) {
return null;
}
return [
'id' => (int) $data['id'],
'type' => $data['type'],
];
}
}