diff --git a/controllers/admin/AdminEverBlockPageController.php b/controllers/admin/AdminEverBlockPageController.php index 764e684..a7c42ca 100644 --- a/controllers/admin/AdminEverBlockPageController.php +++ b/controllers/admin/AdminEverBlockPageController.php @@ -256,6 +256,8 @@ public function renderForm() $coverImage = _PS_IMG_ . 'pages/' . $obj->cover_image; } + $employeeChoices = $this->getEmployeeChoices(); + $this->fields_form = [ 'legend' => [ 'title' => $this->l('Page'), @@ -299,6 +301,18 @@ public function renderForm() 'name' => 'meta_description', 'lang' => true, ], + [ + 'type' => 'select', + 'label' => $this->l('Author'), + 'name' => 'id_employee', + 'required' => false, + 'options' => [ + 'query' => $employeeChoices, + 'id' => 'id_employee', + 'name' => 'name', + ], + 'desc' => $this->l('Select a PrestaShop employee to display as the guide author.'), + ], [ 'type' => 'textarea', 'label' => $this->l('Short description'), @@ -361,6 +375,8 @@ public function postProcess() if (Tools::isSubmit('submitAdd' . $this->table) || Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) { $page = new EverblockPage((int) Tools::getValue($this->identifier)); $page->id_shop = (int) $this->context->shop->id; + $authorId = (int) Tools::getValue('id_employee'); + $page->id_employee = $authorId > 0 ? $authorId : null; $page->active = (int) Tools::getValue('active'); $page->groups = json_encode($this->getSelectedGroups()); $positionInput = Tools::getValue('position'); @@ -423,6 +439,26 @@ protected function getSelectedGroups(): array return array_values(array_unique(array_map('intval', $groups))); } + protected function getEmployeeChoices(): array + { + $choices = [ + [ + 'id_employee' => 0, + 'name' => $this->l('No author'), + ], + ]; + + $employees = Employee::getEmployees((int) $this->context->language->id, true); + foreach ($employees as $employee) { + $choices[] = [ + 'id_employee' => (int) $employee['id_employee'], + 'name' => trim($employee['firstname'] . ' ' . $employee['lastname']), + ]; + } + + return $choices; + } + protected function handleImageUpload() { if (!isset($_FILES['cover_image']) || empty($_FILES['cover_image']['tmp_name'])) { diff --git a/controllers/front/page.php b/controllers/front/page.php index ef6d4e9..7d12706 100644 --- a/controllers/front/page.php +++ b/controllers/front/page.php @@ -86,6 +86,17 @@ public function initContent() ); } + $authorData = null; + if (!empty($page->id_employee)) { + $employee = new Employee((int) $page->id_employee); + if (Validate::isLoadedObject($employee)) { + $authorData = [ + 'name' => trim($employee->firstname . ' ' . $employee->lastname), + 'email' => (string) $employee->email, + ]; + } + } + $this->everblockPage = $page; $this->context->smarty->assign([ @@ -94,6 +105,7 @@ public function initContent() 'everblock_page_image' => $page->cover_image ? $this->context->link->getMediaLink(_PS_IMG_ . 'pages/' . $page->cover_image) : '', + 'everblock_page_author' => $authorData, 'everblock_structured_data' => $this->buildItemListStructuredData($pages, $pageLinks), 'everblock_prettyblocks_enabled' => $isPrettyBlocksEnabled, 'everblock_prettyblocks_zone_name' => $isPrettyBlocksEnabled ? 'everblock_page_zone_' . (int) $page->id : '', diff --git a/models/EverblockPage.php b/models/EverblockPage.php index a290e72..4f78b26 100644 --- a/models/EverblockPage.php +++ b/models/EverblockPage.php @@ -28,6 +28,7 @@ class EverblockPage extends ObjectModel { public $id_everblock_page; public $id_shop; + public $id_employee; public $groups; public $active; public $cover_image; @@ -53,6 +54,12 @@ class EverblockPage extends ObjectModel 'validate' => 'isUnsignedInt', 'required' => true, ], + 'id_employee' => [ + 'type' => self::TYPE_INT, + 'lang' => false, + 'validate' => 'isUnsignedInt', + 'required' => false, + ], 'groups' => [ 'type' => self::TYPE_STRING, 'lang' => false, diff --git a/sql/install.php b/sql/install.php index 0951a0e..6242970 100644 --- a/sql/install.php +++ b/sql/install.php @@ -178,6 +178,7 @@ $sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'everblock_page` ( `id_everblock_page` int(10) unsigned NOT NULL auto_increment, `id_shop` int(10) unsigned NOT NULL DEFAULT 1, + `id_employee` int(10) unsigned DEFAULT NULL, `groups` text DEFAULT NULL, `cover_image` varchar(255) DEFAULT NULL, `active` int(10) unsigned NOT NULL DEFAULT 1, diff --git a/src/Service/EverblockTools.php b/src/Service/EverblockTools.php index eff42c9..2d3ed26 100644 --- a/src/Service/EverblockTools.php +++ b/src/Service/EverblockTools.php @@ -4584,6 +4584,7 @@ public static function generateLoremIpsum(string $txt, Context $context): string public static function checkAndFixDatabase() { $db = Db::getInstance(_PS_USE_SQL_SLAVE_); + $dbMaster = Db::getInstance(); $tableNames = [ _DB_PREFIX_ . 'everblock', _DB_PREFIX_ . 'everblock_lang', @@ -4816,9 +4817,15 @@ public static function checkAndFixDatabase() $columnsToAdd, 'Unable to update Ever Block game play database' ); + $pageTable = _DB_PREFIX_ . 'everblock_page'; + $columnExists = $dbMaster->executeS('SHOW COLUMNS FROM `' . $pageTable . '` LIKE "id_employee"'); + if (!$columnExists) { + $dbMaster->execute('ALTER TABLE `' . $pageTable . '` ADD `id_employee` int(10) unsigned DEFAULT NULL AFTER `id_shop`'); + } // Ajoute les colonnes manquantes à la table everblock_page $columnsToAdd = [ 'id_shop' => 'int(10) unsigned NOT NULL DEFAULT 1', + 'id_employee' => 'int(10) unsigned DEFAULT NULL', 'groups' => 'text DEFAULT NULL', 'cover_image' => 'varchar(255) DEFAULT NULL', 'active' => 'int(10) unsigned NOT NULL DEFAULT 1', diff --git a/views/templates/front/page.tpl b/views/templates/front/page.tpl index 393d347..2123609 100644 --- a/views/templates/front/page.tpl +++ b/views/templates/front/page.tpl @@ -24,6 +24,14 @@
{$everblock_page_content nofilter}
+ {if !empty($everblock_page_author)} + + {/if} {if $everblock_prettyblocks_enabled}