Example #1
0
 /**
  *  Obtiene los necesarios para ver la asistencias de alumnos
  *
  **/
 protected function obtenerDatos()
 {
     Misc::use_helper('Misc');
     //Iniciando Variables
     $alumno_id = -1;
     $cuenta_id = -1;
     $vista_id = 1;
     // default para vista DIARIO
     $division_id = 0;
     $carrera_id = 0;
     $datos = array();
     $idxAlumno = array();
     $aFeriado = array();
     $aIntervalo = array();
     $optionsDivision = array();
     $optionsCarrera = array();
     $aTemp = array();
     $aFechaTemp = array();
     $aTipoasistencias = array();
     $aPorcentajeAsistencia = array();
     $flag_error = 0;
     $nombre_completo_archivo = "";
     $bool_gd = array_search("gd", get_loaded_extensions());
     // Tomando los datos del formulario y completando variable
     $ciclolectivo_id = $this->getUser()->getAttribute('fk_ciclolectivo_id');
     $ciclolectivo = CiclolectivoPeer::retrieveByPK($ciclolectivo_id);
     $ciclolectivo_fecha_inicio = strtotime($ciclolectivo->getFechaInicio());
     $ciclolectivo_fecha_fin = strtotime($ciclolectivo->getFechaFin());
     // Asigno la fecha de inicio del ciclo lectivo por defecto
     $aFechaActual = getdate($ciclolectivo_fecha_inicio);
     // Tomo el año de la fecha de inicio y de fin del ciclo lectivo
     $anio_desde = date("Y", $ciclolectivo_fecha_inicio);
     $anio_hasta = date("Y", $ciclolectivo_fecha_fin);
     if ($this->getRequestParameter('dia')) {
         $d = $this->getRequestParameter('dia');
     } else {
         $d = $aFechaActual['mday'];
     }
     if ($this->getRequestParameter('mes')) {
         $m = $this->getRequestParameter('mes');
     } else {
         $m = $aFechaActual['mon'];
     }
     if ($this->getRequestParameter('ano')) {
         $y = $this->getRequestParameter('ano');
     } else {
         $y = $aFechaActual['year'];
     }
     if ($this->getRequestParameter('alumno_id')) {
         $alumno_id = $this->getRequestParameter('alumno_id');
         $a = AlumnoPeer::retrieveByPK($alumno_id);
         $cuenta_id = $a->getFkCuentaId();
     }
     if ($this->getRequestParameter('carrera_id')) {
         $carrera_id = $this->getRequestParameter('carrera_id');
     }
     if ($this->getRequestParameter('vistas')) {
         $vista_id = $this->getRequestParameter('vistas');
     }
     $establecimiento_id = $this->getUser()->getAttribute('fk_establecimiento_id');
     $criteria = new Criteria();
     $criteria->add(AnioPeer::FK_ESTABLECIMIENTO_ID, $establecimiento_id);
     if ($this->getRequestParameter('alumno_id')) {
         $criteria->add(RelAlumnoDivisionPeer::FK_ALUMNO_ID, $alumno_id);
         $criteria->addJoin(RelAlumnoDivisionPeer::FK_DIVISION_ID, DivisionPeer::ID);
     }
     if ($this->getRequestParameter('carrera_id')) {
         $criteria->add(AnioPeer::FK_CARRERA_ID, $carrera_id);
     }
     $criteria->addAscendingOrderByColumn(AnioPeer::DESCRIPCION);
     $criteria->addAscendingOrderByColumn(DivisionPeer::ORDEN);
     $criteria->addAscendingOrderByColumn(DivisionPeer::DESCRIPCION);
     $divisiones = DivisionPeer::doSelectJoinAnio($criteria);
     // divisiones a mostrar
     foreach ($divisiones as $division) {
         $optionsDivision[$division->getId()] = $division->__toString();
     }
     if ($this->getRequestParameter('division_id')) {
         $division_id = $this->getRequestParameter('division_id');
     } else {
         if (count($optionsDivision) > 0) {
             $aTemp = array_keys($optionsDivision);
             $division_id = $aTemp[0];
         } else {
             // Ver si se puede hacer desde el validate
             $this->getRequest()->setError('Division', 'No hay Ninguna División cargada');
             $flag_error = 1;
         }
     }
     $cCarrera = new Criteria();
     $cCarrera->add(CarreraPeer::FK_ESTABLECIMIENTO_ID, $establecimiento_id);
     $carreras = CarreraPeer::doSelect($cCarrera);
     foreach ($carreras as $carrera) {
         $optionsCarrera[$carrera->getId()] = $carrera->getDescripcion();
     }
     if (!checkdate($m, $d, $y)) {
         // Ver si se puede hacer desde el validate
         $this->getRequest()->setError('Fecha', 'La fecha ingresada es erronea');
         $flag_error = 1;
     }
     if ($flag_error == 0) {
         // devuelve un intervalo de dias según vista y fecha seleccionada
         $aIntervalo = diasxintervalo($d, $m, $y, $vista_id);
         // chequeo si el intervalo de fechas generados esta o no dentro de las fechas validas del ciclo lectivo
         foreach ($aIntervalo as $fecha) {
             $fecha_intervalo = strtotime($fecha);
             if ($fecha_intervalo >= $ciclolectivo_fecha_inicio and $fecha_intervalo <= $ciclolectivo_fecha_fin) {
                 $aFechaTemp[] = $fecha;
             }
         }
         $aIntervalo = $aFechaTemp;
     }
     // obteniendo los feriados actuales
     $criteria = new Criteria();
     $feriados = FeriadoPeer::doSelect($criteria);
     foreach ($feriados as $feriado) {
         $aFeriado[$feriado->getFecha()] = $feriado->getNombre();
     }
     // esto deberia estar hecho muy diferente guardar en un /tmp con archivo aleatorio
     if (file_exists(sfConfig::get('sf_upload_dir_name') . '/grafico_asistencias.png')) {
         unlink(sfConfig::get('sf_upload_dir_name') . '/grafico_asistencias.png');
     }
     if (count($aIntervalo) > 0) {
         //Obtener los alumnos de la division y asistencias en el rango de fecha
         //$con = sfContext::getInstance()->getDatabaseConnection($connection='propel');
         $con = Propel::getConnection();
         $s = "SELECT alumno.id, alumno.nombre, alumno.apellido, alumno.apellido_materno,";
         $s .= "tipoasistencia.descripcion, tipoasistencia.nombre AS asistencia, asistencia.fecha,";
         $s .= "asistencia.fk_tipoasistencia_id ";
         $s .= "FROM alumno, rel_alumno_division ";
         $s .= "LEFT JOIN asistencia ON ( rel_alumno_division.FK_ALUMNO_ID = asistencia.FK_ALUMNO_ID ";
         $s .= "AND asistencia.FECHA ";
         $s .= "IN (";
         for ($i = 0, $max = count($aIntervalo); $i < $max; $i++) {
             $s .= "'" . $aIntervalo[$i] . " 00:00:00'";
             if ($i < count($aIntervalo) - 1) {
                 $s .= ",";
             }
         }
         $s .= ") ) ";
         $s .= "LEFT JOIN tipoasistencia ON ( asistencia.FK_TIPOASISTENCIA_ID = tipoasistencia.ID ) ";
         $s .= "WHERE ";
         if ($alumno_id >= 0) {
             $s .= "alumno.ID =" . $alumno_id;
         } else {
             $s .= "rel_alumno_division.FK_DIVISION_ID =" . $division_id;
         }
         $s .= " AND rel_alumno_division.FK_ALUMNO_ID = alumno.ID";
         $s .= " ORDER BY alumno.apellido,alumno.apellido_materno,alumno.nombre,asistencia.FECHA";
         $stmt = $con->prepare($s);
         $alumnos = $stmt->execute();
         $totales = array();
         $tot = 0;
         while ($alumno = $stmt->fetch(PDO::FETCH_ASSOC)) {
             $idxAlumno[$alumno['id']] = $alumno['apellido'] . " " . $alumno['apellido_materno'] . " " . $alumno['nombre'];
             if ($alumno['fecha']) {
                 $datos[$alumno['id']][$alumno['fecha']] = $alumno['asistencia'];
                 @$totales[$alumno['asistencia']]++;
             }
         }
         $aTipoasistencias = $this->getTiposasistencias();
         $aPorcentajeAsistencia = array();
         $flag = 0;
         // cantidad de fechas sin fines de semana
         $cantFechas = 0;
         foreach ($aIntervalo as $fecha) {
             if (!(date("w", strtotime($fecha)) == 6) and !(date("w", strtotime($fecha)) == 0)) {
                 $cantFechas++;
             }
         }
         $dias = $cantFechas * count($idxAlumno);
         foreach ($aTipoasistencias as $idx => $Tipoasistencia) {
             $aPorcentajeAsistencia[$idx] = isset($totales[$idx]) ? number_format($totales[$idx] * 100 / $dias, 2) : number_format(0, 2);
             $tot += isset($totales[$idx]) ? number_format($totales[$idx], 2) : number_format(0, 2);
             if ($aPorcentajeAsistencia[$idx] != 0) {
                 $flag = 1;
             }
         }
         if ($flag == 1) {
             $aTitulo = array_keys($aTipoasistencias);
             $aTitulo[] = "No Cargado";
             if ($bool_gd) {
                 // Si no tiene cargado la GD no muestra el grafico
                 // Genera nombre de archivo único
                 $nombre_archivo = uniqid();
                 $nombre_completo_archivo = $nombre_archivo . '.jpg';
                 // nueva clase para grafico de tortas
                 $graph = new ezcGraphPieChart();
                 // uso driver GD pero podria ser SVG o Ming
                 $graph->driver = new ezcGraphGdDriver();
                 $graph->driver->options->supersampling = 1;
                 $graph->driver->options->jpegQuality = 100;
                 $graph->driver->options->imageFormat = IMG_JPEG;
                 // Color de fondo del grafico
                 $graph->background->color = '#FFFFFF';
                 // De donde sacar la letra
                 $graph->options->font = realpath(sfConfig::get('sf_lib_dir') . "/font/FreeSerifBold.ttf");
                 $graph->options->font->maxFontSize = 9;
                 //     $graph->title = "Asistencia";
                 // Cargo datos de la asistencia
                 $graph->data['Asistencia'] = new ezcGraphArrayDataSet($aPorcentajeAsistencia);
                 // tamaño del symbolo de la lista
                 $graph->legend->symbolSize = 10;
                 // se selecciona las opciones graficas
                 $graph->renderer = new ezcGraphRenderer3d();
                 $graph->renderer->options->moveOut = 0.01;
                 $graph->renderer->options->pieChartShadowSize = 10;
                 // $graph->renderer->options->pieChartGleam = .5;
                 $graph->renderer->options->dataBorder = false;
                 $graph->renderer->options->pieChartHeight = 16;
                 $graph->renderer->options->legendSymbolGleam = 0.5;
                 //graba archivo de imagen
                 $graph->render(400, 250, sfConfig::get('app_alba_tmpdir') . DIRECTORY_SEPARATOR . $nombre_completo_archivo);
             }
         }
     }
     //Asignacion de variables para el template
     $this->bool_tmp = is_writable(sfConfig::get('app_alba_tmpdir'));
     $this->bool_gd = $bool_gd;
     $this->nombre_completo_archivo = $nombre_completo_archivo;
     $this->d = $d;
     $this->m = $m;
     $this->y = $y;
     $this->aTipoasistencias = $aTipoasistencias;
     $this->aAlumnos = $idxAlumno;
     $this->aDatos = $datos;
     $this->optionsDivision = $optionsDivision;
     $this->optionsCarrera = $optionsCarrera;
     $this->aVistas = repeticiones();
     $this->aMeses = Meses();
     $this->aIntervalo = $aIntervalo;
     $this->aPorcentajeAsistencia = $aPorcentajeAsistencia;
     $this->aFeriado = $aFeriado;
     $this->alumno_id = $alumno_id;
     $this->cuenta_id = $cuenta_id;
     $this->vista_id = $vista_id;
     $this->division_id = $division_id;
     $this->carrera_id = $carrera_id;
     $this->anio_desde = $anio_desde;
     $this->anio_hasta = $anio_hasta;
 }
