Ir a la documentación de este archivo.00001 <?php
00002
00003 class Evaluador{
00004
00005 const TIPO_COORDINADOR=1;
00006 const TIPO_PAR=2;
00007 const TIPO_COLABORADOR=3;
00008
00009 protected $eva_id;
00010 protected $eva_nombres;
00011 protected $eva_apellidos;
00012 protected $eva_correo_electronico;
00013 protected $eva_clave;
00014
00015 protected $rol_obj;
00016 protected $evaluaciones;
00017
00018 public function __construct( $id=NULL ){
00019
00020 if( $id != NULL )
00021 $this->getEvaluadorPorId( $id );
00022
00023 }
00024
00030 private function limpiar( ){
00031
00032 foreach( get_object_vars($this) as $name => $value )
00033 switch( $name ){
00034 default: $this->{$name} = NULL; break;
00035 }
00036
00037 $this->rol_obj = new stdClass( );
00038 $this->rol_obj->nombre = 'Evaluador';
00039 $this->rol_obj->descripcion = '';
00040 $this->rol_obj->permisos = 0;
00041 $this->rol_obj->status = 0;
00042
00043 }
00044
00054 public function guardar( ){
00055
00056 $data = array( );
00057
00058 $field = array( );
00059 $value = array( );
00060
00061 if( !$this->getId( ) ){
00062
00063 foreach( get_object_vars($this) as $name => $val )
00064 if( !is_null( $val ) )
00065 switch( $name ){
00066 case 'eva_id': case 'rol_obj': break;
00067 default:
00068 array_push( $field, $name );
00069 array_push( $value, ':'.$name );
00070 $data[':'.$name]=$val;
00071 }
00072 $query = 'INSERT INTO evaluadores ( '.implode( $field, ', ' ).' )VALUES( '.implode( $value, ', ' ).' )';
00073
00074 }else{
00075
00076 foreach( get_object_vars($this) as $name => $val )
00077 if( !is_null( $val ) )
00078 switch( $name ){
00079 case 'eva_id': case 'rol_obj': break;
00080 default:
00081 array_push( $field,"{$name}=:{$name}" );
00082 $data[':'.$name]=$val;
00083 }
00084
00085 $data[':eva_id']=$this->eva_id;
00086
00087 $query = 'UPDATE evaluadores SET '.implode( $field, ', ' ).' WHERE eva_id = :eva_id';
00088
00089 }
00090
00091 $db = Database::getInstance( );
00092 $consulta = $db->prepare( $query );
00093 $consulta->execute( $data );
00094
00095 if( !$this->getId( ) ) $this->getEvaluadorPorId( Database::lastInsertId( 'evaluadores_seq' ) );
00096 }
00097
00105 public function eliminar( ){
00106 if( !$this->getId( ) )
00107 return 0;
00108
00109 $db = Database::getInstance();
00110 $rt = $db->exec( 'DELETE FROM evaluadores WHERE eva_id = '.$this->getId( ) );
00111
00112 $this->limpiar( );
00113
00114 return $rt ? $rt : 0;
00115 }
00116
00129 public function getEvaluadorPorId( $id ){
00130
00131 $this->limpiar( );
00132
00133 try{
00134
00135 $db = Database::getInstance( );
00136
00137 $query = 'SELECT eva_id, eva_nombres, eva_apellidos, eva_correo_electronico, eva_clave '
00138 .' FROM evaluadores WHERE eva_id = :eva_id';
00139
00140 $consulta = $db->prepare( $query );
00141
00142 $consulta->execute( array( ':eva_id' => $id) );
00143
00144 $resultado = $consulta->fetch( PDO::FETCH_ASSOC );
00145 unset( $consulta );
00146
00147 if( !$resultado )
00148 return false;
00149 else{
00150 $this->eva_id = $resultado['eva_id'];
00151 $this->eva_nombres = $resultado['eva_nombres'];
00152 $this->eva_apellidos = $resultado['eva_apellidos'];
00153 $this->eva_correo_electronico = $resultado['eva_correo_electronico'];
00154 $this->eva_clave = $resultado['eva_clave'];
00155 }
00156 return true;
00157 }catch( Exception $e ){ throw $e; }
00158 }
00159
00172 public function getEvaluadorPorCorreoElectronico( $correo ){
00173
00174 $this->limpiar( );
00175
00176 try{
00177
00178 $db = Database::getInstance( );
00179
00180 $query = 'SELECT eva_id, eva_nombres, eva_apellidos, eva_correo_electronico, eva_clave '
00181 .' FROM evaluadores WHERE eva_correo_electronico = :eva_correo';
00182
00183 $consulta = $db->prepare( $query );
00184
00185 $consulta->execute( array( ':eva_correo' => $correo) );
00186
00187 $resultado = $consulta->fetch( PDO::FETCH_ASSOC );
00188 unset( $consulta );
00189
00190 if( !$resultado )
00191 return false;
00192 else{
00193 $this->eva_id = $resultado['eva_id'];
00194 $this->eva_nombres = $resultado['eva_nombres'];
00195 $this->eva_apellidos = $resultado['eva_apellidos'];
00196 $this->eva_correo_electronico = $resultado['eva_correo_electronico'];
00197 $this->eva_clave = $resultado['eva_clave'];
00198 }
00199 return true;
00200 }catch( Exception $e ){ throw $e; }
00201 }
00202
00218 public function getEvaluadorPorCredenciales( $correo, $clave ){
00219
00220 $this->limpiar( );
00221
00222 try{
00223
00224 $db = Database::getInstance( );
00225
00226 $query = 'SELECT eva_id, eva_nombres, eva_apellidos, eva_correo_electronico, eva_clave '
00227 .' FROM evaluadores WHERE eva_correo_electronico = :eva_correo AND eva_clave = :eva_clave';
00228
00229 $consulta = $db->prepare( $query );
00230
00231 $consulta->execute( array( ':eva_correo' => $correo, ':eva_clave'=>$clave) );
00232
00233 $resultado = $consulta->fetch( PDO::FETCH_ASSOC );
00234 unset( $consulta );
00235
00236 if( !$resultado )
00237 return false;
00238 else{
00239 $this->eva_id = $resultado['eva_id'];
00240 $this->eva_nombres = $resultado['eva_nombres'];
00241 $this->eva_apellidos = $resultado['eva_apellidos'];
00242 $this->eva_correo_electronico = $resultado['eva_correo_electronico'];
00243 $this->eva_clave = $resultado['eva_clave'];
00244 }
00245 return true;
00246 }catch( Exception $e ){ throw $e; }
00247 }
00248
00262 public function getCuestionariosLista( $pg=1, $limit=20 ){
00263
00264 if( !$this->getId( ) ) return NULL;
00265
00266 $db = Database::getInstance( );
00267
00268 $consulta = NULL;
00269 $pager = new stdClass( );
00270 $rt = new stdClass( );
00271
00272 $consulta = $db->prepare(
00273 'SELECT count(*) as rowCount FROM evaluaciones eva '
00274 .'JOIN evaluaciones_participantes eva_par ON ( eva_par.eva_id = eva.eva_id ) '
00275 .'JOIN participantes_evaluadores par_eval ON ( par_eval.par_id = eva_par.par_id ) '
00276 .'JOIN evaluaciones_inventarios eva_inv ON ( eva_inv.eva_id = eva.eva_id ) '
00277 .'JOIN inventarios inv ON ( inv.inv_id = eva_inv.inv_id ) '
00278 .'JOIN cuestionarios cue ON ( cue.cue_inv_id = inv.inv_id ) '
00279 .'WHERE cue.cue_tipo = 1 AND par_eval.eva_id = :eval_id AND ('
00280 .'SELECT count(*) as rowCount FROM preguntas a '
00281 .'JOIN cuestionarios b ON ( b.cue_id = a.pre_cue_id ) '
00282 .'JOIN inventarios c ON ( c.inv_id = b.cue_inv_id ) '
00283 .'JOIN evaluaciones_inventarios d ON ( d.inv_id = c.inv_id ) '
00284 .'WHERE '
00285 .'d.eva_id = eva_par.eva_id AND b.cue_id = cue.cue_id '
00286 .'AND NOT EXISTS ( '
00287 .'SELECT * FROM respuestas res WHERE a.pre_id = res.pre_id AND res.eva_id = d.eva_id '
00288 .'AND res.eval_id=:eval_id '
00289 .') '
00290 .')>0'
00291 );
00292
00293 $consulta->execute( array( ':eval_id' => $this->getId( ) ) );
00294 $resultado = $consulta->fetch(PDO::FETCH_ASSOC); unset($consulta);
00295
00296 if( !$resultado || $resultado['rowcount'] == 0){
00297 $rt->PageCount=1;
00298 $rt->Pagina = 1;
00299 $rt->Cuestionarios = array( );
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 .'cue.cue_id, cue.cue_nombre, '
00310 .'eva.eva_id, eva.eva_nombre, eva.eva_fecha_inicio, eva.eva_fecha_fin, '
00311 .'inv.inv_nombre, inv.inv_id, '
00312 .'eva_par.par_id, '
00313 .'par_eval.eva_tipo '
00314 .'FROM evaluaciones eva '
00315 .'JOIN evaluaciones_participantes eva_par ON ( eva_par.eva_id = eva.eva_id ) '
00316 .'JOIN participantes_evaluadores par_eval ON ( par_eval.par_id = eva_par.par_id ) '
00317 .'JOIN evaluaciones_inventarios eva_inv ON ( eva_inv.eva_id = eva.eva_id ) '
00318 .'JOIN inventarios inv ON ( inv.inv_id = eva_inv.inv_id ) '
00319 .'JOIN cuestionarios cue ON ( cue.cue_inv_id = inv.inv_id ) '
00320 .'WHERE cue.cue_tipo = 1 AND par_eval.eva_id = :eval_id AND ('
00321 .'SELECT count(*) as rowCount FROM preguntas a '
00322 .'JOIN cuestionarios b ON ( b.cue_id = a.pre_cue_id ) '
00323 .'JOIN inventarios c ON ( c.inv_id = b.cue_inv_id ) '
00324 .'JOIN evaluaciones_inventarios d ON ( d.inv_id = c.inv_id ) '
00325 .'WHERE '
00326 .'d.eva_id = eva_par.eva_id AND b.cue_id = cue.cue_id '
00327 .'AND NOT EXISTS ( '
00328 .'SELECT * FROM respuestas res WHERE a.pre_id = res.pre_id AND res.eva_id = d.eva_id '
00329 .'AND res.eval_id=:eval_id '
00330 .') '
00331 .')>0'
00332 , $limit, $pager->offset );
00333
00334 $consulta = $db->prepare( $query );
00335 $consulta->execute( array( ':eval_id' => $this->getId( ) ) );
00336
00337 $Cuestionarios = array( );
00338
00339 while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC ) ){
00340 $inv = new stdClass( );
00341 $inv->Id = $resultado['inv_id'];
00342 $inv->Nombre = $resultado['inv_nombre'];
00343
00344 $eva = new stdClass( );
00345 $eva->Id = $resultado['eva_id'];
00346 $eva->Nombre = $resultado['eva_nombre'];
00347 $eva->FechaInicio = $resultado['eva_fecha_inicio'];
00348 $eva->FechaFin = $resultado['eva_fecha_fin'];
00349
00350 $item = new stdClass( );
00351 $item->Id = $resultado['cue_id'];
00352 $item->Nombre = $resultado['cue_nombre'];
00353 $item->Participante = $resultado['par_id'];
00354 $item->Evaluador = $this->getId( );
00355 $item->EvaluadorTipo = $resultado['eva_tipo'];
00356 $item->Inventario = $inv;
00357 $item->Evaluacion = $eva;
00358 array_push( $Cuestionarios, $item );
00359 }
00360 $consulta->closeCursor( ); unset( $consulta );
00361
00362 $rt->PageCount = $pager->pageCount;
00363 $rt->Pagina = $pg > $rt->PageCount ? $rt->PageCount : $pg ;
00364 $rt->Cuestionarios = $Cuestionarios;
00365
00366 return $rt;
00367 }
00368
00369
00377 public function getId( ){ return $this->eva_id ? $this->eva_id : NULL; }
00378
00386 public function getNombres( ){ return $this->eva_nombres; }
00394 public function setNombres( $val ){ $this->eva_nombres = $val; }
00395
00403 public function getApellidos( ){ return $this->eva_apellidos; }
00411 public function setApellidos( $val ){ $this->eva_apellidos = $val; }
00412
00420 public function getCorreoElectronico( ){ return $this->eva_correo_electronico; }
00421
00429 public function setCorreoElectronico( $val ){ $this->eva_correo_electronico = $val; }
00430
00441 public function getRol( ){ return $this->rol_obj; }
00442
00450 public function setClave( $val ){ $this->eva_clave = $val; }
00451
00461 public function getNombreCompleto( ){
00462
00463 $Nombres = $this->eva_nombres;
00464 $Apellidos = $this->eva_apellidos ? ', '.$this->eva_apellidos : '' ;
00465
00466 return ucwords( strtolower( "{$Nombres}{$Apellidos}" ) );
00467 }
00468
00477 public function cambiarClave( $val ){
00478
00479 if( !$this->getId( ) )
00480 return false;
00481
00482 $db = Database::getInstance( );
00483
00484 $consulta = $db->prepare( 'UPDATE evaluadores SET eva_clave = :clave WHERE eva_id = :id' );
00485
00486 $consulta->execute( array( ':id'=>$this->getId( ), ':clave'=>$val ) );
00487 $success = $consulta->rowCount( );
00488 unset($consulta);
00489
00490 return $success == 0 ? false : true;
00491 }
00492
00501 public function permite( ){ return false; }
00502
00510 public function getTipoDeCuenta( ){ return 'E'; }
00511
00512 public function getStatus( ){ return 1; }
00513
00514 }