db = $db;
$this->translator = $translator;
}
/**
* @Callback(table="tl_vr_wa_slot", target="list.sorting.child_record")
*/
public function onChildRecordCallback(array $row)
{
$Slot = WeinanlieferungSlotsModel::findByPk($row['id']);
$arrSorten = [];
$Sorten = StringUtil::deserialize($Slot->sorten, true);
foreach ($Sorten as $sorte)
{
$objSorte = WeinanlieferungRebsorteModel::findByPk($sorte['sorte']);
$objLeseart = WeinanlieferungLeseartModel::findByPk($sorte['leseart']);
$arrSorten[] = ($objSorte !== null ? $objSorte->title : '') . ' ' . ($objLeseart !== null ? $objLeseart->title : '');
}
return sprintf('
Buchbar ab
%s
Buchbar bis
%s
Bottichkapazität
%s
Überkapazität
%s%% (%s Behälter)
', Date::parse(Date::getNumericDateFormat(), $row['date']), Date::parse(Date::getNumericTimeFormat(), $row['time']), Date::parse(Date::getNumericDatimFormat(), $row['buchbar_ab']), Date::parse(Date::getNumericDatimFormat(), $row['buchbar_bis']), $Slot->behaelter, $Slot->overcapacity, round($Slot->behaelter/100*$Slot->overcapacity), $row['duration'], ($row['duration'] == 1 ? $this->translator->trans('MSC.wa_duration_minute', [], 'contao_tl_vr_wa_units') : $this->translator->trans('MSC.wa_duration_minutes', [], 'contao_tl_vr_wa_units')));
}
/**
* @Callback(table="tl_vr_wa_slot", target="fields.time.save", priority=1)
*/
public function checkAndAdjustTime($varValue, DataContainer $dc)
{
/** @var SlotChecker $slotchecker */
$slotchecker = System::getContainer()->get('vonrotenberg.wa.slot_checker');
// Return if there is no active record (override all) or no start date has been set yet
if (!$dc->activeRecord || empty($dc->activeRecord->date))
{
throw new \Exception($this->translator->trans('ERR.wa_slot_nodate', [], 'contao_tl_vr_wa_slot'));
}
$start = strtotime(date('Y-m-d', $dc->activeRecord->date) . ' ' . date('H:i:s', $varValue));
$duration = \intval(Input::post('duration')) !== null ? intval(Input::post('duration')) * 60 : $dc->activeRecord->duration * 60;
if ($slotchecker->checkTimeApplicableForSite($dc->activeRecord->pid, $start, $start + $duration, 0, \intval($dc->id)))
{
throw new \Exception($this->translator->trans('ERR.wa_slot_conflict', [], 'contao_tl_vr_wa_slot'));
}
return $start;
}
/**
* @Callback(table="tl_vr_wa_slot", target="fields.duration.load")
*/
public function setDurationDefault($varValue, DataContainer $dc)
{
$Slottype = WeinanlieferungSlottypesModel::findOneBy(["pid = ?", "`default` = '1'"], [$dc->activeRecord->pid]);
if ($Slottype !== null && !$varValue)
{
$varValue = $Slottype->duration;
}
return $varValue;
}
/**
* @Callback(table="tl_vr_wa_slot", target="fields.behaelter.load")
*/
public function setContainersDefault($varValue, DataContainer $dc)
{
$Slottype = WeinanlieferungSlottypesModel::findOneBy(["pid = ?", "`default` = '1'"], [$dc->activeRecord->pid]);
if ($Slottype !== null && !$varValue)
{
$varValue = $Slottype->containers;
}
return $varValue;
}
/**
* Load callback for the attributes field
*
* @param mixed $varValue The current value
* @param DataContainer $dc The data container
* @return mixed The processed value
*/
public function loadAttributes($varValue, DataContainer $dc)
{
// Just return the value as is, it's already in the correct format (comma-separated list of attribute IDs)
return $varValue;
}
/**
* Save callback for the attributes field
*
* @param mixed $varValue The value to save
* @param DataContainer $dc The data container
* @return mixed The processed value
*/
public function saveAttributes($varValue, DataContainer $dc)
{
// Just return the value as is, it's already in the correct format (comma-separated list of attribute IDs)
return $varValue;
}
/**
* Options callback for the attributes field
* Returns a multi-dimensional array of attribute options grouped by their parent groups
*
* @param DataContainer $dc The data container
* @return array The options array
*/
public function getAttributeOptions(DataContainer $dc)
{
System::loadLanguageFile('tl_vr_wa_attribute');
// Fetch all attribute groups
$groups = WeinanlieferungAttributeGroupModel::findAll(['order' => 'title ASC']);
if ($groups === null) {
return [];
}
// Build the multi-dimensional array of options
$options = [];
foreach ($groups as $group) {
// Get the attributes for this group
$attributes = WeinanlieferungAttributeModel::findBy(['pid=?'], [$group->id], ['order' => 'title ASC']);
if ($attributes === null) {
continue;
}
// Add attributes to the options array
$groupAttributes = [];
foreach ($attributes as $attribute) {
$groupAttributes[$attribute->id] = $attribute->title;
}
// Add the group to the options array if it has attributes
if (!empty($groupAttributes)) {
$groupTitle = $group->title . ' [' . $GLOBALS['TL_LANG']['tl_vr_wa_attribute']['type_options'][$group->type] . ']';
$options[$groupTitle] = $groupAttributes;
}
}
return $options;
}
}