Code:
<?php
// contao/dca/tl_tasting_details.php
use Contao\Database;
use Contao\Input;
$GLOBALS['TL_DCA']['tl_tasting_details'] = [
'config' => [
'dataContainer' => 'Table',
'ptable' => 'tl_tasting',
'sql' => [
'keys' => [
'id' => 'primary'
],
],
'onload_callback' => [
function () {
$db = \Contao\Database::getInstance();
$pid = \Contao\Input::get('pid');
$result = $db->prepare('SELECT `tasting_date` FROM `tl_tasting` WHERE `id` = ?')
->execute([$pid]);
//$prefix = strtoupper(substr($result->name, 0, 2));
//$GLOBALS['TL_DCA']['tl_parts']['fields']['number']['default'] = $prefix;
},
]
],
'list' => [
'sorting' => [
'mode' => 4,
'fields' => ['sorting','tasting_bottle_name'],
'headerFields' => ['tasting_bottle_name'],
'panelLayout' => 'search,limit',
'disableGrouping' => true,
'child_record_callback' => ['tl_tasting_details', 'getTastingBottles'],
],
'operations' => [
'editheader' => [
'href' => 'act=edit',
'icon' => 'header.svg',
],
'delete' => [
'href' => 'act=delete',
'icon' => 'delete.svg',
],
'show' => [
'href' => 'act=show',
'icon' => 'show.svg'
],
],
],
'fields' => [
'id' => [
'sql' => ['type' => 'integer', 'unsigned' => true, 'autoincrement' => true],
],
'pid' => [
'foreignKey' => 'tl_tasting.tasting_date',
'sql' => ['type' => 'integer', 'unsigned' => true, 'default' => 0],
'relation' => ['type'=>'belongsTo', 'load'=>'lazy']
],
'sorting' => [
'sql' => "int(10) unsigned NOT NULL default 0"
],
'tstamp' => [
'sql' => ['type' => 'integer', 'unsigned' => true, 'default' => 0]
],
'tasting_bottle_name' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_bottle_name'],
'inputType' => 'select',
//'options' => $GLOBALS['TL_LANG'][$table]['tl_tasting_bottle']['bottle_name'],
'foreignKey' => 'tl_tasting_bottle.id',
'search' => true,
'options_callback' => ['tl_tasting_details', 'getBottles'],
'eval' => ['includeBlankOption'=>true, 'tl_class'=>'w50'],
'sql' => "varchar(255) NOT NULL default ''"
],
'tasting_bottle_name_extra' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_bottle_name_extra'],
'inputType' => 'text',
'eval' => ['tl_class' => 'w50', 'maxlength' => 255],
'load_callback' => ['tl_tasting_details', 'TestFc'],
'save_callback' => ['tl_tasting_details', 'returnNull'],
'eval' => ['doNotSaveEmpty'=>true, 'tl_class'=>'w50', 'readonly' => true],
],
'tasting_bottle_result' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_bottle_result'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
// Color
'tasting_bottle_color' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_bottle_color'],
'inputType' => 'text',
'eval' => ['tl_class' => 'w50', 'maxlength' => 2, 'rgxp' => 'natural'],
'sql' => ['type' => 'string', 'length' => 2, 'default' => '']
],
// Tasting Nose
'tasting_nose_smoke' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_smoke'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_nose_fruit' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_fruit'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_nose_floral' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_floral'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_nose_salt' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_salt'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_nose_strong' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_strong'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_nose_spicy' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_spicy'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_nose_woody' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_woody'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_nose_medicinal' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_medicinal'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_nose_malty' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_malty'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_nose_notes' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_nose_notes'],
'inputType' => 'text',
'eval' => ['tl_class' => 'w50', 'maxlength' => 255],
'sql' => ['type' => 'string', 'length' => 255, 'default' => '']
],
//Tasting Taste
'tasting_taste_smoke' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_smoke'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_taste_fruit' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_fruit'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_taste_floral' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_floral'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_taste_salt' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_salt'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_taste_strong' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_strong'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_taste_spicy' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_spicy'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_taste_woody' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_woody'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_taste_medicinal' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_medicinal'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_taste_malty' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_malty'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_taste_notes' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_taste_notes'],
'inputType' => 'text',
'eval' => ['tl_class' => 'w50', 'maxlength' => 255],
'sql' => ['type' => 'string', 'length' => 255, 'default' => '']
],
// Tasting Finish
'tasting_finish_duration' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_finish_duration'],
'inputType' => 'select',
'options' => ['1', '2', '3', '4', '5'],
'eval' => ['tl_class' => 'w10', 'maxlength' => 1, 'mandatory' => false, 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 1, 'default' => '']
],
'tasting_finish_notes' => [
'label' => &$GLOBALS['TL_LANG']['tl_tasting_details']['tasting_finish_notes'],
'inputType' => 'text',
'eval' => ['tl_class' => 'w50', 'maxlength' => 255],
'sql' => ['type' => 'string', 'length' => 255, 'default' => '']
],
],
'palettes' => [
'default' => '{tl_tasting_details},tasting_bottle_name,tasting_bottle_name_extra,tasting_bottle_result;
{tasting_color}tasting_bottle_color,
{tl_tasting_nose},tasting_nose_smoke,tasting_nose_fruit,tasting_nose_floral,tasting_nose_salt,
tasting_nose_strong,tasting_nose_spicy,tasting_nose_woody,tasting_nose_medicinal,tasting_nose_malty,tasting_nose_notes;
{tl_tasting_taste},tasting_taste_smoke,tasting_taste_fruit,tasting_taste_floral,tasting_taste_salt,
tasting_taste_strong,tasting_taste_spicy,tasting_taste_woody,tasting_taste_medicinal,tasting_taste_malty,tasting_taste_notes;
{tl_tasting_finish},tasting_finish_duration,tasting_finish_notes'
],
];
class tl_tasting_details extends Backend
{
/**
* List a particular record
* @param array
* @return string
*/
public function getBottles($arrRow)
{
//return array('id1' => 'Value1', 'id2' => 'Value2');
//return $arrOptions;
$db = \Contao\Database::getInstance();
//$pid = \Contao\Input::get('pid');
$objDBResult = $db->prepare('SELECT * FROM `tl_tasting_bottle` ORDER BY bottle_name ')
->execute([$pid]);
$arrReturn = array();
while($objDBResult->next())
{
$arrReturn[$objDBResult->id] = $objDBResult->bottle_name;
}
return $arrReturn;
}
public function getTastingBottles($arrRow)
{
$db = \Contao\Database::getInstance();
//$pid = \Contao\Input::get('pid');
$objDBResult = $db->prepare('SELECT bottle_name, bottler_name FROM tl_tasting_bottle
INNER JOIN tl_tasting_details ON tl_tasting_details.tasting_bottle_name=tl_tasting_bottle.id
INNER JOIN tl_tasting_bottler on tl_tasting_bottler.id=tl_tasting_bottle.bottle_bottler
WHERE tl_tasting_bottle.id = '.$arrRow['tasting_bottle_name'])
->execute([$pid]);
while($objDBResult->next())
{
$strBottleName = $objDBResult->bottle_name;
$strBottlerName = $objDBResult->bottler_name;
}
return '<div class="tl_content_left">'.$strBottleName.' ['.$strBottlerName.']</div>';
}
public function returnNull($arrRow)
{
//return array('id1' => 'Value1', 'id2' => 'Value2');
//return $arrOptions;
return Null;
}
public function TestFc($arrRow)
{
//return array('id1' => 'Value1', 'id2' => 'Value2');
//return $arrOptions;
return 'test';
}
}
Lesezeichen