Browse Source

successfully populating shows into calendar

pull/13/head
James Tomasino 9 months ago
parent
commit
3987c26428
  1. 34
      schedule/calendar.php

34
schedule/calendar.php

@ -3,21 +3,22 @@
function check_in_range($start_date, $end_date, $checkdate) {
$start_ts = strtotime($start_date);
$end_ts = strtotime($end_date);
$user_ts = strtotime($checkdate);
return (($user_ts >= $start_ts) && ($user_ts < $end_ts));
$ch_ts = strtotime($checkdate);
return (($ch_ts >= $start_ts) && ($ch_ts < $end_ts));
}
// Create a date range between the schedule start and end dates
$begin = new DateTime($schedule[0]['start']);
$end = new DateTime(end($schedule)['start']);
$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);
?>
<table class="calendar">
<thead>
<tr>
<th></th>
<?php
// Loop over our date range to draw the headers
foreach($daterange as $date){
?>
<th>
@ -32,12 +33,14 @@ foreach($daterange as $date){
</thead>
<tbody>
<?php
$time = mktime(0, 0, 0, 1, 1); // time will count us by 30-min increments through the day
for ($i = 0; $i < 86400; $i += 1800) { // 1800 = half hour, 86400 = one day
// time will count us by 30-min increments through the day
$time = mktime(0, 0, 0, 1, 1);
// Loop over the day in 30 min increments
for ($i = 0; $i < 86400; $i += 1800) {
?>
<tr>
<?php
// Only show row if we're on a full hour block
// Only show row if we're on a full hour block. It's a rowspan 2
if ((($i / 1800) % 2) === 0 ) {
?>
<td class="hour" rowspan="2"><span><?php echo date('H', $time + $i) ?>:00</span></td>
@ -46,12 +49,23 @@ for ($i = 0; $i < 86400; $i += 1800) { // 1800 = half hour, 86400 = one day
?>
<?php
// Loop over each day of the week for this 30 min span
foreach($daterange as $date){
// merge date (changing days) and time (incrementing by 30 min) to draw calendar by row.
$merge = new DateTime($date->format('Y-m-d') .' ' .date('H:i:s', $time + $i));
?>
<td><?php echo $merge->format('Y-m-d H:i:s'); ?></td>
<?php
// We'll now use $merge to see if any shows are airing at this time
$match = false;
foreach ($schedule as $show) {
if (check_in_range($show['start'], $show['end'], $merge->format('Y-m-d H:i:s'))) {
echo "<td>" . $show['title'] . "</td>\n";
$match = true;
break;
}
}
// if no match was found, leave an empty node
if (! $match) {
echo "<td></td>\n";
}
}
?>
</tr>

Loading…
Cancel
Save