Example #2
0
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(CarreraPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(CarreraPeer::DATABASE_NAME);
         $criteria->add(CarreraPeer::ID, $pks, Criteria::IN);
         $objs = CarreraPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Example #3
0
<?php

$c = new Criteria();
$c->add(CarreraPeer::FK_ESTABLECIMIENTO_ID, $sf_user->getAttribute('fk_establecimiento_id'));
$c->addAscendingOrderByColumn(CarreraPeer::ORDEN);
$carreras = CarreraPeer::doSelect($c);
$optionsCarreras = array();
$optionsCarreras[""] = "--Seleccione un Carrera--";
foreach ($carreras as $carrera) {
    $optionsCarreras[$carrera->getId()] = $carrera->getDescripcion();
}
echo select_tag('filters[carrera]', options_for_select($optionsCarreras, isset($filters['carrera']) ? $filters['carrera'] : null));
Example #4
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = CarreraPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setFkEstablecimientoId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setDescripcion($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setOrden($arr[$keys[3]]);
     }
 }
Example #5
0
 public static function doSelectJoinAllExceptEstablecimiento(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $c = clone $c;
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     AnioPeer::addSelectColumns($c);
     $startcol2 = AnioPeer::NUM_COLUMNS - AnioPeer::NUM_LAZY_LOAD_COLUMNS;
     CarreraPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (CarreraPeer::NUM_COLUMNS - CarreraPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(AnioPeer::FK_CARRERA_ID), array(CarreraPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = AnioPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = AnioPeer::getInstanceFromPool($key1))) {
         } else {
             $omClass = AnioPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             AnioPeer::addInstanceToPool($obj1, $key1);
         }
         $key2 = CarreraPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = CarreraPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = CarreraPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 CarreraPeer::addInstanceToPool($obj2, $key2);
             }
             $obj2->addAnio($obj1);
         }
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Example #6
0
 public function getCarrera(PropelPDO $con = null)
 {
     if ($this->aCarrera === null && $this->fk_carrera_id !== null) {
         $c = new Criteria(CarreraPeer::DATABASE_NAME);
         $c->add(CarreraPeer::ID, $this->fk_carrera_id);
         $this->aCarrera = CarreraPeer::doSelectOne($c, $con);
     }
     return $this->aCarrera;
 }
Example #7
0
 public function countCarreras(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(EstablecimientoPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collCarreras === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(CarreraPeer::FK_ESTABLECIMIENTO_ID, $this->id);
             $count = CarreraPeer::doCount($criteria, $con);
         }
     } else {
         if (!$this->isNew()) {
             $criteria->add(CarreraPeer::FK_ESTABLECIMIENTO_ID, $this->id);
             if (!isset($this->lastCarreraCriteria) || !$this->lastCarreraCriteria->equals($criteria)) {
                 $count = CarreraPeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collCarreras);
             }
         } else {
             $count = count($this->collCarreras);
         }
     }
     return $count;
 }
Example #8
0
 protected function getCarreras($establecimiento_id)
 {
     $optionsCarrera = array();
     $criteria = new Criteria();
     $criteria->add(CarreraPeer::FK_ESTABLECIMIENTO_ID, $establecimiento_id);
     $carreras = CarreraPeer::doSelect($criteria);
     $optionsCarrera[] = "";
     foreach ($carreras as $carrera) {
         $optionsCarrera[$carrera->getId()] = $carrera->__toString();
     }
     asort($optionsCarrera);
     return $optionsCarrera;
 }