IESA
Programa de Feedback Gerencial y Liderazgo
 Todo Estructuras de Datos Archivos Funciones Variables
Profesor.class.php
Ir a la documentación de este archivo.
00001 <?php
00002 
00003 class Profesor{
00004 
00005         protected $pro_id;
00006         protected $pro_correo_electronico;
00007         protected $pro_clave;
00008         protected $pro_nombre;
00009         protected $pro_cuenta;
00010         
00011         protected $pro_evaluaciones;
00012 
00013         public function __construct( $id=NULL ){ 
00014                 if( $id != NULL )
00015                         $this->getProfesorPorId( $id );
00016         }
00017 
00023         private function limpiar(  ){
00024 
00025                 foreach( get_object_vars($this) as $name => $value )
00026                         switch( $name ){
00027                                 default: $this->{$name} = NULL; break;
00028                         }
00029 
00030         }
00031 
00043         public function getProfesor( $data ){
00044 
00045                         $db = Database::getInstance(  );
00046 
00047                         $query = 'SELECT pro_id, pro_cuenta, pro_clave FROM profesores WHERE '.$data['where'];
00048 
00049                         $consulta = $db->prepare( $query );
00050                         $consulta->execute( $data['data'] );
00051 
00052                         $resultado = $consulta->fetch( PDO::FETCH_ASSOC );
00053                         $consulta->closeCursor(  );
00054                         unset( $consulta );
00055 
00056                         if( !$resultado )
00057                                 return false;
00058                         else{
00059                                 $this->pro_id = $resultado['pro_id'];
00060                                 $this->pro_cuenta = $resultado['pro_cuenta'];
00061                                 $this->pro_clave = $resultado['pro_clave'];
00062 
00063                                 $consulta = $db->prepare(
00064                                         'SELECT DOCENTE as NOMBRE, USUARIO_DOCENTE, CORREO_DOCENTE1 as CORREO'
00065                                         .' FROM VW_ACTIVIDADES WHERE USUARIO_DOCENTE = :cuenta'
00066                                         .' GROUP BY DOCENTE, USUARIO_DOCENTE, CORREO_DOCENTE1'
00067                                 );
00068                                 $consulta->execute( array( ':cuenta' => $this->pro_cuenta ) );
00069 
00070                                 $resultado = $consulta->fetch( PDO::FETCH_ASSOC );
00071                                 $consulta->closeCursor(  );
00072                                 unset( $consulta );
00073 
00074                                 if( !$resultado ){
00075                                         $this->limpiar(  );
00076                                         return false;
00077                                 }
00078                                 $this->pro_nombre = $resultado['nombre'];
00079                                 $this->pro_correo_electronico = $resultado['correo'];
00080                         }
00081 
00082                 return true;
00083         }
00084 
00097         public function getProfesorPorId( $id ){
00098                 return $this->getProfesor( array( 
00099                         'where' => 'pro_id = :id',
00100                         'data'=> array(
00101                                 ':id'=>$id
00102                         )
00103                 ));
00104         }
00105 
00118         public function getProfesorPorCuenta( $cuenta ){
00119                 return $this->getProfesor( array( 
00120                         'where' => 'pro_cuenta = :cuenta',
00121                         'data'=> array(
00122                                 ':cuenta'=>$cuenta
00123                         )
00124                 ));
00125         }
00126 
00142         public function getProfesorPorCredenciales( $cuenta, $clave ){
00143                 return $this->getProfesor(
00144                         array(
00145                                 'where' => 'pro_cuenta = :cuenta AND pro_clave = :clave ',
00146                                 'data'  => array(
00147                                         ':cuenta' => $cuenta,
00148                                         ':clave' => $clave
00149                                 )
00150                         )
00151                 );
00152         }
00153 
00154         
00163         public function getEvaluaciones(  ){
00164 
00165                 if( !$this->getId(  ) ) return NULL;
00166 
00167                 if( $this->pro_evaluaciones != NULL ) return $this->pro_evaluaciones;
00168 
00169                 $db = Database::getInstance(  );
00170                 $consulta = $db->prepare(
00171                         'SELECT b.* FROM evaluaciones_profesores a'
00172                         .' JOIN evaluaciones b ON a.eva_id = b.eva_id WHERE a.pro_id = :pro_id'
00173                 );
00174                 $consulta->execute( array( 
00175                         'pro_id' => $this->getId(  )
00176                 ) );
00177 
00178                 $Evaluaciones = array(  );
00179 
00180                 while( $resultado = $consulta->fetch( PDO::FETCH_ASSOC ) ){
00181 
00182                         $item = new stdClass(  );
00183 
00184                         $item->Id = $resultado['eva_id'];
00185                         $item->Nombre = $resultado['eva_nombre'];
00186 
00187                         $f = preg_split( '[-]', $resultado['eva_fecha_inicio'] );
00188                         $item->FechaInicio = $f[2].'/'.$f[1].'/'.$f[0];
00189 
00190                         $f = preg_split( '[-]', $resultado['eva_fecha_fin'] );
00191                         $item->FechaFin = $f[2].'/'.$f[1].'/'.$f[0];
00192 
00193                         $item->ActividadId = $resultado['eva_act_id'];
00194                         
00195                         array_push( $Evaluaciones, $item );
00196                 }
00197 
00198                 unset( $consulta );
00199 
00200                 return $Evaluaciones;
00201         }
00202         
00203         
00211         public function getId(  ){ return $this->pro_id ? $this->pro_id : NULL; }
00212 
00220         public function getNombres(  ){ $Nombre = trim( preg_split( '[,]', $this->pro_nombre ) ); return $Nombre[0]; }
00221 
00229         public function getApellidos(  ){ $Nombre = trim( preg_split( '[,]', $this->pro_nombre ) ); return sizeof( $Nombre > 1 ) ? $Nombre[1] : ''; }
00230 
00238         public function getCorreoElectronico(  ){ return $this->pro_correo_electronico; }
00239 
00247         public function getCuenta(  ){ return $this->pro_cuenta; }
00248 
00256         public function getClave(  ){ return $this->pro_clave; }
00257 
00267         public function getNombreCompleto(  ){ return ucwords( strtolower( $this->pro_nombre ) ); }
00268 
00277         public function cambiarClave( $val ){
00278 
00279                 if( !$this->getId(  ) )
00280                         return false;
00281 
00282                 $db = Database::getInstance(  );
00283 
00284                 $consulta = $db->prepare( 'UPDATE profesores SET pro_clave = :clave WHERE pro_id = :id'  );
00285 
00286                 $consulta->execute( array( ':id'=>$this->getId(  ), ':clave'=>$val ) );
00287 
00288                 if( $consulta->rowCount(  ) == 0 ){
00289                         unset($consulta);
00290                         return false;
00291                 }
00292 
00293                 unset($consulta);
00294                 return true;
00295         }
00296 
00305         public function permite(  ){ return false; }
00306 
00317         public function getRol(  ){
00318                 $rol_obj = new stdClass( );
00319                 $rol_obj->nombre = 'Profesor';
00320                 $rol_obj->descripcion = '';
00321                 $rol_obj->permisos = 0;
00322                 $rol_obj->status = 0;
00323                 return $rol_obj;
00324         }
00325 
00326 
00334         public function getTipoDeCuenta(  ){ return 'D'; }
00335 
00336         public function getStatus(  ){ return 1; }
00337 
00338 }
00339