-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpage-schedule.php
175 lines (155 loc) · 6.78 KB
/
page-schedule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* Template Name: Schedule
* The template for displaying all posts.
*/
get_header();
?>
<main class="container schedule" id="main">
<div class="row">
<div id="content" role="main">
<div id="wrapper-schedule">
<h1 class="kz-title"><?php the_title(); ?></h1>
<h2 class="schedule-content">
<?php
for ($i = 0; have_posts(); ++$i) {
the_post();
the_content();
}
?>
</h2>
<div class="schedule-wrapper">
<?php
function showTimeSpan($from, $to) {
return ($from == '23:59' ? '00:00' : $from) . '-' . ($to == '23:59' ? '00:00' : $to);
}
function fix59($timehour) {
if (round(($timehour - floor($timehour)) * 60.0) == 59.0) {
return (floor($timehour) + 1) * 100;
} else {
return round($timehour * 100);
}
}
$schedule_days_titles = array( 'יום ראשון', 'יום שני', 'יום שלישי', 'יום רביעי', 'יום חמישי', 'יום שישי', 'יום שבת' );
$currdate = new DateTime("now", new DateTimeZone("Israel") );
$currdaynum = intval($currdate->format("w"));
$currhour = intval($currdate->format("H")) + intval($currdate->format("i")) / 60.0;
// Rotate shows so day start at 5 am and shows before 5am are the prev day
$origshows = get_schedule();
$shows = array();
for ($daynum = 0; $daynum < 7; ++$daynum) {
$shows[$daynum] = $origshows[$daynum];
$shows[$daynum]['times'] = array();
}
foreach ($origshows as $daynum => $daydata) {
foreach ($daydata['times'] as $timenum => $times) {
if ($times['hide_on_schedule']) continue;
if ($times['starthour'] < 5) {
$times['starthour'] += 24;
$times['endhour'] += 24;
$shows[($daynum + 6) % 7]['times'][round($times['starthour'] * 100)] = $times;
} else {
$shows[$daynum]['times'][round($times['starthour'] * 100)] = $times;
}
}
ksort($shows[$daynum]['times']);
}
// Get change show times
$changehours = array();
foreach ($shows as $daynum => $daydata) {
foreach ($daydata['times'] as $timenum => $times) {
$changehours[fix59($times['starthour'])] = $times['start'];
$changehours[fix59($times['endhour'])] = $times['end'];
}
}
ksort($changehours);
$changehoursnums = array_keys($changehours);
?>
<div class="schedule-table clearfix">
<div class="mobile-slides">
<?php
foreach ($shows as $daynum => $daydata) {
if( $daynum == $currdaynum ) {
echo '<div class="day-column active-day">';
} else {
echo '<div class="day-column">';
}
echo '<div class="day-title">' . $schedule_days_titles[$daynum];
echo '<div class="day-title-date">';
echo date('d/m', strtotime('+'.($daynum-date('w')).' days'));
echo '</div>';
echo '</div>';
$lastend = 0;
$lasttime = reset($changehours);
foreach ($daydata["times"] as $startnum => $times) {
$startnum = array_search(fix59($times['starthour']), $changehoursnums);
$endnum = array_search(fix59($times['endhour']), $changehoursnums);
$times['len'] = $endnum - $startnum;
$times['beforelen'] = $startnum - $lastend;
$times['beforetime'] = $lasttime;
$lastend = $endnum;
$lasttime = $times['end'];
if( $times['beforelen'] > 0 ) {
echo '<div class="show-box" style="background: rgba(0,0,0,0); height: ' . $times['beforelen']*80 . 'px">';
// echo '<div class="show-hour">' . showTimeSpan($times['beforetime'], $times['start']) . '</div>';
echo '</div>';
}
$id = $daydata["day"] . '_' . $times['starthour'];
$clazz = 'show-box cat-' . $times['term'];
if ($daynum == $currdaynum && $times['starthour'] <= $currhour && $currhour <= $times['endhour']) {
$clazz .= ' active';
}
$style = 'height: ' . $times['len']*80 . 'px';
echo '<div id="' . $id . '" class="' . $clazz . '" realtime="' . $times['realtime'] . '" style="' . $style . '">';
// echo '<img src="' . $times['image'] . '">';
echo '<div class="show-hour">' . showTimeSpan($times['start'], $times['end']) . '</div>';
echo '<div class="dj-and-name">';
echo '<a href="' . $times['linkdj'] . '">' . $times['dj'] . '</a>';
echo '<a href="' . $times['linkshow'] . '"><b>' . $times['show'] . '</b></a>';
echo '</div>';
echo '</div>';
}
echo '</div>';
}
?>
</div>
</div><!--.mobile-slides-->
<div class="mobile-only controls">
<a href="#" class="arrow prev">▶</a>
<a href="#" class="arrow next">◀</a>
</div>
</div>
<script>
setTimeout(function(){
console.log('1');
if( jQuery('#wrapper-schedule .schedule-table .day-column').length ) {
jQuery('#wrapper-schedule .mobile-slides').height( jQuery('#wrapper-schedule .schedule-table .day-column.active-day').height() );
jQuery('#wrapper-schedule .schedule-table').height( jQuery('#wrapper-schedule .schedule-table .day-column.active-day').height() );
console.log(jQuery('#wrapper-schedule .schedule-table .day-column.active-day').height());
jQuery('#wrapper-schedule .controls .arrow.next').click(function(){
var currentDayIndex = jQuery(this).parents('.schedule-wrapper').find('.active-day').index();
var newDayIndex = currentDayIndex+1;
if(currentDayIndex == 6)
newDayIndex = 0;
jQuery(this).parents('.schedule-wrapper').find('.active-day').removeClass('active-day');
jQuery(this).parents('.schedule-wrapper').find('.day-column').eq(newDayIndex).addClass('active-day');
return false;
});
jQuery('#wrapper-schedule .controls .arrow.prev').click(function(){
var currentDayIndex = jQuery(this).parents('.schedule-wrapper').find('.active-day').index();
var newDayIndex = currentDayIndex-1;
if(currentDayIndex == 0)
newDayIndex = 6;
jQuery(this).parents('.schedule-wrapper').find('.active-day').removeClass('active-day');
jQuery(this).parents('.schedule-wrapper').find('.day-column').eq(newDayIndex).addClass('active-day');
return false;
});
}
}, 750);
</script>
</div><!--#wrapper-schedule-->
</div><!-- /#content -->
<?php get_sidebar(); ?>
</div><!-- /.row -->
</main><!-- /.container -->
<?php get_footer(); ?>