Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions controllers/admin/AdminEverBlockPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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'])) {
Expand Down
12 changes: 12 additions & 0 deletions controllers/front/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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 : '',
Expand Down
7 changes: 7 additions & 0 deletions models/EverblockPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions sql/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/Service/EverblockTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions views/templates/front/page.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
<div class="everblock-page__content rte" itemprop="articleBody">
{$everblock_page_content nofilter}
</div>
{if !empty($everblock_page_author)}
<footer class="everblock-page__footer mt-4">
<p class="everblock-page__author small text-muted mb-0" itemprop="author" itemscope itemtype="https://schema.org/Person">
<span class="everblock-page__author-label">{l s='Author' mod='everblock' d='Modules.Everblock.Front'}:</span>
<span itemprop="name">{$everblock_page_author.name|escape:'htmlall':'UTF-8'}</span>
</p>
</footer>
{/if}
</article>

{if $everblock_prettyblocks_enabled}
Expand Down
Loading