blob: aab3a2f0327d1fbc95e1ea9e9aed9e2c4e5e706b [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2class schedulesView {
3 const HOUR_HEIGHT = 30;
4
5 public static function renderSchedule(&$week, $editEnabled = false, $editLink, $deleteLink) {
6 $secmin = 24*60*60;
7 $secmax = 0;
8
9 foreach ($week as $day) {
10 if ($day["beginswork"] < $secmin) $secmin = $day["beginswork"];
11 if ($day["endswork"] > $secmax) $secmax = $day["endswork"];
12 }
13
14 $min = max(floor($secmin/(60*60)) - 1, 0);
15 $max = min(ceil($secmax/(60*60)) + 1, 24);
16 ?>
17 <div class="overflow-wrapper overflow-wrapper--for-table" style="text-align: center;">
18 <div class="schedule mdl-shadow--2dp">
19 <div class="sidetime">
20 <?php
21 for ($hour = $min; $hour <= $max; $hour++) {
22 ?>
23 <div class="hour">
24 <div class="hour--text"><?=security::htmlsafe(visual::padNum($hour, 2).":00")?></div>
25 </div>
26 <?php
27 }
28 ?>
29 </div>
30 <?php
31 for ($day = 0; $day < 7; $day++) {
32 $isset = isset($week[$day]);
33
34 if (!$isset && $day >= 5 && !isset($week[5]) && !isset($week[6])) continue;
35
36 if ($isset) {
37 $size = [];
38 $size["work"] = [];
39 $size["work"]["top"] = (($week[$day]["beginswork"]/(60*60)) - $min)*self::HOUR_HEIGHT;
40 $size["work"]["height"] = intervals::measure([$week[$day]["beginswork"], $week[$day]["endswork"]])/(60*60)*self::HOUR_HEIGHT;
41
42 foreach (schedules::$otherEvents as $event) {
43 if (intervals::measure([$week[$day]["begins".$event], $week[$day]["ends".$event]]) > 0) {
44 $size[$event] = [];
45 $size[$event]["top"] = ($week[$day]["begins".$event] - $week[$day]["beginswork"])/(60*60)*self::HOUR_HEIGHT;
46 $size[$event]["height"] = intervals::measure([$week[$day]["begins".$event], $week[$day]["ends".$event]])/(60*60)*self::HOUR_HEIGHT;
47 }
48 }
49 }
50 ?>
51 <div class="day">
52 <div class="day--header"><?=security::htmlsafe(calendars::$days[$day])?></div>
53 <div class="day--content">
54 <?php
55 if ($isset) {
56 ?>
57 <div class="work-event" style="top: <?=(int)round($size["work"]["top"])?>px; height: <?=(int)round($size["work"]["height"])?>px;">
58 <?php
59 if ($editEnabled) {
60 ?>
61 <div class="event--actions">
62 <a href='<?=$editLink($week[$day])?>' data-dyndialog-href='<?=$editLink($week[$day])?>' title='Modificar horario'><i class='material-icons'>edit</i></a>
63 <a href='<?=$deleteLink($week[$day])?>' data-dyndialog-href='<?=$deleteLink($week[$day])?>' title='Eliminar horario'><i class='material-icons'>delete</i></a>
64 </div>
65 <?php
66 }
67 ?>
68 <div class="event--header">Trabajo</div>
69 <div class="event--body"><?=security::htmlsafe(schedules::sec2time($week[$day]["beginswork"]))?> - <?=security::htmlsafe(schedules::sec2time($week[$day]["endswork"]))?></div>
70 <?php
71 foreach (schedules::$otherEvents as $event) {
72 if (isset($size[$event])) {
73 ?>
74 <div class="inline-event" style="top: <?=(int)round($size[$event]["top"])?>px; height: <?=(int)round($size[$event]["height"])?>px;">
75 <div class="event--header"><?=security::htmlsafe(schedules::$otherEventsDescription[$event])?></div>
76 <div class="event--body"></div>
77 </div>
78 <?php
79 }
80 }
81 ?>
82 </div>
83 <?php
84 }
85
86 for ($hour = $min; $hour <= $max; $hour++) {
87 ?>
88 <div class="hour"></div>
89 <?php
90 }
91 ?>
92 </div>
93 </div>
94 <?php
95 }
96 ?>
97 </div>
98 </div>
99 <?php
100 }
101
102 public static function renderPlainSchedule($week, $editEnabled = false, $editLink, $deleteLink, &$flag) {
103 foreach ($week as $day) {
104 $flag = true;
105 ?>
106 <h4><?=security::htmlsafe(calendars::$days[$day["day"]])?> <span class="mdl-color-text--grey-600">(<?=security::htmlsafe(calendars::$types[$day["typeday"]])?>)</span>
107 <?php
108 if ($editEnabled) {
109 ?>
110 <a href='<?=$editLink($day)?>' data-dyndialog-href='<?=$editLink($day)?>' title='Modificar horario' class='mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect'><i class='material-icons icon'>edit</i></a>
111 <a href='<?=$deleteLink($day)?>' data-dyndialog-href='<?=$deleteLink($day)?>' title='Eliminar horario' class='mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect'><i class='material-icons icon'>delete</i></a>
112 <?php
113 }
114 ?>
115 </h4>
116 <ul>
117 <li><b>Horario de trabajo:</b> <?=security::htmlsafe(schedules::sec2time($day["beginswork"]))?> - <?=security::htmlsafe(schedules::sec2time($day["endswork"]))?></li>
118 <?php if (intervals::measure([$day["beginsbreakfast"], $day["endsbreakfast"]]) > 0) { ?><li><b>Desayuno:</b> <?=security::htmlsafe(schedules::sec2time($day["beginsbreakfast"]))?> - <?=security::htmlsafe(schedules::sec2time($day["endsbreakfast"]))?></li><?php } ?>
119 <?php if (intervals::measure([$day["beginslunch"], $day["endslunch"]]) > 0) { ?><li><b>Comida:</b> <?=security::htmlsafe(schedules::sec2time($day["beginslunch"]))?> - <?=security::htmlsafe(schedules::sec2time($day["endslunch"]))?></li><?php } ?>
120 </ul>
121 <?php
122 }
123 }
124}