コード例 #1
0
ファイル: actions.class.php プロジェクト: mediasadc/alba
 /**
  *  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;
 }
コード例 #2
0
ファイル: BaseFeriadoPeer.php プロジェクト: mediasadc/alba
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(FeriadoPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(FeriadoPeer::DATABASE_NAME);
         $criteria->add(FeriadoPeer::ID, $pks, Criteria::IN);
         $objs = FeriadoPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
コード例 #3
0
ファイル: BaseCiclolectivo.php プロジェクト: mediasadc/alba
 public function countFeriados(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(CiclolectivoPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collFeriados === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(FeriadoPeer::FK_CICLOLECTIVO_ID, $this->id);
             $count = FeriadoPeer::doCount($criteria, $con);
         }
     } else {
         if (!$this->isNew()) {
             $criteria->add(FeriadoPeer::FK_CICLOLECTIVO_ID, $this->id);
             if (!isset($this->lastFeriadoCriteria) || !$this->lastFeriadoCriteria->equals($criteria)) {
                 $count = FeriadoPeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collFeriados);
             }
         } else {
             $count = count($this->collFeriados);
         }
     }
     return $count;
 }
コード例 #4
0
ファイル: BaseFeriado.php プロジェクト: mediasadc/alba
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = FeriadoPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setNombre($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setFecha($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setRepeticionAnual($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setInamovible($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setFkCiclolectivoId($arr[$keys[5]]);
     }
 }