123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- require_once 'Evento.php';
- require_once 'Fechas.php';
- class EventoInsignia {
- private static function getEventos ($pdo, $mes, $anio, $insignia_id = null, $evento_id = null) {
- $eventos = array();
- if (!is_null($mes)){
- $fecha_min = $anio. '-' . $mes . '-1';
- $fecha_max = $anio. '-' . $mes . '-' . cal_days_in_month(CAL_GREGORIAN, $mes, $anio);
- if (is_null($insignia_id) && is_null($evento_id))
- $stmt = $pdo->prepare('Select * from alu_fs_calendarioevento(null, null, :Fecha_inicio, :Fecha_fin)');
- else {
- if (is_null($insignia_id)){
- $stmt = $pdo->prepare('Select * from alu_fs_calendarioevento(null, :Evento, :Fecha_inicio, :Fecha_fin)');
- $stmt->bindParam(':Evento', $evento_id);
- } else {
- if (is_null($evento_id)) {
- $stmt = $pdo->prepare('Select * from alu_fs_calendarioevento(:Insignia, null, :Fecha_inicio, :Fecha_fin)');
- $stmt->bindParam(':Insignia', $insignia_id);
- } else {
- $stmt = $pdo->prepare('Select * from alu_fs_calendarioevento(:Insignia, :Evento, :Fecha_inicio, :Fecha_fin)');
- $stmt->bindParam(':Insignia', $insignia_id);
- $stmt->bindParam(':Evento', $evento_id);
- }
- }
- }
- $stmt->bindParam(":Fecha_inicio", $fecha_min);
- $stmt->bindParam(":Fecha_fin", $fecha_max);
- } else {
- if (is_null($insignia_id) && is_null($evento_id))
- $stmt = $pdo->prepare('Select * from alu_fs_calendarioevento(null, null, null, null)');
- else {
- if (is_null($insignia_id)){
- $stmt = $pdo->prepare('Select * from alu_fs_calendarioevento(null, :Evento, null, null)');
- $stmt->bindParam(':Evento', $evento_id);
- } else {
- if (is_null($evento_id)) {
- $stmt = $pdo->prepare('Select * from alu_fs_calendarioevento(:Insignia, null, null, null)');
- $stmt->bindParam(':Insignia', $insignia_id);
- } else {
- $stmt = $pdo->prepare('Select * from alu_fs_calendarioevento(:Insignia, :Evento, null, null)');
- $stmt->bindParam(':Insignia', $insignia_id);
- $stmt->bindParam(':Evento', $evento_id);
- }
- }
- }
- }
- if(!$stmt->execute())
- print_r($stmt->errorInfo());
- else {
- $eventos = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- }
- return $eventos;
- }
- public static function getDatosEventos($pdo, $mes, $anio, $insignia_id = null, $evento_id = null) {
- $eventos_display = array();//eventos con todas las fechas para pintarse. Arreglo de Objeto evento
- $eventos = self::getEventos($pdo, $mes, $anio, $insignia_id, $evento_id);
- foreach($eventos as $evento){
- $eventoObj = new Evento($evento['evento_id'], $evento['periodo_id'],$evento['insignia_id'], $evento['titulo'], $evento['detalle'], $evento['shortname'], $evento['fecha_inicio'], $evento['hora_inicio'], $evento['hora_fin'] ,$evento['inscripciones']);
- //-- Calcular posibles fechas e insertar fechas en objeto --
- $fecha = Fechas::validaFormatoFecha($evento['fecha_inicio']);
- switch($evento['repeticion_id']){
- case 1: //diario
- $cont = 0;
- while (strtotime($fecha) <= strtotime($evento['reglas_fecha_final'])) {
- $eventoObj->addFecha($fecha);
- $fecha = date ("Y-m-d", strtotime("+1 day", strtotime($fecha)));
- $cont++;
- }
- if ($cont == 2)
- $eventoObj->periodicidad = 'ULTIMOS';
- else
- $eventoObj->periodicidad = 'RANGO';
- break;
- case 2: //semanal
- $diasArr = explode(",", $evento['reglas_dias']);
- while (strtotime($fecha) <= strtotime($evento['reglas_fecha_final'])) {
- if(in_array(date("w", strtotime($fecha)), $diasArr) ){//si es el día que quiero
- $eventoObj->addFecha($fecha);
- }
- $fecha = date ("Y-m-d", strtotime("+1 day", strtotime($fecha)));
- }
- $eventoObj->periodicidad = 'ALTERNADOS';
- break;
- case 3://mensual
- $diasArr = explode(",", $evento['reglas_dias']);
- //reglas
- $weekTxt = array(1=>"first", 2=>"second", 3=>"third", 4=>"fourth", -1=>"last");
- $dayname = array("sun", "mon", "tue", "wed", "thu", "fri", "sat");
- $fecha = date ("Y-m-01", strtotime($fecha));//empieza a revisar en el primer día del mes
- $semana = $evento['reglas_semana'];
- while (strtotime($fecha) <= strtotime($evento['reglas_fecha_final'])) {
- foreach($diasArr as $d){
- //echo "-->". intval(date("w", strtotime($fecha)))." == ". intval($d)."[".$fecha."]";
- if($semana == 1 && intval(date("w", strtotime($fecha))) == intval($d) ){//si el día actual es el que quiero lo guarda
- $eventoObj->addFecha($fecha);
- }else{//si no calcula siguiente día
- if(intval(date("w", strtotime($fecha))) == intval($d)){
- $fechaTmp = date ("Y-m-d", strtotime($weekTxt[$semana-1]." ".$dayname[$d], strtotime($fecha)));
- }else{
- $fechaTmp = date ("Y-m-d", strtotime($weekTxt[$semana]." ".$dayname[$d], strtotime($fecha)));
- }
- $eventoObj->addFecha($fechaTmp);
- }
- }
- $fecha = date ("Y-m-01", strtotime("+1 month", strtotime($fecha)));//siguiente mes primer día
- }
- $eventoObj->periodicidad = 'ALTERNADOS';
- break;
- default: //no se repite
- $eventoObj->addFecha($fecha);
- $eventoObj->periodicidad = 'UNICO';
- break;
- }
- $stmt = $pdo->prepare('Select * from fs_calendarioeventoeditado(:Evento)');
- $stmt->bindParam(":Evento", $eventoObj->evento_id);
- if(!$stmt->execute())
- print_r($stmt->errorInfo());
- else {
- //modifica fechas
- $eventosEditados_rs = $stmt->fetchAll();
- foreach($eventosEditados_rs as $modif){
- $eventoObj->replaceFecha($modif["CalendarioEventoEditado_fecha_origen"], $modif["CalendarioEventoEditado_fecha_nueva"], $modif["CalendarioEventoEditado_hora_inicial"], $modif["CalendarioEventoEditado_hora_final"]);
- }
- //Quitar fechas de excepción
- if (!empty($evento['excepcion'])){
- foreach(explode(",", $evento['excepcion']) as $ex){
- $eventoObj->removeFecha($ex);
- }
- $eventoObj->periodicidad = 'ALTERNADOS';
- }
- //Descompone el objeto en un arreglo con todas las fechas y agrega a lista al total del calendario
- $alta = false;
- if (!is_null($mes)){
- $cont = 0;
- $fechas = array_column($eventoObj->fechasArr, 'fecha');
- while (!$alta && $cont < count($fechas)) {
- if (($anio . '-' . Fechas::dosDigitos($mes)) == substr($fechas[$cont], 0,-3))
- $alta = true;
- $cont++;
- }
- } else
- $alta = true;
- if ($alta) {
- $eventoObj->dia = self::primerDiaMes(array_column($eventoObj->fechasArr,'fecha'), $anio . '-' . Fechas::dosDigitos($mes));
- array_push($eventos_display, $eventoObj->getEventList($mes, $anio));
- }
- }
- $stmt->closeCursor();
- $stmt = null;
- }
- return $eventos_display;
- }
- public static function getDatosInsignia($pdo, $evento){
- $insignia = array();
- $stmt = $pdo->prepare('SELECT * FROM fs_insigniageneral(:Evento_id)');
- $stmt->bindParam(':Evento_id', $evento);
- if(!$stmt->execute())
- print_r($stmt->errorInfo());
- else
- $insignia = $stmt->fetch();
- $stmt->closeCursor();
- $stmt = null;
- return $insignia;
- }
- public static function getFechasRomanizadas($fechasArr, $tipo, $fecha, $horas = false, $anio = false){
- $fechas = array('texto' => '', 'horario' => '', 'horarioTemp' => '');
- if (count($fechas) > 0){
- switch ($tipo){
- case 'UNICO':
- if ($horas)
- $fechas['horario'] = Fechas::horas($fechasArr[0]['hora_ini'], $fechasArr[0]['hora_fin'], '-');
- else
- $fechas['horario'] = '';
- $fechas['horarioTemp'] = $fechas['horario'];
- break;
- case 'RANGO':
- case 'ALTERNADOS':
- case 'ULTIMOS':
- $hora_ini = array_unique(array_column($fechasArr, 'hora_ini'));
- $hora_fin = array_unique(array_column($fechasArr, 'hora_fin'));
- if(count($hora_ini) == 1 && count($hora_fin) == 1 || !$horas) {
- if ($horas)
- $fechas['horario'] = Fechas::horas($fechasArr[0]['hora_ini'], $fechasArr[0]['hora_fin'], '-');
- else
- $fechas['horario'] = '';
- switch ($tipo){
- case 'ULTIMOS':
- $fechas['texto'] = Fechas::estandarizaDia($fechasArr[0]['fecha'], $fechasArr[count($fechasArr) - 1]['fecha'], $tipo, $anio);
- break;
- case 'ALTERNADOS':
- $temp = array_column($fechasArr, 'fecha');
- $fechas['texto'] = '';
- for ($cont = 0; $cont < (count($temp) - 1); $cont++) {
- if ($cont < count($temp) - 2)
- $fechas['texto'] .= Fechas::estandarizaDia($temp[$cont], $temp[$cont + 1], 'ALTERNADOS', $anio);
- else
- $fechas['texto'] .= Fechas::estandarizaDia($temp[$cont], $temp[$cont + 1], 'ULTIMOS', $anio);
- }
- break;
- case 'RANGO':
- $fechas['texto'] = Fechas::estandarizaDia($fechasArr[0]['fecha'], $fechasArr[count($fechasArr) - 1]['fecha'], $tipo, $anio);
- break;
- }
- $fechas['horarioTemp'] = $fechas['horario'];
- } else {
- $encontrado = false;
- $fechas['texto'] = '';
- for ($cont = 0; $cont < count($fechasArr); $cont++) {
- $horario = Fechas::horas($fechasArr[$cont]['hora_ini'], $fechasArr[$cont]['hora_fin'], '-');
- $fechas['texto'] .= Fechas::romanizaFecha($fechasArr[$cont]['fecha'], $anio) . ' | ' . $horario;
- if ($cont < (count($fechasArr) - 1))
- $fechas['texto'] .= '<br />';
- if (!is_null($fecha)){
- if ($fecha == substr($fechasArr[$cont]['fecha'],0, -3) && !$encontrado)
- $fechas['horarioTemp'] = $horario;
- }
- }
- }
- break;
- }
- }
- return $fechas;
- }
- public static function getRegistroEvento($pdo, $usuario, $insignia = null, $fechaIni = null, $fechaFin = null){
- $registro = array();
- if (is_null($fechaIni))
- $fechas = ', null, null)';
- else
- $fechas = ',:Inicio, :Fin)';
- if (!is_null($insignia)){
- $stmt = $pdo->prepare('SELECT * FROM alu_fs_registroevento(:Insignia_id, :Usuario_id' . $fechas);
- $stmt->bindParam(':Insignia_id', $insignia);
- if (!is_null($fechaIni)){
- $stmt->bindParam(':Inicio', $fechaIni);
- $stmt->bindParam(':Fin', $fechaFin);
- }
- } else {
- $stmt = $pdo->prepare('SELECT * FROM alu_fs_registroevento(null, :Usuario_id' . $fechas);
- if (!is_null($fechaIni)){
- $stmt->bindParam(':Inicio', $fechaIni);
- $stmt->bindParam(':Fin', $fechaFin);
- }
- }
- $stmt->bindParam(':Usuario_id', $usuario);
- if(!$stmt->execute())
- print_r($stmt->errorInfo());
- else
- $registro = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- return $registro;
- }
- private static function primerDiaMes($fechas, $fecha) {
- $encontrado = false;
- $dia = '';
- while (($temp = current($fechas)) && !$encontrado) {
- if ($fecha == substr($temp, 0,-3)) {
- $dia = substr($temp, -2);
- $encontrado = true;
- }
- next($fechas);
- }
- return $dia;
- }
- }
|