Exemplo n.º 1
0
 public function getDatos(OrigenDatos $origenDato)
 {
     $datos = array();
     $nombre_campos = array();
     if ($origenDato->getSentenciaSql() != '') {
         $conexion = $origenDato->getConexion();
         $conn = $this->getEntityManager()->getRepository('IndicadoresBundle:Conexion')->getConexionGenerica($conexion);
         try {
             $query = $conn->query($origenDato->getSentenciaSql());
             if ($query->rowCount() > 0) {
                 $datos = $query->fetchAll();
                 $nombre_campos = array_keys($datos[0]);
             }
         } catch (\PDOException $e) {
             return false;
         } catch (DBAL\DBALException $e) {
             return false;
         }
     } else {
         $reader = new Excel();
         try {
             $reader->loadFile($origenDato->getAbsolutePath());
             $datos_aux = $reader->getSheet()->toArray(null, false, false, false);
             $nombre_campos = array_values(array_shift($datos_aux));
             // Buscar por columnas que tengan null en el título
             $primer_null = array_search(null, $nombre_campos);
             if ($primer_null == false) {
                 foreach ($datos_aux as $fila) {
                     $datos[] = $fila;
                 }
             } else {
                 $nombre_campos = array_slice($nombre_campos, 0, $primer_null, true);
                 foreach ($datos_aux as $fila) {
                     $datos[] = array_slice($fila, 0, $primer_null, true);
                 }
             }
             $fix_datos = array();
             foreach ($datos as $k => $f) {
                 foreach ($f as $indice => $campo) {
                     $fix_datos[$k][$nombre_campos[$indice]] = trim($campo);
                 }
             }
         } catch (\Exception $e) {
             return false;
         }
         $datos = $fix_datos;
     }
     return $datos;
 }
 public function getTotalRegistros(OrigenDatos $origenDato)
 {
     if ($origenDato->getSentenciaSql() != '') {
         $conexion = $origenDato->getConexion();
         $conn = $this->getEntityManager()->getRepository('IndicadoresBundle:Conexion')->getConexionGenerica($conexion);
         if ($conexion->getIdMotor()->getCodigo() == 'pdo_dblib') {
             $query = mssql_query($origenDato->getSentenciaSql(), $conn);
             $total = mssql_num_rows($query);
         } else {
             $total = $conn->query($origenDato->getSentenciaSql())->rowCount();
         }
         return $total;
     } else {
         return 1;
     }
 }