I've cobbled together a snippet that returns an array of disabled date ranges from another snippet to feed into a datepicker. It seems to work however it's only returning one row. Being a bit of a novice at PHP could anyone tell me where I'm going wrong and how to return all rows?
Thanks
Snippet 1 Provides the array of from and to dates booked
<?php
$template = $modx->getOption('template','');
$assetsPath = $modx->getOption('slots.assets_path', null, $modx->getOption('assets_path').'components/slots/');
$Slots =& $modx->slots;
$booking = $modx->getService('slots','Slots',$modx->getOption('slots.core_path',null,$modx->getOption('core_path').'components/slots/').'model/slots/',$scriptProperties);
if (!($booking instanceof Slots)) return '';
/* setup default properties */
$c = $modx->newQuery('Slot');
$slots = $modx->getCollection('Slot',$c);
$query = $modx->newQuery('Slot');
$forms = $modx->getCollection('Slot',$query);
$output = '';
foreach ($forms as $form) {
$slotArray = $form->toArray();
foreach($slotArray as $key => $value) {
$f = $form->get('datefrom', $value);
$l = $form->get('dateto', $value);
$days = $modx->setPlaceholders(array(
'start'=> $f,
'end'=> $l
));
}
}
return $output;
Snippet 2 Reads the from and to dates and puts them into a date range adding dates in between
<?php
function dateRange($first,$last,$step='+1 day',$format='j-n-Y'){
$dates=array();
$current=strtotime($first);
$last=strtotime($last);
while($current<=$last){
$dates[]=date($format,$current);
$current=strtotime($step,$current);
}
return $dates;
}
$output = '';
$disablerange = $modx->runsnippet('getDateRange');
$a = $modx->getPlaceholder('start');
$b = $modx->getPlaceholder('end');
$array = (dateRange($a,$b));
$output .= '[';
$dis = implode("','", $array);
$output .= "'".$dis."'";
$output .= ']';
return $output;