IESA
Programa de Feedback Gerencial y Liderazgo
 Todo Estructuras de Datos Archivos Funciones Variables
Utilitario.class.php
Ir a la documentación de este archivo.
00001 <?php
00002 class Utilitario{
00003         
00004         static $Chars;
00005         
00017         static  public function enviarCorreo( $data ){
00018                 try{
00019 
00020                         set_time_limit( 0 );
00021 
00022                         $transport = Swift_SmtpTransport::newInstance( Config::get('swiftmailer/uri'), Config::get('swiftmailer/port') )
00023                                 ->setUsername( Config::get('swiftmailer/account/user') )
00024                                 ->setPassword( Config::get('swiftmailer/account/password') );
00025 
00026                         $mailer = Swift_Mailer::newInstance($transport);
00027 
00028                         $message = Swift_Message::newInstance( $data['subject'] )
00029                                 ->setFrom( 
00030                                         array( Config::get('swiftmailer/from/mail') => Config::get('swiftmailer/from/name') )
00031                                 )
00032                                 ->setTo( $data['to'] )
00033                                 ->setBody( $data['body'], $data['format'] );
00034 
00035                         $result = $mailer->send($message);
00036 
00037                         unset( $message );
00038                         unset( $transport );
00039 
00040                         return $result;
00041                 }catch( Exception $e ){
00042                         return false;
00043                 }
00044         }
00045 
00067         static public function Request( $name, $method='' ){
00068 
00069                 $rt = NULL;
00070 
00071                 if( session_id(  ) == '' )
00072                         session_start();
00073 
00074                 if( strtoupper($method) == 'GET' )
00075                         $rt = isset( $_GET[$name] ) ? $_GET[$name] : NULL;
00076                 if( strtoupper($method) == 'POST' )
00077                         $rt = isset( $_POST[$name] ) ? $_POST[$name] : NULL;
00078                 else{
00079                         $req = array_merge( $_GET, $_POST );
00080                         $rt = isset( $req[$name] ) ? $req[$name] : NULL ;
00081                 }
00082 
00083                 return is_string( $rt ) ? str_replace( '\"', '"', urldecode( $rt ) ) : $rt ;
00084 
00085         }
00086 
00087 
00088         static public function convertir_especiales_html($str){
00089                 if( !isset( self::$Chars )){
00090                         $todas = get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES);
00091                         $etiquetas = get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES);
00092                         self::$Chars = array_diff($todas, $etiquetas);
00093                 }
00094                 $str = strtr($str, self::$Chars );
00095                 return $str;
00096         }
00097 
00098 
00108         static public function getCuestionarioDemografico(  ){
00109 
00110                 $db = Database::getInstance(  );
00111 
00112                 $query = 'SELECT cue_id FROM cuestionarios WHERE cue_tipo = 2 ORDER BY cue_id DESC';
00113 
00114                 $consulta = $db->prepare( $query );
00115                 $consulta->execute( array(  ) );
00116                 $resultado = $consulta->fetch( PDO::FETCH_ASSOC );
00117                 $consulta->closeCursor(  ); unset( $consulta );
00118 
00119                 return  $resultado ? $resultado['cue_id'] : false;
00120 
00121         }
00122 
00142         static public function ListaEvaluaciones( $pg=1, $limit=20, $filtro=array(  ) ){
00143 
00144                 $db = Database::getInstance(  );
00145 
00146                 $consulta = NULL;
00147                 $pager = new stdClass(  );
00148                 $rt = new stdClass(  );
00149 
00150                 $consulta = $db->prepare(
00151                         'SELECT count(*) as rowCount FROM evaluaciones'.( isset( $filtro['where'] ) ? " WHERE {$filtro['where']}" : '' ) 
00152                 );
00153 
00154                 $consulta->execute( isset( $filtro['data'] ) ? $filtro['data'] : array(  ) );
00155 
00156                 $resultado = $consulta->fetch(PDO::FETCH_ASSOC);
00157                 unset($consulta);
00158 
00159                 $rt = new stdClass(  );
00160 
00161                 if( !$resultado || $resultado['rowcount'] == 0){
00162 
00163                         $rt->PageCount=1;
00164                         $rt->Pagina = 1;
00165                         $rt->Evaluaciones = array(  );
00166 
00167                         return $rt;
00168                 }
00169                 $rt->RowCount = $resultado['rowcount'];
00170 
00171                 $pager->pageCount = ceil( $resultado['rowcount'] / $limit );
00172                 $pager->offset = $limit * ( ( $pg > $pager->pageCount ? $pager->pageCount : $pg ) -1 );
00173 
00174                 $query = Database::limit(
00175                         'SELECT'
00176                             .' eva.eva_id, eva.eva_nombre, eva.eva_fecha_inicio, eva.eva_fecha_fin,'
00177                             .' vw_act.TACT_DESCRIPTOR, vw_act.LOC_DESCRIPTOR, vw_act.MAT_DESCRIPTOR, vw_act.DOCENTE'
00178                         .' FROM evaluaciones eva'
00179                         .' JOIN VW_ACTIVIDADES vw_act ON eva.eva_act_id = vw_act.DIC_CODIGO'
00180                         .( isset( $filtro['where'] ) ? " WHERE {$filtro['where']}" : '' )
00181                         .' ORDER BY eva_id'
00182                 , $limit, $pager->offset );
00183                 
00184                 $consulta = $db->prepare( $query );
00185                 $consulta->execute( isset( $filtro['data'] ) ? $filtro['data'] : array(  ) );
00186 
00187                 $Evaluaciones = array(  );
00188 
00189                 $eva = $inv = NULL;
00190 
00191                 while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ){
00192 
00193                         $fecha_inicio = preg_split( '[-]', substr($resultado['eva_fecha_inicio'],0,10) );
00194                         $fecha_inicio = $fecha_inicio[2].'/'.$fecha_inicio[1].'/'.$fecha_inicio[0];
00195 
00196                         $fecha_fin = preg_split( '[-]', substr($resultado['eva_fecha_fin'],0,10) );
00197                         $fecha_fin = $fecha_fin[2].'/'.$fecha_fin[1].'/'.$fecha_fin[0];
00198 
00199                         $eva = new stdClass(  );
00200                         $eva->Id = $resultado['eva_id'];
00201                         $eva->Nombre = $resultado['eva_nombre'];
00202                         $eva->FechaInicio = $fecha_inicio;
00203                         $eva->FechaFin = $fecha_fin;
00204                         $eva->Inventarios = array(  );
00205                         $eva->Actividad = new stdClass(  );
00206                         $eva->Actividad->Tipo = htmlentities( ucwords( strtolower( trim( $resultado['tact_descriptor'] ) ) ) );
00207                         $eva->Actividad->Localidad = htmlentities( ucwords( strtolower( trim( $resultado['loc_descriptor'] ) ) ) );
00208                         $eva->Actividad->Materia = htmlentities( ucwords( strtolower( trim( $resultado['mat_descriptor'] ) ) ) );
00209                         $eva->Actividad->Profesor = htmlentities( ucwords( strtolower( trim( $resultado['docente'] ) ) ) );
00210                         array_push( $Evaluaciones, $eva );
00211                 }
00212                 unset( $consulta );
00213 
00214                 $query = 
00215                         'SELECT'
00216                             .' inv.inv_id, inv.inv_nombre, inv.inv_descripcion,'
00217                             .' cue.cue_id, cue.cue_nombre, cue.cue_instrucciones'
00218                         .' FROM evaluaciones_inventarios eva_inv'
00219                         .' JOIN inventarios inv ON inv.inv_id = eva_inv.inv_id '
00220                         .' JOIN cuestionarios cue ON cue.cue_inv_id = inv.inv_id'
00221                         .' WHERE eva_inv.eva_id = :eva_id'
00222                         .' ORDER BY inv.inv_id';
00223 
00224                 $consulta = $db->prepare( $query );
00225 
00226                 foreach( $Evaluaciones as $idx => &$eva ){
00227                         $consulta->execute( array( ':eva_id' => $eva->Id ) );
00228                         $eva->Inventarios = array(  );
00229                         while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ){
00230                                 if( sizeof($eva->Inventarios) == 0 || $eva->Inventarios[ sizeof($eva->Inventarios) -1 ]->Id != $resultado['inv_id'] ){
00231                                         $inv = new stdClass(  );
00232                                         $inv->Id = $resultado['inv_id'];
00233                                         $inv->Nombre = $resultado['inv_nombre'];
00234                                         $inv->Descripcion = $resultado['inv_descripcion'];
00235                                         $inv->Cuestionarios = array(  );
00236                                         array_push( $eva->Inventarios, $inv );
00237                                 }
00238                                 $cue = new stdClass(  );
00239                                 $cue->Id = $resultado['cue_id'];
00240                                 $cue->Nombre = $resultado['cue_nombre'];
00241                                 $cue->Descripcion = $resultado['cue_instrucciones'];
00242                                 array_push( $eva->Inventarios[ sizeof( $eva->Inventarios ) -1 ]->Cuestionarios, $cue );
00243                         }
00244                 }
00245                 unset( $consulta );
00246 
00247                 $rt->PageCount = $pager->pageCount;
00248                 $rt->Pagina = $pg > $rt->PageCount ? $rt->PageCount : $pg ;
00249                 $rt->Evaluaciones = $Evaluaciones;
00250 
00251                 return $rt;
00252 
00253         }
00254 
00275         static public function ListaEvaluacionesPorParticipante( $par_id, $pg=1, $limit=20 ){
00276 
00277                 $db = Database::getInstance(  );
00278 
00279                 $pager = new stdClass(  );
00280 
00281                 $consulta = $db->prepare(
00282                         'SELECT count(*) as rowCount FROM evaluaciones a'
00283                         .' JOIN evaluaciones_participantes b ON b.eva_id = a.eva_id'
00284                         .' WHERE b.par_id = :par_id'
00285                 );
00286 
00287                 $consulta->execute( array( ':par_id'=>$par_id ) );
00288 
00289                 $resultado = $consulta->fetch(PDO::FETCH_ASSOC);
00290                 unset($consulta);
00291 
00292                 $rt = new stdClass(  );
00293 
00294                 if( !$resultado || $resultado['rowcount'] == 0){
00295 
00296                         $rt->PageCount=1;
00297                         $rt->Pagina = 1;
00298                         $rt->Evaluaciones = array(  );
00299 
00300                         return $rt;
00301                 }
00302                 $rt->RowCount = $resultado['rowcount'];
00303 
00304                 $pager->pageCount = ceil( $resultado['rowcount'] / $limit );
00305                 $pager->offset = $limit * ( ( $pg > $pager->pageCount ? $pager->pageCount : $pg ) -1 );
00306 
00307                 $query = Database::limit(
00308                         'SELECT'
00309                             .' eva.eva_id, eva.eva_nombre, eva.eva_fecha_inicio, eva.eva_fecha_fin,'
00310                             .' vw_act.TACT_DESCRIPTOR, vw_act.LOC_DESCRIPTOR, vw_act.MAT_DESCRIPTOR, vw_act.DOCENTE'
00311                         .' FROM evaluaciones eva'
00312                         .' JOIN VW_ACTIVIDADES vw_act ON eva.eva_act_id = vw_act.DIC_CODIGO'
00313                         .' JOIN evaluaciones_participantes eva_par ON eva_par.eva_id = eva.eva_id'
00314                         .' WHERE eva_par.par_id = :par_id'
00315                         .' ORDER BY eva.eva_id'
00316                 , $limit, $pager->offset );
00317 
00318                 $consulta = $db->prepare( $query );
00319                 $consulta->execute( array( ':par_id'=>$par_id ) );
00320 
00321                 $Evaluaciones = array(  );
00322 
00323                 $eva = $inv = NULL;
00324 
00325                 while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ){
00326 
00327                         $fecha_inicio = preg_split( '[-]', $resultado['eva_fecha_inicio'] );
00328                         $fecha_inicio = $fecha_inicio[2].'/'.$fecha_inicio[1].'/'.$fecha_inicio[0];
00329 
00330                         $fecha_fin = preg_split( '[-]', $resultado['eva_fecha_fin'] );
00331                         $fecha_fin = $fecha_fin[2].'/'.$fecha_fin[1].'/'.$fecha_fin[0];
00332 
00333                         $eva = new stdClass(  );
00334                         $eva->Id = $resultado['eva_id'];
00335                         $eva->Nombre = $resultado['eva_nombre'];
00336                         $eva->FechaInicio = $fecha_inicio;
00337                         $eva->FechaFin = $fecha_fin;
00338                         $eva->Actividad = new stdClass(  );
00339                         $eva->Actividad->Tipo = htmlentities( ucwords( strtolower( trim( $resultado['tact_descriptor'] ) ) ) );
00340                         $eva->Actividad->Localidad = htmlentities( ucwords( strtolower( trim( $resultado['loc_descriptor'] ) ) ) );
00341                         $eva->Actividad->Materia = htmlentities( ucwords( strtolower( trim( $resultado['mat_descriptor'] ) ) ) );
00342                         $eva->Actividad->Profesor = htmlentities( ucwords( strtolower( trim( $resultado['docente'] ) ) ) );
00343                         $eva->Inventarios = array(  );
00344                         array_push( $Evaluaciones, $eva );
00345                 }
00346                 unset( $consulta );
00347 
00348                 $query = 
00349                         'SELECT'
00350                             .' inv.inv_id, inv.inv_nombre, inv.inv_descripcion, inv.inv_tipo,'
00351                             .' cue.cue_id, cue.cue_nombre, cue.cue_descripcion, cue.cue_tipo'
00352                         .' FROM evaluaciones_inventarios eva_inv'
00353                         .' JOIN inventarios inv ON inv.inv_id = eva_inv.inv_id '
00354                         .' JOIN cuestionarios cue ON cue.cue_inv_id = inv.inv_id'
00355                         .' WHERE eva_inv.eva_id = :eva_id AND cue.cue_tipo = 0'
00356                         .' ORDER BY inv.inv_id';
00357                 $consulta = $db->prepare( $query );
00358 
00359                 foreach( $Evaluaciones as $idx => &$eva ){
00360                         $consulta->execute( array( ':eva_id' => $eva->Id ) );
00361                         $eva->Inventarios = array(  );
00362                         while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ){
00363                                 if( sizeof( $eva->Inventarios ) == 0 || $eva->Inventarios[ sizeof( $eva->Inventarios ) -1 ]->Id != $resultado['inv_id'] ){
00364                                         $inv = new stdClass(  );
00365                                         $inv->Id = $resultado['inv_id'];
00366                                         $inv->Nombre = $resultado['inv_nombre'];
00367                                         $inv->Descripcion = $resultado['inv_descripcion'];
00368                                         $inv->Tipo = $resultado['inv_tipo'];
00369                                         $inv->Cuestionarios = array(  );
00370                                         array_push( $eva->Inventarios, $inv );
00371                                 }
00372                                 $cue = new stdClass(  );
00373                                 $cue->Id = $resultado['cue_id'];
00374                                 $cue->Nombre = $resultado['cue_nombre'];
00375                                 $cue->Descripcion = $resultado['cue_descripcion'];
00376                                 $cue->Tipo = $resultado['cue_tipo'];
00377                                 array_push( $eva->Inventarios[ sizeof( $eva->Inventarios ) -1 ]->Cuestionarios, $cue );
00378                         }
00379                 }
00380                 unset( $consulta );
00381 
00382                 $rt->PageCount = $pager->pageCount;
00383                 $rt->Pagina = $pg > $rt->PageCount ? $rt->PageCount : $pg ;
00384                 $rt->Evaluaciones = $Evaluaciones;
00385 
00386                 return $rt;
00387 
00388         }
00389 
00410         static public function ListaEvaluacionesPorEvaluador( $eva_id, $pg=1, $limit=20 ){
00411 
00412                 $db = Database::getInstance(  );
00413 
00414                 $pager = new stdClass(  );
00415 
00416                 $consulta = $db->prepare(
00417                         'SELECT count(*) as rowCount FROM evaluaciones a'
00418                         .' JOIN evaluaciones_participantes b ON b.eva_id = a.eva_id'
00419                         .' JOIN participantes_evaluadores c ON c.par_id = b.par_id'
00420                         .' WHERE c.eva_id = :eva_id'
00421                 );
00422 
00423                 $consulta->execute( array( ':eva_id'=>$eva_id ) );
00424 
00425                 $resultado = $consulta->fetch(PDO::FETCH_ASSOC);
00426                 unset($consulta);
00427 
00428                 $rt = new stdClass(  );
00429 
00430                 if( !$resultado || $resultado['rowcount'] == 0){
00431 
00432                         $rt->PageCount=1;
00433                         $rt->Pagina = 1;
00434                         $rt->Evaluaciones = array(  );
00435 
00436                         return $rt;
00437                 }
00438                 $rt->RowCount = $resultado['rowcount'];
00439 
00440                 $pager->pageCount = ceil( $resultado['rowcount'] / $limit );
00441                 $pager->offset = $limit * ( ( $pg > $pager->pageCount ? $pager->pageCount : $pg ) -1 );
00442 
00443                 $query = Database::limit(
00444                         'SELECT'
00445                             .' eva.eva_id, eva.eva_nombre, eva.eva_fecha_inicio, eva.eva_fecha_fin,'
00446                                 .' par_eva.eva_tipo,'
00447                             .' vw_act.TACT_DESCRIPTOR, vw_act.LOC_DESCRIPTOR, vw_act.MAT_DESCRIPTOR, vw_act.DOCENTE'
00448                         .' FROM evaluaciones eva'
00449                         .' JOIN VW_ACTIVIDADES vw_act ON eva.eva_act_id = vw_act.DIC_CODIGO'
00450                         .' JOIN evaluaciones_participantes eva_par ON eva_par.eva_id = eva.eva_id'
00451                         .' JOIN participantes_evaluadores par_eva ON par_eva.par_id = eva_par.par_id'
00452                         .' WHERE par_eva.eva_id = :eva_id'
00453                         .' ORDER BY eva.eva_id'
00454                 , $limit, $pager->offset );
00455 
00456                 $consulta = $db->prepare( $query );
00457                 $consulta->execute( array( ':eva_id'=>$eva_id ) );
00458 
00459                 $Evaluaciones = array(  );
00460 
00461                 $eva = $inv = NULL;
00462 
00463                 while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ){
00464 
00465                         $fecha_inicio = preg_split( '[-]', $resultado['eva_fecha_inicio'] );
00466                         $fecha_inicio = $fecha_inicio[2].'/'.$fecha_inicio[1].'/'.$fecha_inicio[0];
00467 
00468                         $fecha_fin = preg_split( '[-]', $resultado['eva_fecha_fin'] );
00469                         $fecha_fin = $fecha_fin[2].'/'.$fecha_fin[1].'/'.$fecha_fin[0];
00470 
00471                         $eva = new stdClass(  );
00472                         $eva->Id = $resultado['eva_id'];
00473                         $eva->Nombre = $resultado['eva_nombre'];
00474                         $eva->FechaInicio = $fecha_inicio;
00475                         $eva->FechaFin = $fecha_fin;
00476                         $eva->TipoEvaluador = $resultado['eva_tipo'];
00477                         $eva->Actividad = new stdClass(  );
00478                         $eva->Actividad->Tipo = htmlentities( ucwords( strtolower( trim( $resultado['tact_descriptor'] ) ) ) );
00479                         $eva->Actividad->Localidad = htmlentities( ucwords( strtolower( trim( $resultado['loc_descriptor'] ) ) ) );
00480                         $eva->Actividad->Materia = htmlentities( ucwords( strtolower( trim( $resultado['mat_descriptor'] ) ) ) );
00481                         $eva->Actividad->Profesor = htmlentities( ucwords( strtolower( trim( $resultado['docente'] ) ) ) );
00482                         $eva->Inventarios = array(  );
00483                         array_push( $Evaluaciones, $eva );
00484                 }
00485                 unset( $consulta );
00486 
00487                 $query = 
00488                         'SELECT'
00489                             .' inv.inv_id, inv.inv_nombre, inv.inv_descripcion, inv.inv_tipo,'
00490                             .' cue.cue_id, cue.cue_nombre, cue.cue_descripcion, cue.cue_tipo'
00491                         .' FROM evaluaciones_inventarios eva_inv'
00492                         .' JOIN inventarios inv ON inv.inv_id = eva_inv.inv_id '
00493                         .' JOIN cuestionarios cue ON cue.cue_inv_id = inv.inv_id'
00494                         .' WHERE inv.inv_tipo = 1 AND eva_inv.eva_id = :eva_id AND cue.cue_tipo = :eva_tipo'
00495                         .' ORDER BY inv.inv_id';
00496                 $consulta = $db->prepare( $query );
00497 
00498                 foreach( $Evaluaciones as $idx => &$eva ){
00499                         $consulta->execute( array( ':eva_id' => $eva->Id, ':eva_tipo' => $eva->TipoEvaluador ) );
00500                         $eva->Inventarios = array(  );
00501                         while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ){
00502                                 if( sizeof( $eva->Inventarios ) == 0 || $eva->Inventarios[ sizeof( $eva->Inventarios ) -1 ]->Id != $resultado['inv_id'] ){
00503                                         $inv = new stdClass(  );
00504                                         $inv->Id = $resultado['inv_id'];
00505                                         $inv->Nombre = $resultado['inv_nombre'];
00506                                         $inv->Descripcion = $resultado['inv_descripcion'];
00507                                         $inv->Tipo = $resultado['inv_tipo'];
00508                                         $inv->Cuestionarios = array(  );
00509                                         array_push( $eva->Inventarios, $inv );
00510                                 }
00511                                 $cue = new stdClass(  );
00512                                 $cue->Id = $resultado['cue_id'];
00513                                 $cue->Nombre = $resultado['cue_nombre'];
00514                                 $cue->Descripcion = $resultado['cue_descripcion'];
00515                                 $cue->Tipo = $resultado['cue_tipo'];
00516                                 array_push( $eva->Inventarios[ sizeof( $eva->Inventarios ) -1 ]->Cuestionarios, $cue );
00517                         }
00518                 }
00519                 unset( $consulta );
00520 
00521                 $rt->PageCount = $pager->pageCount;
00522                 $rt->Pagina = $pg > $rt->PageCount ? $rt->PageCount : $pg ;
00523                 $rt->Evaluaciones = $Evaluaciones;
00524 
00525                 return $rt;
00526 
00527         }
00528 
00538         static public function ListaUsuarios( $pg=1, $limit=20, $filtro=array(  ) ){
00539 
00540                 $db = Database::getInstance(  );
00541 
00542                 $consulta = NULL;
00543                 $pager = new stdClass(  );
00544                 $rt = new stdClass(  );
00545                 
00546                 $consulta = $db->prepare(
00547                         'SELECT count(*) as rowCount FROM usuarios'.( isset( $filtro['where'] ) ? " WHERE {$filtro['where']}" : '' ) 
00548                 );
00549 
00550                 $consulta->execute( isset( $filtro['data'] ) ? $filtro['data'] : array(  ) );
00551 
00552                 $resultado = $consulta->fetch(PDO::FETCH_ASSOC);
00553                 unset($consulta);
00554 
00555                 $rt = new stdClass(  );
00556 
00557                 if( !$resultado || $resultado['rowcount'] == 0){
00558 
00559                         $rt->PageCount=1;
00560                         $rt->Pagina = 1;
00561                         $rt->Usuarios = array(  );
00562 
00563                         return $rt;
00564                 }
00565                 $rt->RowCount = $resultado['rowcount'];
00566 
00567                 $pager->pageCount = ceil( $resultado['rowcount'] / $limit );
00568                 $pager->offset = $limit * ( ( $pg > $pager->pageCount ? $pager->pageCount : $pg ) -1 );
00569 
00570                 $query = 
00571                         'SELECT'
00572                             .' usu.usu_id, usu.usu_nombres, usu.usu_apellidos, usu.usu_correo_electronico, usu.usu_status,'
00573                         .' rol.rol_id, rol.rol_nombre, rol.rol_descripcion, rol.rol_status'
00574                         .' FROM usuarios usu'
00575                         .' JOIN  roles rol ON rol.rol_id = usu.usu_rol_id'
00576                         .( isset( $filtro['where'] ) ? " WHERE {$filtro['where']}" : '' )
00577                         .' ORDER BY usu.usu_nombres, usu.usu_apellidos'
00578                 ;
00579 
00580                 if( Database::driver(  ) == 'oci' )
00581                         $query = "SELECT * FROM (SELECT a.*, ROWNUM rnum FROM ( {$query} ) a WHERE ROWNUM <= {$limit}) WHERE rnum >= ".$pager->offset;
00582                 else
00583                         $query.= " LIMIT {$limit} OFFSET ".$pager->offset;
00584 
00585                 $consulta = $db->prepare( $query );
00586                 $consulta->execute( isset( $filtro['data'] ) ? $filtro['data'] : array(  ) );
00587                 
00588                 $Usuarios = array(  );
00589 
00590                 while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ){
00591 
00592                         $usu = new stdClass(  );
00593                         $usu->Id = $resultado['usu_id'];
00594                         $usu->Nombres = htmlentities( ucwords( strtolower( trim( $resultado['usu_nombres']) ) ) );
00595                         $usu->Apellidos = htmlentities( ucwords( strtolower( trim( $resultado['usu_apellidos']) ) ) );
00596                         $usu->Correo = $resultado['usu_correo_electronico'];
00597                         $usu->Status = $resultado['usu_status'];
00598                         $usu->Rol = new stdClass(  );
00599                         $usu->Rol->Id = $resultado['rol_id'];
00600                         $usu->Rol->Nombre = ucwords( strtolower( trim( $resultado['rol_nombre'] ) ) );
00601                         $usu->Rol->Descripcion = $resultado['rol_descripcion'];
00602                         $usu->Rol->Status = $resultado['rol_status'];
00603 
00604                         array_push( $Usuarios, $usu );
00605                 }
00606                 unset( $consulta );
00607 
00608                 $rt->PageCount = $pager->pageCount;
00609                 $rt->Pagina = $pg > $rt->PageCount ? $rt->PageCount : $pg ;
00610                 $rt->Usuarios = $Usuarios;
00611 
00612                 return $rt;
00613 
00614         }
00615 
00625         static public function ListaRoles( $pg=1, $limit=20, $filtro=array(  ) ){
00626 
00627                 $db = Database::getInstance(  );
00628 
00629                 $consulta = NULL;
00630                 $pager = new stdClass(  );
00631                 $rt = new stdClass(  );
00632                 
00633                 $consulta = $db->prepare(
00634                         'SELECT count(*) as rowCount FROM roles'.( isset( $filtro['where'] ) ? " WHERE {$filtro['where']}" : '' ) 
00635                 );
00636 
00637                 $consulta->execute( isset( $filtro['data'] ) ? $filtro['data'] : array(  ) );
00638 
00639                 $resultado = $consulta->fetch(PDO::FETCH_ASSOC);
00640                 unset($consulta);
00641 
00642                 $rt = new stdClass(  );
00643 
00644                 if( !$resultado || $resultado['rowcount'] == 0){
00645 
00646                         $rt->PageCount=1;
00647                         $rt->Pagina = 1;
00648                         $rt->Roles = array(  );
00649 
00650                         return $rt;
00651                 }
00652                 $rt->RowCount = $resultado['rowcount'];
00653 
00654                 $pager->pageCount = ceil( $resultado['rowcount'] / $limit );
00655                 $pager->offset = $limit * ( ( $pg > $pager->pageCount ? $pager->pageCount : $pg ) -1 );
00656 
00657                 $query = 
00658                         'SELECT'
00659                         .' rol_id, rol_nombre, rol_descripcion, rol_status'
00660                         .' FROM roles'
00661                         .( isset( $filtro['where'] ) ? " WHERE {$filtro['where']}" : '' )
00662                         .' ORDER BY rol_nombre, rol_descripcion, rol_status'
00663                 ;
00664 
00665                 if( Database::driver(  ) == 'oci' )
00666                         $query = "SELECT * FROM (SELECT a.*, ROWNUM rnum FROM ( {$query} ) a WHERE ROWNUM <= {$limit}) WHERE rnum >= ".$pager->offset;
00667                 else
00668                         $query.= " LIMIT {$limit} OFFSET ".$pager->offset;
00669 
00670                 $consulta = $db->prepare( $query );
00671                 $consulta->execute( isset( $filtro['data'] ) ? $filtro['data'] : array(  ) );
00672                 
00673                 $Roles = array(  );
00674 
00675                 while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ){
00676 
00677                         $rol = new stdClass(  );
00678                         $rol->Id = $resultado['rol_id'];
00679                         $rol->Nombre = htmlentities($resultado['rol_nombre']);
00680                         $rol->Descripcion = htmlentities($resultado['rol_descripcion']);
00681                         $rol->Status = $resultado['rol_status'];
00682 
00683                         array_push( $Roles, $rol );
00684                 }
00685                 unset( $consulta );
00686 
00687                 $rt->PageCount = $pager->pageCount;
00688                 $rt->Pagina = $pg > $rt->PageCount ? $rt->PageCount : $pg ;
00689                 $rt->Roles = $Roles;
00690 
00691                 return $rt;
00692 
00693         }
00694 
00704         static public function ListaActividades( $pg=1, $limit=20, $filtro=array(  ) ){
00705                 try{
00706                         $db = Database::getInstance(  );
00707 
00708                         $resultado = NULL;
00709                         $consulta = NULL;
00710                         $pager = new stdClass(  );
00711                         $actividades = array( );
00712                         $rt = new stdClass(  );
00713 
00714                         $query = 'SELECT count(*) as rowCount FROM VW_ACTIVIDADES'.( isset( $filtro['where'] ) ? " WHERE {$filtro['where']}":'' );
00715                         $consulta = $db->prepare( $query );
00716 
00717                         $consulta->execute( isset( $filtro['data'] ) ? $filtro['data'] : array(  ) );
00718 
00719                         $resultado = $consulta->fetch(PDO::FETCH_ASSOC);
00720                         unset($consulta);
00721 
00722                         $rt = new stdClass(  );
00723 
00724                         if( !$resultado || $resultado['rowcount'] == 0){
00725 
00726                                 $rt->PageCount=1;
00727                                 $rt->Pagina = 1;
00728                                 $rt->Actividades = array(  );
00729 
00730                                 return $rt;
00731                         }
00732                         $rt->RowCount = $resultado['rowcount'];
00733 
00734                         $pager->pageCount = ceil( $resultado['rowcount'] / $limit );
00735                         $pager->offset = $limit * ( ( $pg > $pager->pageCount ? $pager->pageCount : $pg ) -1 );
00736 
00737                         $query = 'SELECT '
00738                                 .' a.dic_codigo,a.act_descriptor,a.tact_descriptor,a.loc_descriptor,a.mat_descriptor,a.docente,a.correo_docente1,'
00739                                 .( Database::driver(  ) == 'oci' ?
00740                                                 " to_char(a.prg_fec_ini, 'YYYY-MM-DD') as prg_fec_ini, to_char( a.prg_fec_fin, 'YYYY-MM-DD' ) as prg_fec_fin,"
00741                                         :
00742                                                 'a.prg_fec_fin, a.prg_fec_ini,' )
00743                                 .' ( select count(*) from VW_PARTICIPANTES_DDG b where b.PRG_CODIGO = a.PRG_CODIGO ) + '
00744                                 .' ( select count(*) from VW_PARTICIPANTES_POST c where c.MATCOD = a.MAT_POST_CODIGO ) as num_participantes '
00745                                 .' FROM VW_ACTIVIDADES a'
00746                                 .( isset( $filtro['where'] ) ? " WHERE {$filtro['where']}" : '' )
00747                                 .' ORDER BY a.act_descriptor, a.tact_descriptor, a.prg_fec_ini, a.prg_fec_fin, a.loc_descriptor ASC ';
00748                                 
00749                         if( Database::driver(  ) == 'oci' )
00750                                 $query = "SELECT * FROM (SELECT a.*,ROWNUM rnum FROM ({$query}) a WHERE ROWNUM<={$limit}) WHERE rnum>=".$pager->offset;
00751                         else
00752                                 $query.= " LIMIT {$limit} OFFSET ".$pager->offset;
00753                                 
00754                         $consulta = $db->prepare( $query );
00755 
00756                         $consulta->execute( isset( $filtro['data'] ) ? $filtro['data'] : array(  ) );
00757 
00758                         while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ) {
00759 
00760                                 $item = new stdClass(  );
00761 
00762                                 $item->Id = $resultado['dic_codigo'];
00763                                 $item->Nombre = htmlentities( ucwords( strtolower( trim( $resultado['act_descriptor'] ) ) ) );
00764                                 $item->Tipo = htmlentities( ucwords( strtolower( trim( $resultado['tact_descriptor'] ) ) ) );
00765 
00766                                 $date = preg_split( '[-]', preg_replace( '/[ ]\d{2}[:]\d{2}[:]\d{2}/', '', $resultado['prg_fec_ini']) );
00767                                 $item->FechaInicio = $date[2].'/'.$date[1].'/'.$date[0];
00768 
00769                                 $date = preg_split( '[-]', preg_replace( '/[ ]\d{2}[:]\d{2}[:]\d{2}/', '', $resultado['prg_fec_fin']) );
00770                                 $item->FechaFin = $date[2].'/'.$date[1].'/'.$date[0];
00771 
00772                                 $item->Localidad = htmlentities( ucwords( strtolower( trim( $resultado['loc_descriptor'] ) ) ) );
00773                                 $item->Materia = htmlentities( ucwords( strtolower( trim( $resultado['mat_descriptor'] ) ) ) );
00774                                 $item->Profesor = htmlentities( ucwords( strtolower( trim( $resultado['docente'] ) ) ) );
00775                                 $item->ProfesorCorreo = $resultado['correo_docente1'];
00776                                 $item->NumeroParticipantes = $resultado['num_participantes'];
00777                                 //$item->NumeroEvaluaciones = $resultado['num_evaluaciones'];
00778 
00779                                 array_push( $actividades, $item );
00780                         }
00781 
00782                         unset( $consulta );
00783 
00784                         $rt->PageCount = $pager->pageCount;
00785                         $rt->Pagina = $pg > $rt->PageCount ? $rt->PageCount : $pg ;
00786                         $rt->Actividades = $actividades;
00787 
00788                         return $rt;
00789                 }catch( Exception $e ){ throw $e; }
00790 
00791         }
00792 
00803         static public function ListaTipoActividades(  ){
00804 
00805                 $TipoActividades = array(  );
00806                 
00807                 try{
00808 
00809                         $db = Database::getInstance(  );
00810 
00811                         $consulta = $db->prepare( 'SELECT ACT_TACT_CODIGO, TACT_DESCRIPTOR FROM VW_ACTIVIDADES GROUP BY ACT_TACT_CODIGO, TACT_DESCRIPTOR' );
00812 
00813                         $consulta->execute(  );
00814 
00815                         while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ) {
00816 
00817                                 $item = new stdClass(  );
00818 
00819                                 $item->Id = $resultado['act_tact_codigo'];
00820                                 $item->Nombre = htmlentities( ucwords( strtolower( trim( $resultado['tact_descriptor'] ) ) ) );
00821 
00822                                 array_push( $TipoActividades, $item );
00823 
00824                         }
00825                         
00826                         unset( $consulta );
00827 
00828                         return $TipoActividades;
00829                 
00830                 }catch( Exception $e ){ throw $e; }
00831                 
00832 
00833         }
00834 
00845         static public function ListaLocalidades(  ){
00846 
00847                 $localidades = array(  );
00848 
00849                 try{
00850                 
00851                         $db = Database::getInstance(  );
00852 
00853                         $consulta = $db->prepare( 'SELECT PRG_LOC_CODIGO, LOC_DESCRIPTOR FROM VW_ACTIVIDADES GROUP BY PRG_LOC_CODIGO, LOC_DESCRIPTOR' );
00854 
00855                         $consulta->execute(  );
00856 
00857                         while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ) {
00858 
00859                                 $item = new stdClass(  );
00860 
00861                                 $item->Id = $resultado['prg_loc_codigo'];
00862                                 $item->Nombre = htmlentities( ucwords( strtolower( trim( $resultado['loc_descriptor'] ) ) ) );
00863 
00864                                 array_push( $localidades, $item );
00865 
00866                         }
00867 
00868                         unset( $consulta );
00869 
00870                         return $localidades;
00871 
00872                 }catch( Exception $e ){ throw $e; }
00873 
00874         }
00875 
00886         /*
00887         static public function ListaInventarios(  ){
00888 
00889                 $inventarios = array(  );
00890 
00891                 try{
00892 
00893                         $db = Database::getInstance(  );
00894 
00895                         if( Database::driver(  ) == 'oci' )
00896                                 $query =
00897                                         'SELECT a.*, ( SELECT count(*) FROM cuestionarios b WHERE b.cue_inv_id = a.inv_id ) "inv_n_cuestionarios" FROM inventarios a';
00898                         else
00899                                 $query =
00900                                         'SELECT *, ( SELECT count(*) FROM cuestionarios b WHERE b.cue_inv_id = a.inv_id ) as inv_n_cuestionarios FROM inventarios a';
00901                                         
00902                         $consulta = $db->prepare( $query );
00903 
00904                         $consulta->execute(  );
00905 
00906                         while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ) {
00907 
00908                                 $item = new stdClass(  );
00909 
00910                                 $item->Id = $resultado['inv_id'];
00911                                 $item->Nombre = htmlentities( ucwords( strtolower( trim( $resultado['inv_nombre'] ) ) ) );
00912                                 $item->Descripcion = htmlentities( trim( $resultado['inv_descripcion'] ) );
00913                                 $item->NumeroCuestionarios = htmlentities( ucwords( strtolower( trim( $resultado['inv_n_cuestionarios'] ) ) ) );
00914 
00915                                 array_push( $inventarios, $item );
00916 
00917                         }
00918 
00919                         unset( $consulta );
00920 
00921                         return $inventarios;
00922 
00923                 }catch( Exception $e ){ throw $e; }
00924 
00925         }
00926         */
00927         static public function ListaInventarios( $pg=1, $limit=20, $filtro=array(  ) ){
00928 
00929                 $count = Database::count( 'inventarios', $filtro );
00930 
00931                 $db = Database::getInstance(  );
00932                 $pager = new stdClass(  );
00933                 $inventarios = array( );
00934                 $rt = new stdClass(  );
00935 
00936                 if( $count == 0){
00937                         $rt->PageCount=1;
00938                         $rt->Pagina = 1;
00939                         $rt->Inventarios = array(  );
00940                         return $rt;
00941                 }
00942                 $rt->RowCount = $count;
00943 
00944                 $pager->pageCount = ceil( $count / $limit );
00945                 $pager->offset = $limit * ( ( $pg > $pager->pageCount ? $pager->pageCount : $pg ) -1 );
00946 
00947                 $query = Database::limit(
00948                                 'SELECT '
00949                                         .'a.*, ( '
00950                                                 .'SELECT count(*) FROM evaluaciones eva '
00951                                                 .'JOIN evaluaciones_inventarios eva_inv ON ( eva.eva_id = eva_inv.eva_id ) '
00952                                                 .'WHERE eva_inv.inv_id = a.inv_id'
00953                                         .' ) as asignado '
00954                                 .'FROM inventarios a' .( isset( $filtro['where'] ) ? " WHERE {$filtro['where']}" : '' ).' ORDER BY inv_id', 
00955                                 $limit, $pager->offset 
00956                         );
00957 
00958                 $consulta = $db->prepare( $query );
00959 
00960                 $consulta->execute( isset( $filtro['data'] ) ? $filtro['data'] : array(  ) );
00961 
00962                 while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT ) ) {
00963                         array_push( $inventarios, ( object ) array(
00964                                 'Id' => $resultado['inv_id'],
00965                                 'Nombre' => ucwords( strtolower( trim( $resultado['inv_nombre'] ) ) ),
00966                                 'Descripcion' => htmlentities( trim( $resultado['inv_descripcion'] ) ),
00967                                 'Tipo' => $resultado['inv_tipo'],
00968                                 'Asignado' => $resultado['asignado']
00969                         ) );
00970                 }
00971                 $rt->Inventarios = $inventarios;
00972                 $consulta->closeCursor(  ); unset( $consulta );
00973 
00974                 $rt->PageCount = $pager->pageCount;
00975                 $rt->Pagina = $pg > $rt->PageCount ? $rt->PageCount : $pg ;
00976 
00977                 return $rt;
00978                 
00979         }
00980 
00981 }
00982 ?>