PHP-Code:
<?php
use Contao\DC_Table;
use Contao\Backend;
$GLOBALS['TL_DCA']['tl_products'] = array
(
// Config
'config' => array
(
'dataContainer' => 'Table',
'sql' => array
(
'keys' => array
(
'id' => 'primary'
)
),
'onsubmit_callback' => array(array('tl_products', 'onsubmit_callback'))
),
// List
'list' => array
(
'sorting' => array
(
'mode' => 1,
'flag' => 11,
'fields' => array('artno'),
'panelLayout' => 'filter;search,limit'
),
'label' => array(
'fields' => array('id', 'artno', 'titlede'),
'label_callback' => array('tl_products', 'label_callback'),
'showColumns' => true
),
'operations' => array
(
'edit' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_products']['edit'],
'href' => 'act=edit',
'icon' => 'edit.gif'
),
'copy' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_products']['copy'],
'href' => 'act=copy',
'icon' => 'copy.gif',
'button_callback' => array('tl_products', 'copyProduct')
),
'delete' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_products']['delete'],
'href' => 'act=delete',
'icon' => 'delete.gif',
'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
),
'toggle' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_products']['toggle'],
'icon' => 'visible.svg',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'button_callback' => array('tl_products', 'toggleIcon')
)
)
),
// Palettes
'palettes' => array
(
'default' => '{basicinfo_legend}, artno, titlede, titleen; {category_legend}, category; {description_legend}, shortdescriptionde, shortdescriptionen, descriptionde, descriptionen; {image_legend}, imageSRC; {datasheet_legend}, datasheet_data, dimensions, weight, shippinginfo_de, shippinginfo_en, ean, conradnr, tariffno; {download_legend}, downloadSRC, linkedDownloads; {faq_legend}, faq_data; {recommendedProducts_legend}, recommendedProducts; {youtube_legend}, youtube_de, youtube_en; {datasheetData_legend}, datasheetImageSRC'
),
// Fields
'fields' => array
(
'id' => array
(
'sql' => "int(10) unsigned NOT NULL auto_increment"
),
'tstamp' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['tstamp'],
'eval' => array('rgxp'=>'date'),
'flag' => 5,
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'published' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['published'],
'filter' => true,
'inputType' => 'checkbox',
'sql' => "char(1) NOT NULL default '0'"
),
'artno' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['artno'],
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'tl_class'=>'w50', 'doNotCopy'=>true),
'search' => true,
'sql' => "varchar(255) NOT NULL default ''"
),
'titlede' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['titlede'],
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'tl_class'=>'clr w50', 'doNotCopy'=>true),
'search' => true,
'sql' => "varchar(255) NOT NULL default ''"
),
'titleen' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['titleen'],
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'tl_class'=>'w50', 'doNotCopy'=>true),
'sql' => "varchar(255) NOT NULL default ''"
),
'category' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['category'],
'inputType' => 'multiColumnWizard',
'eval' => array(
'columnFields' => [
'data' => [
'label' => &$GLOBALS['TL_LANG']['tl_products']['category']['data'],
'inputType' => 'select',
'foreignKey'=> 'tl_categories.categoryde',
'eval' => ['includeBlankOption'=>true, 'allowHtml' => false, 'style'=>'width:100%']
]
],
'buttons' => array('copy'=>false, 'up'=>false, 'down'=>false),
'tl_class' => 'w50'
),
'sql' => "blob NULL"
),
'shortdescriptionde' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['shortdescriptionde'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>true, 'tl_class'=>'w50', 'style'=>'resize: none'),
'sql' => "varchar(255) NOT NULL default ''"
),
'shortdescriptionen' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['shortdescriptionen'],
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'tl_class'=>'w50', 'style'=>'resize: none'),
'sql' => "varchar(255) NOT NULL default ''"
),
'descriptionde' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['descriptionde'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>true, 'rte'=>'tinyMCE', 'style'=>'resize: none', 'tl_class'=>'clr'),
'sql' => "mediumtext NOT NULL default ''"
),
'descriptionen' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['descriptionen'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>true, 'rte'=>'tinyMCE', 'style'=>'resize: none', 'tl_class'=>'clr'),
'sql' => "mediumtext NOT NULL default ''"
),
'imageSRC' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['imageSRC'],
'inputType' => 'fileTree',
'eval' => array('mandatory'=>true, 'multiple'=>true, 'orderField'=>'orderImageSRC', 'files'=>true, 'filesOnly'=>true, 'isGallery'=>true, 'extensions'=>'png', 'fieldType'=>'checkbox', 'path'=>'files/files/Produkte'),
'sql' => "blob NULL"
),
'orderImageSRC' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_products']['sortOrder'],
'sql' => "blob NULL"
),
'downloadSRC' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['downloadSRC'],
'inputType' => 'fileTree',
'eval' => array('multiple'=>true, 'files'=>true, 'orderField'=>'orderDownloadSRC', 'filesOnly'=>true, 'isGallery'=>false, 'fieldType'=>'checkbox', 'path'=>'files/files/Produkte'),
'sql' => "blob NULL"
),
'orderDownloadSRC' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_products']['sortOrder'],
'sql' => "blob NULL"
),
'linkedDownloads' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['linkedDownloads'],
'inputType' => 'multiColumnWizard',
'eval' => array(
'columnFields' => [
'titlede' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['linkedDownloads']['titlede'],
'inputType' => 'text',
'mandatory' => true,
'class' => 'tl_text',
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%;'],
],
'titleen' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['linkedDownloads']['titleen'],
'inputType' => 'text',
'mandatory' => true,
'class' => 'tl_text',
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%'],
],
'data' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['linkedDownloads']['data'],
'inputType' => 'text',
'mandatory' => true,
'class' => 'tl_text',
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%;'],
]
],
'style' => 'max-width:100%;'
),
'sql' => "blob NULL"
),
'datasheet_data' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['datasheet_data'],
'inputType' => 'multiColumnWizard',
'eval' => array(
'columnFields' => [
'headline_de' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['datasheet_data']['headline_de'],
'inputType' => 'textarea',
'mandatory' => true,
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%; resize: none;'],
],
'headline_en' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['datasheet_data']['headline_en'],
'inputType' => 'textarea',
'mandatory' => true,
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%; resize: none;'],
],
'data_de' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['datasheet_data']['data_de'],
'inputType' => 'textarea',
'mandatory' => true,
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%; resize: none;'],
],
'data_en' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['datasheet_data']['data_en'],
'inputType' => 'textarea',
'mandatory' => true,
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%; resize: none;'],
]
], 'style' => 'max-width:100%'
),
'sql' => "blob NULL"
),
'dimensions' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['dimensions'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>false, 'tl_class'=>'w50', 'style'=>'resize: none'),
'sql' => "varchar(255) NOT NULL default ''"
),
'shippinginfo_de' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['shippinginfo_de'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>false, 'tl_class'=>'w50', 'style'=>'resize: none'),
'sql' => "mediumtext NOT NULL default ''"
),
'shippinginfo_en' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['shippinginfo_en'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>false, 'tl_class'=>'w50', 'style'=>'resize: none'),
'sql' => "mediumtext NOT NULL default ''"
),
'weight' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['weight'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>false, 'tl_class'=>'w50', 'style'=>'resize: none'),
'sql' => "varchar(255) NOT NULL default ''"
),
'ean' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['ean'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>false, 'tl_class'=>'w50', 'style'=>'resize: none', 'doNotCopy'=>true),
'sql' => "varchar(255) NOT NULL default ''"
),
'tariffno' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['tariffno'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>false, 'tl_class'=>'w50', 'style'=>'resize: none'),
'sql' => "varchar(255) NOT NULL default ''"
),
'conradnr' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['conradnr'],
'inputType' => 'textarea',
'eval' => array('mandatory'=>false, 'tl_class'=>'w50', 'style'=>'resize: none', 'doNotCopy'=>true),
'sql' => "varchar(255) NOT NULL default ''"
),
'faq_data' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['faq_data'],
'inputType' => 'multiColumnWizard',
'eval' => array(
'columnFields' => [
'questionde' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['faq_data']['questionde'],
'inputType' => 'textarea',
'mandatory' => true,
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%; resize: none;'],
],
'questionen' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['faq_data']['questionen'],
'inputType' => 'textarea',
'mandatory' => true,
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%; resize: none;'],
],
'answerde' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['faq_data']['answerde'],
'inputType' => 'textarea',
'mandatory' => true,
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%; resize: none;'],
],
'answeren' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['faq_data']['answeren'],
'inputType' => 'textarea',
'mandatory' => true,
'eval' => ['mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%; resize: none;'],
]
],
'style' => 'max-width:100%',
'buttons' => array('copy'=>false)
),
'sql' => "blob NULL"
),
'recommendedProducts' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['recommendedProducts'],
'inputType' => 'multiColumnWizard',
'eval' => array(
'columnFields' => [
'data' => [
'label' => $GLOBALS['TL_LANG']['tl_products']['recommendedProducts']['products'],
'inputType' => 'select',
'foreignKey' => 'tl_products.artno',
'eval' => ['includeBlankOption'=>true, 'mandatory' => false, 'allowHtml' => false, 'style' => 'width: 100%;'],
]
],
'buttons' => array('copy'=>false),
'tl_class' => 'w50'
),
'sql' => "blob NULL"
),
'youtube_de' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['youtube_de'],
'inputType' => 'text',
'eval' => array('mandatory'=>false, 'tl_class'=>'w50', 'allowHtml' => false, 'doNotCopy'=>true),
'search' => true,
'sql' => "varchar(255) NOT NULL default ''"
),
'youtube_en' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['youtube_en'],
'inputType' => 'text',
'eval' => array('mandatory'=>false, 'tl_class'=>'w50', 'allowHtml' => false, 'doNotCopy'=>true),
'search' => true,
'sql' => "varchar(255) NOT NULL default ''"
),
'datasheetImageSRC' => array
(
'label' => $GLOBALS['TL_LANG']['tl_products']['datasheetImageSRC'],
'inputType' => 'fileTree',
'eval' => array('mandatory'=>false, 'multiple'=>false, 'orderField'=>'orderdatasheetImageSRC', 'files'=>true, 'filesOnly'=>true, 'isGallery'=>true, 'extensions'=>'png', 'fieldType'=>'checkbox', 'path'=>'files/files/Produkte'),
'sql' => "blob NULL"
),
'orderdatasheetImageSRC' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_products']['sortOrderDatasheetImage'],
'sql' => "blob NULL"
),
)
);
class tl_products extends Backend
{
public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
{
$this->import('BackendUser', 'User');
if (strlen($this->Input->get('tid'))) {
$this->toggleVisibility($this->Input->get('tid'), ($this->Input->get('state') == 0));
$this->redirect($this->getReferer());
}
$href .= '&id='.$this->Input->get('id').'&tid='.$row['id'].'&state='.$row[''];
if (!$row['published']){
$icon = 'invisible.gif';
}
return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';
}
public function toggleVisibility($intId, $blnPublished)
{
$this->createInitialVersion('tl_products', $intId);
// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_products']['fields']['published']['save_callback'])) {
foreach ($GLOBALS['TL_DCA']['tl_products']['fields']['published']['save_callback'] as $callback) {
$this->import($callback[0]);
$blnPublished = $this->$callback[0]->$callback[1]($blnPublished, $this);
}
}
// Update the database
$this->Database->prepare("UPDATE tl_products SET tstamp=". time() .", published='" . ($blnPublished ? '0' : '1') . "' WHERE id=?")
->execute($intId);
$this->createNewVersion('tl_products', $intId);
// Save Log
$product = \BundleProvider\ContaoProductsBundle\Model\ProductModel::findById($intId);
$logMsg = BackendUser::getInstance()->username . " changed visibility for product " . $product->artno . " (ID: " . $product->id . ").";
\System::log($logMsg, __METHOD__, TL_GENERAL);
}
// Duplicate Product
public function copyProduct($row, $href, $label, $title, $icon, $attributes, $table)
{
if ($GLOBALS['TL_DCA'][$table]['config']['closed']) {
return '';
}
return '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.Contao\StringUtil::specialchars($title).'"'.$attributes.'>'.Contao\Image::getHtml($icon, $label).'</a> ';
}
// Label Callback
public function label_callback($row, $label, DataContainer $dc, $args)
{
// Replace Image
if($args[0]){
$product = \BundleProvider\ContaoProductsBundle\Model\ProductModel::findById($args[0]);
if($product->orderImageSRC) {
$src = \FilesModel::findByUuid(unserialize($product->orderImageSRC)[0])->path;
$smallImg = \Image::get($src, 300, null, 'proportional');
$args[0] = '<img src="' . $smallImg . '" style="max-width:100px;">';
}
}
return $args;
}
// OnSubmit Callback
public function onsubmit_callback(DataContainer $dc)
{
$logMsg = BackendUser::getInstance()->username . " updated product " . $dc->activeRecord->artno . " (ID: " . $dc->activeRecord->id . ").";
\System::log($logMsg, __METHOD__, TL_GENERAL);
}
}
Lesezeichen