Last active
August 29, 2015 14:09
-
-
Save davit/61711ef3b2b2d2bf22c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$has_event_class = 'has-event-false'; | |
$events = array( | |
0 => array( | |
'city' => 'Tbilisi', | |
'start_date' => '2014-11-18 09:00', | |
'end_date' => '2014-11-18 12:00', | |
'name' => 'Meeting with Jesus' | |
), | |
1 => array( | |
'city' => 'Tbilisi', | |
'start_date' => '2014-11-18 17:00', | |
'end_date' => '2014-11-18 18:00', | |
'name' => 'Meeting with Budda' | |
), | |
2 => array( | |
'city' => 'Tbilisi', | |
'start_date' => '2014-11-19 13:00', | |
'end_date' => '2014-11-19 16:00', | |
'name' => 'Meeting with Apollo' | |
), | |
3 => array( | |
'city' => 'Batumi', | |
'start_date' => '2014-11-20 13:00', | |
'end_date' => '2014-11-20 18:00', | |
'name' => 'Meeting with Krishna' | |
), | |
4 => array( | |
'city' => 'Batumi', | |
'start_date' => '2014-11-21 15:00', | |
'end_date' => '2014-11-21 18:00', | |
'name' => 'Meeting with Zeus' | |
), | |
); | |
?> | |
<div class="table-responsive"> | |
<table class="table"> | |
<tr> | |
<?php | |
if (1 == date('N')) { // N - Now | |
$monday = time(); | |
} else { | |
$monday = strtotime('last Monday'); | |
} | |
?> | |
<?php foreach (range(0, 7) as $column): ?> | |
<?php if ($column == 0): ?> | |
<?php print ""; ?> | |
<th class="hours-column"></th> | |
<?php else: ?> | |
<th class="days-column"> | |
<?php print t(date('l', $monday)); | |
print " "; | |
print t(date('d/m', strtotime('+' . ($column - 1) . 'day'))); | |
$monday = strtotime('tomorrow', $monday); | |
?> | |
<?php endif; ?> | |
</th> | |
<?php endforeach; ?> | |
</tr> | |
<?php | |
//Set up the initial time - as per customer's request | |
$hour_initial = "09:00"; | |
?> | |
<?php foreach (range(0, 9) as $hour): ?> | |
<tr> | |
<?php foreach (range(0, 7) as $column): ?> | |
<?php if ($column == 0): ?> | |
<td class="hours-cell-data"> | |
<?php | |
$effectiveHour = strtotime("+" . $hour . " hours", strtotime($hour_initial)); | |
print date("H:i", $effectiveHour); | |
?> | |
</td> | |
<?php else: ?> | |
<?php | |
global $has_event_class; | |
?> | |
<td> | |
<?php foreach ($events as $event): ?> | |
<?php | |
$start_date = strtotime($event['start_date']); | |
$end_date = strtotime($event['end_date']); | |
$interval_hours = abs(round(($end_date - $start_date) / 3600, 1)); //Event interval in hours rounded | |
?> | |
<?php if ( | |
date('Y-m-d', strtotime('+' . ($column - 1) . 'day')) | |
== | |
date('Y-m-d', strtotime($event['start_date'])) | |
&& | |
(date('H:i', $start_date) == date('H:i', $effectiveHour)) | |
): ?> | |
<?php | |
$has_event_class = 'has-event-true'; | |
$row_span = $interval_hours; | |
?> | |
<span class="hours-interval-span"> <?php print (date('H:i', $start_date)); ?> | |
<?php print "-"; ?> | |
<?php print (date('H:i', $end_date)); ?> | |
</span> | |
<span class="event-name-span"> | |
<?php print $event['name']; ?> | |
</span> | |
<?php else: ?> | |
<?php $has_event_class = 'has-event-false'; ?> | |
<?php endif; ?> | |
<?php endforeach; ?> | |
</td> | |
<?php endif; ?> | |
<?php endforeach; ?> | |
</tr> | |
<?php endforeach; ?> | |
</table> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment