blob: 69dfb3c179b76a8a3507357a3a8f3d07baf84c29 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
Adrià Vilanova Martínez5af86512023-12-02 20:44:16 +01002/*
3 * hores
4 * Copyright (c) 2023 Adrià Vilanova Martínez
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public
17 * License along with this program.
18 * If not, see http://www.gnu.org/licenses/.
19 */
20
Copybara botbe50d492023-11-30 00:16:42 +010021class schedulesView {
22 const HOUR_HEIGHT = 30;
23
24 public static function renderSchedule(&$week, $editEnabled = false, $editLink, $deleteLink) {
25 $secmin = 24*60*60;
26 $secmax = 0;
27
28 foreach ($week as $day) {
29 if ($day["beginswork"] < $secmin) $secmin = $day["beginswork"];
30 if ($day["endswork"] > $secmax) $secmax = $day["endswork"];
31 }
32
33 $min = max(floor($secmin/(60*60)) - 1, 0);
34 $max = min(ceil($secmax/(60*60)) + 1, 24);
35 ?>
36 <div class="overflow-wrapper overflow-wrapper--for-table" style="text-align: center;">
37 <div class="schedule mdl-shadow--2dp">
38 <div class="sidetime">
39 <?php
40 for ($hour = $min; $hour <= $max; $hour++) {
41 ?>
42 <div class="hour">
43 <div class="hour--text"><?=security::htmlsafe(visual::padNum($hour, 2).":00")?></div>
44 </div>
45 <?php
46 }
47 ?>
48 </div>
49 <?php
50 for ($day = 0; $day < 7; $day++) {
51 $isset = isset($week[$day]);
52
53 if (!$isset && $day >= 5 && !isset($week[5]) && !isset($week[6])) continue;
54
55 if ($isset) {
56 $size = [];
57 $size["work"] = [];
58 $size["work"]["top"] = (($week[$day]["beginswork"]/(60*60)) - $min)*self::HOUR_HEIGHT;
59 $size["work"]["height"] = intervals::measure([$week[$day]["beginswork"], $week[$day]["endswork"]])/(60*60)*self::HOUR_HEIGHT;
60
61 foreach (schedules::$otherEvents as $event) {
62 if (intervals::measure([$week[$day]["begins".$event], $week[$day]["ends".$event]]) > 0) {
63 $size[$event] = [];
64 $size[$event]["top"] = ($week[$day]["begins".$event] - $week[$day]["beginswork"])/(60*60)*self::HOUR_HEIGHT;
65 $size[$event]["height"] = intervals::measure([$week[$day]["begins".$event], $week[$day]["ends".$event]])/(60*60)*self::HOUR_HEIGHT;
66 }
67 }
68 }
69 ?>
70 <div class="day">
71 <div class="day--header"><?=security::htmlsafe(calendars::$days[$day])?></div>
72 <div class="day--content">
73 <?php
74 if ($isset) {
75 ?>
76 <div class="work-event" style="top: <?=(int)round($size["work"]["top"])?>px; height: <?=(int)round($size["work"]["height"])?>px;">
77 <?php
78 if ($editEnabled) {
79 ?>
80 <div class="event--actions">
81 <a href='<?=$editLink($week[$day])?>' data-dyndialog-href='<?=$editLink($week[$day])?>' title='Modificar horario'><i class='material-icons'>edit</i></a>
82 <a href='<?=$deleteLink($week[$day])?>' data-dyndialog-href='<?=$deleteLink($week[$day])?>' title='Eliminar horario'><i class='material-icons'>delete</i></a>
83 </div>
84 <?php
85 }
86 ?>
87 <div class="event--header">Trabajo</div>
88 <div class="event--body"><?=security::htmlsafe(schedules::sec2time($week[$day]["beginswork"]))?> - <?=security::htmlsafe(schedules::sec2time($week[$day]["endswork"]))?></div>
89 <?php
90 foreach (schedules::$otherEvents as $event) {
91 if (isset($size[$event])) {
92 ?>
93 <div class="inline-event" style="top: <?=(int)round($size[$event]["top"])?>px; height: <?=(int)round($size[$event]["height"])?>px;">
94 <div class="event--header"><?=security::htmlsafe(schedules::$otherEventsDescription[$event])?></div>
95 <div class="event--body"></div>
96 </div>
97 <?php
98 }
99 }
100 ?>
101 </div>
102 <?php
103 }
104
105 for ($hour = $min; $hour <= $max; $hour++) {
106 ?>
107 <div class="hour"></div>
108 <?php
109 }
110 ?>
111 </div>
112 </div>
113 <?php
114 }
115 ?>
116 </div>
117 </div>
118 <?php
119 }
120
121 public static function renderPlainSchedule($week, $editEnabled = false, $editLink, $deleteLink, &$flag) {
122 foreach ($week as $day) {
123 $flag = true;
124 ?>
125 <h4><?=security::htmlsafe(calendars::$days[$day["day"]])?> <span class="mdl-color-text--grey-600">(<?=security::htmlsafe(calendars::$types[$day["typeday"]])?>)</span>
126 <?php
127 if ($editEnabled) {
128 ?>
129 <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>
130 <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>
131 <?php
132 }
133 ?>
134 </h4>
135 <ul>
136 <li><b>Horario de trabajo:</b> <?=security::htmlsafe(schedules::sec2time($day["beginswork"]))?> - <?=security::htmlsafe(schedules::sec2time($day["endswork"]))?></li>
137 <?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 } ?>
138 <?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 } ?>
139 </ul>
140 <?php
141 }
142 }
143}