<?php

/**
 * This file is part of contao-weinanlieferung-bundle.
 *
 * (c) vonRotenberg
 *
 * @license commercial
 */

use Contao\DC_Table;
use Contao\DataContainer;
use Contao\Config;

$GLOBALS['TL_DCA']['tl_vr_wa_reservation'] = array
(

    // Config
    'config' => array
    (
        'dataContainer'    => DC_Table::class,
//        'doNotCopyRecords' => true,
//        'doNotDeleteRecords' => true,
        'backlink'         => 'do=weinanlieferung',
        'enableVersioning' => true,
        'sql'              => array
        (
            'keys' => array
            (
                'id' => 'primary',
                'pid' => 'index'
            )
        )
    ),

    // List
    'list' => array
    (
        'sorting' => array
        (
            'mode' => DataContainer::MODE_SORTED,
            'fields' => array('pid'/*,'(SELECT s.time FROM tl_vr_wa_slot s WHERE s.id = tl_vr_wa_reservation.pid) ASC'*/),
            //            'disableGrouping' => true,
            'panelLayout' => 'filter;sort,limit',
        ),
        'label' => array(
            'fields'                  => array('pid','behaelter','uid'),
            'format'                  => '%s',
            'showColumns'             => true,
        ),
        'global_operations' => array
        (
            'all' => array
            (
                'href'                => 'act=select',
                'class'               => 'header_edit_all',
                'attributes'          => 'onclick="Backend.getScrollOffset()" accesskey="e"'
            )
        ),
        'operations' => array
        (
            'edit' => array
            (
                'href'                => 'act=edit',
                'icon'                => 'edit.gif',
            ),
            'copy' => array
            (
                'href'                => 'act=paste&amp;mode=copy',
                'icon'                => 'copy.svg'
            ),
            'cut' => array
            (
                'href'                => 'act=paste&amp;mode=cut',
                'icon'                => 'cut.svg',
                'attributes'          => 'onclick="Backend.getScrollOffset()"'
            ),
            'delete' => array
            (
                'href'                => 'act=delete',
                'icon'                => 'delete.gif',
            ),
            'toggle' => array
            (
                'href'                => 'act=toggle&amp;field=buchbar',
                'icon'                => 'visible.svg',
                'showInHeader'        => true
            ),
            'show' => array
            (
                'icon'                => 'show.gif',
            ),
        )
    ),

    // Palettes
    'palettes' => array
    (
        '__selector__' => array(),
        'default' => 'pid,behaelter,upload,uid,sorten'
    ),

    // Subpalettes
    'subpalettes' => array
    (
    ),

    // Fields
    'fields' => array
    (
        'id'          => array
        (
            'sql' => "int(10) unsigned NOT NULL auto_increment"
        ),
        'pid'         => array
        (
            'inputType' => 'select',
            'foreignKey' => 'tl_vr_wa_slot.time',
            'eval'       => array('mandatory'=>true,'chosen'=>true,'includeBlankOption'=>true),
            'sql'        => "int(10) unsigned NOT NULL default '0'",
            'relation'   => array('type' => 'belongsTo', 'load' => 'lazy')
        ),
        'tstamp'      => array
        (
            'sql' => "int(10) unsigned NOT NULL default '0'"
        ),
        'uid'         => array
        (
            'inputType' => 'select',
            'foreignKey' => 'tl_member.username',
            'eval'       => array('mandatory'=>true,'chosen'=>true,'includeBlankOption'=>true),
            'sql'        => "int(10) unsigned NOT NULL default '0'",
            'relation'   => array('type' => 'belongsTo', 'load' => 'lazy')
        ),
        'behaelter'         => array
        (
            'inputType'               => 'text',
            'eval'       => array('rgxp'=>'natural'),
            'sql'        => "smallint(3) unsigned NOT NULL default 0",
        ),
        'sorten'       => array
        (
            'inputType'               => 'checkbox',
            'eval'  => array('multiple'=>true, 'csv'=>';'),
            'sql'       => "blob NULL",
        ),
        'upload' => array
        (
            'exclude'                 => true,
            'inputType'               => 'fileTree',
            'eval'                    => array('filesOnly'=>true, 'fieldType'=>'radio', 'tl_class'=>'clr', 'extensions'=>Config::get('allowedDownload')),
            'sql'                     => "binary(16) NULL"
        ),
        'filename' => array
        (
            'exclude'                 => true,
            'inputType'               => 'text',
            'eval'                    => array
            (
                'maxlength' => 255,
                'decodeEntities'=>true
            ),
            'sql'                     => "varchar(255) BINARY NOT NULL default ''"
        ),
    )
);