PHP-Code:
<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
$GLOBALS['TL_DCA']['tl_lb_dates'] = array(
// Config
'config' => array
(
'dataContainer' => 'Table',
'enableVersioning' => true,
'ptable' => 'tl_lb_locations',
),
// List
'list' => array
(
'sorting' => array
(
'mode' => 4,
'fields' => array('startDate'),
'headerFields' => array('title', 'slots', 'tstamp', 'published'),
'flag' => 7,
'panelLayout' => 'search,filter,sorting,limit',
'child_record_callback' => array('tl_lb_dates', 'listDates')
),
'label' => array
(
'fields' => array('title'),
'format' => '%s'
),
'global_operations' => array
(
'all' => array
(
'label' => &$GLOBALS['TL_LANG']['MSC']['all'],
'href' => 'act=select',
'class' => 'header_edit_all',
'attributes' => 'onclick="Backend.getScrollOffset();"'
)
),
'operations' => array
(
'edit' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_lb_dates']['edit'],
'href' => 'act=edit',
'icon' => 'edit.gif',
),
'delete' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_lb_dates']['delete'],
'href' => 'act=delete',
'icon' => 'delete.gif',
'attributes' => 'onclick="if (!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\')) return false; Backend.getScrollOffset();"',
)
)
),
// Palettes
'palettes' => array
(
'default' => 'title;startDate,stopDate;note;description;published'
),
// Subpalettes
'subpalettes' => array(
),
// Fields
'fields' => array
(
//Titel
'title' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_lb_dates']['title'],
'inputType' => 'text',
'search' => true,
'sorting' => true,
'eval' => array('mandatory' => true)
),
//Notizen für Backenduser (toDo List o.Ä)
'note' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_lb_dates']['note'],
'inputType' => 'textarea',
'search' => true,
'eval' => array('allowHtml' => true,'style' => 'height: 100px;','rte' => 'tinyMCE')
),
//Beschreibung
'description' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_lb_dates']['description'],
'inputType' => 'textarea',
'search' => true,
'eval' => array('allowHtml' => true,'style' => 'height: 100px;','rte' => 'tinyMCE')
),
//sichtbar
'published' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_lb_dates']['published'],
'exclude' => true,
'filter' => true,
'flag' => 1,
'inputType' => 'checkbox',
'eval' => array('doNotCopy'=>true, 'tl_class' => 'w50')
),
//Startdatum
'startDate' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_lb_dates']['startDate'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('rgxp'=>'date', 'datepicker'=>$this->getDatePickerString(), 'tl_class'=>'w50 wizard'),
'save_callback' => array(array('tl_lb_dates', 'checkDates'))
),
//Enddatum
'stopDate' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_lb_dates']['stopDate'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('rgxp'=>'date', 'datepicker'=>$this->getDatePickerString(), 'tl_class'=>'w50 wizard'),
'save_callback' => array(array('tl_lb_dates', 'checkDates'))
)
)
);
class tl_lb_dates extends Backend
{
public function checkDates()
{
$id = $dc->activeRecord->id;
$startDate = $this->Input->post('startDate');
$stopDate = $this->Input->post('stopDate');
//Enddatum kleiner als Startdatum
if($stopDate < $startDate)
{
throw new Exception($GLOBALS['TL_LANG']['ERR']['endbeforestart']);
}
else
{
$updatearray = array('startDate'=>strtotime($startDate),'stopDate'=>strtotime($stopDate));
//zurückgeben korrekter Daten
return $this->Database->prepare("UPDATE tl_lb_dates %s WHERE id=?")
->set($updatearray)
->execute($id);
}
}
public function listDates($arrRow)
{
$date = ($this->parseDate('d.m.Y',$this->startDate) == $this->parseDate('d.m.Y',$this->stopDate)) ? $this->parseDate('d.m.Y',$this->startDate) : $this->parseDate('d.m.Y',$this->startDate).' - '.$this->parseDate('d.m.Y',$this->stopDate);
$time = time();
$key = ($arrRow['published'] && ($arrRow['start'] == '' || $arrRow['start'] < $time) && ($arrRow['stop'] == '' || $arrRow['stop'] > $time)) ? 'published' : 'unpublished';
return '
<div class="cte_type ' . $key . '">'.$date.'</div>
<div class="block">'.$arrRow['title'].'</div>
';
}
}
?>
Lesezeichen