feat(main): Make FAQ and slide entities translatable

This commit is contained in:
2026-09-09 13:17:58 +02:00
parent 7cafc376b7
commit 4e7333493a
11 changed files with 358 additions and 62 deletions
+45 -11
View File
@@ -41,15 +41,16 @@ class CustomHtmlSlide extends ObjectModel
public $date_upd;
public static $definition = [
'table' => 'ws_customhtml_slide',
'primary' => 'id_ws_customhtml_slide',
'fields' => [
'table' => 'ws_customhtml_slide',
'primary' => 'id_ws_customhtml_slide',
'multilang' => true,
'fields' => [
'id_ws_customhtml' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 256],
'description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024],
'extra_description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024],
'link' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 512],
'link_text' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128],
'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 256, 'lang' => true],
'description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024, 'lang' => true],
'extra_description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024, 'lang' => true],
'link' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 512, 'lang' => true],
'link_text' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128, 'lang' => true],
'image' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 255],
'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
@@ -57,15 +58,48 @@ class CustomHtmlSlide extends ObjectModel
],
];
/**
* Admin use — loads every language into lang fields as [id_lang => value] arrays.
*/
public static function getByBlockId(int $idBlock): array
{
$result = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml_slide`, `title`, `description`, `extra_description`, `link`, `link_text`, `image`, `ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide`
$ids = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml_slide` FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide`
WHERE `id_ws_customhtml` = ' . (int) $idBlock . '
ORDER BY `ordering` ASC'
);
return array_map(static function (array $row) {
$slide = new self((int) $row['id_ws_customhtml_slide']);
return [
'id_ws_customhtml_slide' => (int) $slide->id,
'title' => $slide->title,
'description' => $slide->description,
'extra_description' => $slide->extra_description,
'link' => $slide->link,
'link_text' => $slide->link_text,
'image' => $slide->image,
'ordering' => (int) $slide->ordering,
];
}, $ids ?: []);
}
/**
* Front-end use — resolves lang fields to plain strings for one language.
*/
public static function getByBlockIdForLang(int $idBlock, int $idLang): array
{
$result = Db::getInstance()->executeS(
'SELECT wcs.`id_ws_customhtml_slide`, wcsl.`title`, wcsl.`description`, wcsl.`extra_description`,
wcsl.`link`, wcsl.`link_text`, wcs.`image`, wcs.`ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide` wcs
LEFT JOIN `' . _DB_PREFIX_ . 'ws_customhtml_slide_lang` wcsl
ON wcsl.`id_ws_customhtml_slide` = wcs.`id_ws_customhtml_slide` AND wcsl.`id_lang` = ' . (int) $idLang . '
WHERE wcs.`id_ws_customhtml` = ' . (int) $idBlock . '
ORDER BY wcs.`ordering` ASC'
);
return $result ?: [];
}