| Server IP : 104.21.84.107 / Your IP : 104.23.243.196 Web Server : Apache/2.4.63 (Ubuntu) System : Linux adminpruebas-Virtual-Machine 6.14.0-37-generic #37-Ubuntu SMP PREEMPT_DYNAMIC Fri Nov 14 22:10:32 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.4.5 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /proc/self/root/var/www/biblioteca/includes/ |
Upload File : |
<?php
declare(strict_types=1);
function capacitacionSortMinutes(string $timeLabel): int
{
$normalized = strtolower(trim($timeLabel));
$normalized = str_replace(['a. m.', 'a.m.', 'am'], 'am', $normalized);
$normalized = str_replace(['p. m.', 'p.m.', 'pm'], 'pm', $normalized);
if (!preg_match('/^(\d{1,2}):(\d{2})\s*(am|pm)?$/', $normalized, $matches)) {
return PHP_INT_MAX;
}
$hours = (int) $matches[1];
$minutes = (int) $matches[2];
$meridiem = $matches[3] ?? '';
if ($meridiem === 'am' && $hours === 12) {
$hours = 0;
} elseif ($meridiem === 'pm' && $hours < 12) {
$hours += 12;
}
return ($hours * 60) + $minutes;
}
function buildCapacitacionItem(array $item): ?array
{
if (empty($item['fecha'])) {
return null;
}
$fecha = DateTimeImmutable::createFromFormat('Y-m-d', (string) $item['fecha']);
if (!$fecha) {
return null;
}
return [
'fecha' => $fecha,
'hora' => (string) ($item['hora'] ?? ''),
'hora_orden' => capacitacionSortMinutes((string) ($item['hora'] ?? '')),
'titulo' => (string) ($item['titulo'] ?? ''),
'descripcion' => (string) ($item['descripcion'] ?? ''),
'capacitador' => (string) ($item['capacitador'] ?? ''),
'publico' => (string) ($item['publico'] ?? ''),
'modalidad' => (string) ($item['modalidad'] ?? ''),
'categoria' => (string) ($item['categoria'] ?? 'Capacitación'),
'plataforma' => (string) ($item['plataforma'] ?? ''),
'cupo' => (string) ($item['cupo'] ?? ''),
'acento' => (string) ($item['acento'] ?? '#8f141b'),
'boton_texto' => (string) ($item['boton_texto'] ?? 'Registro'),
'boton_url' => (string) ($item['boton_url'] ?? '#'),
'qr_imagen' => (string) ($item['qr_imagen'] ?? ''),
'qr_alt' => (string) ($item['qr_alt'] ?? ''),
];
}
function sortCapacitacionesChronologically(array &$items): void
{
usort($items, static function (array $a, array $b): int {
$byDate = $a['fecha'] <=> $b['fecha'];
if ($byDate !== 0) {
return $byDate;
}
$byTime = ((int) ($a['hora_orden'] ?? PHP_INT_MAX)) <=> ((int) ($b['hora_orden'] ?? PHP_INT_MAX));
if ($byTime !== 0) {
return $byTime;
}
return strcmp((string) ($a['hora'] ?? ''), (string) ($b['hora'] ?? ''));
});
}