blob: ee8a4c17ca2f862ea6b19a8856971b7cc6e0174f [file] [log] [blame]
<?php
/*
* hores
* Copyright (c) 2023 Adrià Vilanova Martínez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see http://www.gnu.org/licenses/.
*/
class schedulesView {
const HOUR_HEIGHT = 30;
public static function renderSchedule(&$week, $editEnabled, $editLink, $deleteLink) {
$secmin = 24*60*60;
$secmax = 0;
foreach ($week as $day) {
if ($day["beginswork"] < $secmin) $secmin = $day["beginswork"];
if ($day["endswork"] > $secmax) $secmax = $day["endswork"];
}
$min = max(floor($secmin/(60*60)) - 1, 0);
$max = min(ceil($secmax/(60*60)) + 1, 24);
?>
<div class="overflow-wrapper overflow-wrapper--for-table" style="text-align: center;">
<div class="schedule mdl-shadow--2dp">
<div class="sidetime">
<?php
for ($hour = $min; $hour <= $max; $hour++) {
?>
<div class="hour">
<div class="hour--text"><?=security::htmlsafe(visual::padNum($hour, 2).":00")?></div>
</div>
<?php
}
?>
</div>
<?php
for ($day = 0; $day < 7; $day++) {
$isset = isset($week[$day]);
if (!$isset && $day >= 5 && !isset($week[5]) && !isset($week[6])) continue;
if ($isset) {
$size = [];
$size["work"] = [];
$size["work"]["top"] = (($week[$day]["beginswork"]/(60*60)) - $min)*self::HOUR_HEIGHT;
$size["work"]["height"] = intervals::measure([$week[$day]["beginswork"], $week[$day]["endswork"]])/(60*60)*self::HOUR_HEIGHT;
foreach (schedules::$otherEvents as $event) {
if (intervals::measure([$week[$day]["begins".$event], $week[$day]["ends".$event]]) > 0) {
$size[$event] = [];
$size[$event]["top"] = ($week[$day]["begins".$event] - $week[$day]["beginswork"])/(60*60)*self::HOUR_HEIGHT;
$size[$event]["height"] = intervals::measure([$week[$day]["begins".$event], $week[$day]["ends".$event]])/(60*60)*self::HOUR_HEIGHT;
}
}
}
?>
<div class="day">
<div class="day--header"><?=security::htmlsafe(calendars::$days[$day])?></div>
<div class="day--content">
<?php
if ($isset) {
?>
<div class="work-event" style="top: <?=(int)round($size["work"]["top"])?>px; height: <?=(int)round($size["work"]["height"])?>px;">
<?php
if ($editEnabled) {
?>
<div class="event--actions">
<a href='<?=$editLink($week[$day])?>' data-dyndialog-href='<?=$editLink($week[$day])?>' title='Modificar horario'><i class='material-icons'>edit</i></a>
<a href='<?=$deleteLink($week[$day])?>' data-dyndialog-href='<?=$deleteLink($week[$day])?>' title='Eliminar horario'><i class='material-icons'>delete</i></a>
</div>
<?php
}
?>
<div class="event--header">Trabajo</div>
<div class="event--body"><?=security::htmlsafe(schedules::sec2time($week[$day]["beginswork"]))?> - <?=security::htmlsafe(schedules::sec2time($week[$day]["endswork"]))?></div>
<?php
foreach (schedules::$otherEvents as $event) {
if (isset($size[$event])) {
?>
<div class="inline-event" style="top: <?=(int)round($size[$event]["top"])?>px; height: <?=(int)round($size[$event]["height"])?>px;">
<div class="event--header"><?=security::htmlsafe(schedules::$otherEventsDescription[$event])?></div>
<div class="event--body"></div>
</div>
<?php
}
}
?>
</div>
<?php
}
for ($hour = $min; $hour <= $max; $hour++) {
?>
<div class="hour"></div>
<?php
}
?>
</div>
</div>
<?php
}
?>
</div>
</div>
<?php
}
public static function renderPlainSchedule($week, $editEnabled, $editLink, $deleteLink, &$flag) {
foreach ($week as $day) {
$flag = true;
?>
<h4><?=security::htmlsafe(calendars::$days[$day["day"]])?> <span class="mdl-color-text--grey-600">(<?=security::htmlsafe(calendars::$types[$day["typeday"]])?>)</span>
<?php
if ($editEnabled) {
?>
<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>
<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>
<?php
}
?>
</h4>
<ul>
<li><b>Horario de trabajo:</b> <?=security::htmlsafe(schedules::sec2time($day["beginswork"]))?> - <?=security::htmlsafe(schedules::sec2time($day["endswork"]))?></li>
<?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 } ?>
<?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 } ?>
</ul>
<?php
}
}
}