first commit
This commit is contained in:
86
admin/templates.php
Normal file
86
admin/templates.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
use KupShop\ContentBundle\Util\BlocksTrait;
|
||||
use KupShop\I18nBundle\Translations\TemplatesTranslation;
|
||||
|
||||
$main_class = 'Templates';
|
||||
|
||||
class Templates extends Window
|
||||
{
|
||||
use BlocksTrait;
|
||||
|
||||
public function get_vars()
|
||||
{
|
||||
$vars = parent::get_vars();
|
||||
|
||||
$vars['categories'] = array_map(function ($x) {
|
||||
return $x['name'];
|
||||
}, sqlFetchAll(sqlQuery('SELECT * FROM '.getTableName('templates_categories')), 'id'));
|
||||
|
||||
if (!empty($vars['body']['data']['id'])) {
|
||||
$useCount = sqlQueryBuilder()
|
||||
->select('COUNT(id_template) as uses')
|
||||
->from('templates_products')
|
||||
->where(\Query\Operator::equals(['id_template' => $vars['body']['data']['id']]))
|
||||
->execute()->fetch();
|
||||
} else {
|
||||
$useCount = false;
|
||||
}
|
||||
|
||||
$vars['body']['data']['uses'] = 0;
|
||||
if ($useCount) {
|
||||
$vars['body']['data']['uses'] = $useCount['uses'];
|
||||
}
|
||||
|
||||
if (isset($vars['body']['data']['id_block'])) {
|
||||
$vars['body']['data']['blocks'] = $this->getBlocks($vars['body']['data']['id_block']);
|
||||
}
|
||||
|
||||
if ($translationUtil = $this->getTranslationUtil()) {
|
||||
$vars['body']['data']['translation_figure'] = $translationUtil->getTranslationsFigure(TemplatesTranslation::class, $this->getID());
|
||||
}
|
||||
|
||||
$this->unserializeCustomData($vars['body']['data']);
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
$data = parent::getData();
|
||||
|
||||
if (getVal('Submit')) {
|
||||
$this->serializeCustomData($data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function handleUpdate()
|
||||
{
|
||||
$data = $this->getData();
|
||||
|
||||
$SQL = parent::handleUpdate();
|
||||
|
||||
if (($translationUtil = $this->getTranslationUtil()) && !empty($data['translation_figure'])) {
|
||||
$translationUtil->updateTranslationsFigure(TemplatesTranslation::class, $this->getID(), $data['translation_figure']);
|
||||
}
|
||||
|
||||
$ID = $this->getID();
|
||||
|
||||
if ($SQL) {
|
||||
$this->saveBlocks($data, $ID, 'templates');
|
||||
// $this->updateBlocksPhotosPositions($ID, 'templates', 'id_block', 'photos_blocks_relation');
|
||||
}
|
||||
|
||||
return $SQL;
|
||||
}
|
||||
|
||||
public function handleDelete()
|
||||
{
|
||||
$data = $this->getObject();
|
||||
$this->removeBlocks($data['id_block']);
|
||||
|
||||
return parent::handleDelete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user