Page 1 of 1

[Php] Print Calendar with Data Binding

Posted: Sun Mar 04, 2018 4:19 pm
by tthlan
#############################

Calendar Custom


<?php
$arrDay = [
0 => translate('home.cal_sun'),
1 => translate('home.cal_mon'),
2 => translate('home.cal_tue'),
3 => translate('home.cal_wed'),
4 => translate('home.cal_thu'),
5 => translate('home.cal_fri'),
6 => translate('home.cal_sat')];

$today = date("Ymd");
?>
<?php if (isset($vertical_calendar) && !empty($vertical_calendar)): ?>
<?php foreach ($vertical_calendar as $cal): ?>
<?php
/* Holiday and Sunday is Special Day */
$strClass = '';
if($today === $cal->calendar_date) {
$strClass = 'today';
} else if(intval($cal->calendar_weekday) === 6) {
$strClass = 'sat';
} else if(intval($cal->calendar_weekday) === 0) {
$strClass = 'holiday';
}
?>
<div class="cal-ver cal-width">
<div class="cal-ver-content">
<a data-ymd="<?= $cal->calendar_date; ?>" href="/link?mode=timetable&calendar_date=<?= $cal->calendar_date; ?>">
<p class="weekday <?= ($strClass); ?>">
<?php echo $arrDay[$cal->calendar_weekday]; ?>
</p>
<p class="date <?= ($strClass === 'special-day' ? $strClass: ''); ?>"><?= ($today === $cal->calendar_date ? translate('common.today') : substr($cal->calendar_date,6,2)); ?></p>
<div class="line-hr <?= ($strClass === 'special-day' ? $strClass: ''); ?>"></div>
<?php if ($cal->cnt_notable > 0 || $cal->cnt_withtable > 0): ?>
<div class="count-rsv">
<?php if ($cal->cnt_notable > 0): ?><div class="count-ad"><?= $cal->count-ad1; ?></div><?php endif; ?>
<?php if ($cal->cnt_withtable > 0): ?><div class="count-customer"><?= $cal->count-customer; ?></div><?php endif; ?>
</div>
<?php endif; ?>
</a>
</div>
</div>
<?php endforeach; ?>
<?php else:?>
<?php
for ($i = 0; $i < 7; $i++):
$datetime = strtotime("+$i days");
$date = date('d', $datetime);
$weekday = date('w', $datetime);

/* Holiday and Sunday is Special Day */
$strClass = (intval($weekday) === 6 || intval($weekday) === 0 ? 'special-day' : 'not-today');
?>
<div class="cal-ver cal-width">
<div class="cal-ver-content">
<a data-ymd="<?= date('Ymd', $datetime); ?>" href="#">
<p class="weekday <?php echo $strClass; ?>">
<?php echo $arrDay[$weekday]; ?>
</p>
<p class="date <?= ($strClass === 'special-day' ? $strClass: ''); ?>"><?= ($today === date('Ymd', $datetime) ? translate('common.today') : $date); ?></p>
<div class="line-hr <?= ($strClass === 'special-day' ? $strClass: ''); ?>"></div>
</a>
</div>
</div>
<?php endfor; ?>
<?php endif; ?>
<div class="cal-ver cal-width">
<div class="cal-ver-content" id="show-calendar">
<a href="" onclick="" id="cal-show" data-toggle="modal" data-target="#viewModalCalendar">
<p class="show-carlendar icon icon-calendar"></p>
<p class="have-rsv"></p>
</a>
</div>
</div>

###########################