feat(main): Groups and blocks

This commit is contained in:
2026-08-10 16:13:15 +02:00
parent 6aff506cd6
commit 635c13a0ed
39 changed files with 1188 additions and 237 deletions
+76
View File
@@ -0,0 +1,76 @@
<?php
namespace Websmid\CustomHtml\Model;
use ObjectModel;
use Db;
class CustomHtmlBlock extends ObjectModel
{
/** @var int */
public $id;
/** @var int */
public $id_ws_customhtml_group;
/** @var string */
public $title = '';
/** @var string */
public $content = '';
/** @var int */
public $active = 1;
/** @var int */
public $show_title = 0;
/** @var int */
public $ordering = 0;
/** @var string */
public $date_add;
/** @var string */
public $date_upd;
public static $definition = [
'table' => 'ws_customhtml',
'primary' => 'id_ws_customhtml',
'fields' => [
'id_ws_customhtml_group' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 256],
'content' => ['type' => self::TYPE_HTML, 'validate' => 'isCleanHtml'],
'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
'show_title' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
],
];
public static function getActiveByGroupIds(array $groupIds): array
{
$groupIds = array_map('intval', $groupIds);
if (empty($groupIds)) {
return [];
}
$result = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml`, `id_ws_customhtml_group`, `title`, `content`, `active`, `show_title`, `ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml`
WHERE `id_ws_customhtml_group` IN (' . implode(',', $groupIds) . ')
AND `active` = 1
ORDER BY `ordering` ASC'
);
$blocksByGroup = [];
foreach ($result as $row) {
$blocksByGroup[(int) $row['id_ws_customhtml_group']][] = $row;
}
return $blocksByGroup;
}
}
@@ -5,7 +5,7 @@ namespace Websmid\CustomHtml\Model;
use ObjectModel;
use Db;
class CustomHtml extends ObjectModel
class CustomHtmlGroup extends ObjectModel
{
/** @var int */
public $id;
@@ -16,15 +16,9 @@ class CustomHtml extends ObjectModel
/** @var string */
public $title = '';
/** @var string */
public $content = '';
/** @var int */
public $active = 1;
/** @var int */
public $show_title = 0;
/** @var int */
public $ordering = 0;
@@ -35,25 +29,23 @@ class CustomHtml extends ObjectModel
public $date_upd;
public static $definition = [
'table' => 'ws_customhtml',
'primary' => 'id_ws_customhtml',
'table' => 'ws_customhtml_group',
'primary' => 'id_ws_customhtml_group',
'fields' => [
'hook_name' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64],
'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 256],
'content' => ['type' => self::TYPE_HTML, 'validate' => 'isCleanHtml'],
'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
'show_title' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
],
];
public static function getActiveByHookName(string $hookName): array
{
$result = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml`, `title`, `content`, `active`, `show_title`, `ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml`
'SELECT `id_ws_customhtml_group`, `title`, `active`, `ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_group`
WHERE `hook_name` = \'' . pSQL($hookName) . '\'
AND `active` = 1
ORDER BY `ordering` ASC'