2011-04-04 15:16:10 +00:00
< ? php
/*
* Clase Aut<EFBFBD> mata
*
* Realiza transiciones entre estados .
*
* 2008 - 10 - 08 ( diego ) : Se crea el objeto con los m<EFBFBD> todos necesarios para transitar .
*
*/
class Automata {
private $objeto ;
private $idioma ;
private $rol ;
function Automata ( $objeto , $idioma , $rol ){
$this -> objeto = $objeto ;
$this -> rol = $rol ;
if ( $idioma == " " ){
$this -> idioma = " sp " ;
} else {
$this -> idioma = $idioma ;
}
}
function getSiguientes ( $estado ){
$consulta = " SELECT final, nombre, rol FROM " . $this -> objeto . " _transiciones, " . $this -> objeto . " _estados WHERE inicial=' $estado ' AND idioma=' $this->idioma ' " .
" AND " . $this -> objeto . " _transiciones.final = " . $this -> objeto . " _estados.cod AND " . $this -> objeto . " _transiciones.rol <> '' " ;
2011-05-19 08:46:58 +00:00
$bd = new BD ();
2011-04-04 15:16:10 +00:00
$resultado = $bd -> execQuery ( $consulta );
while ( $rows = mysql_fetch_assoc ( $resultado )){
$final = $rows [ " final " ];
$nombre = $rows [ " nombre " ];
$rol = $rows [ " rol " ];
if ( $this -> tienePermisos ( $rows [ " rol " ])){
$lista [ $final ] = $nombre ;
}
}
if ( count ( $lista ) == 0 ) $lista = array ();
return $lista ;
}
private function tienePermisos ( $rolTrans ){
if ( $rolTrans == " " ) return true ;
$arrayRolUsr = explode ( " . " , $this -> rol );
$arrayRolTrans = explode ( " . " , $rolTrans );
foreach ( $arrayRolUsr as $rol ){
if ( in_array ( $rol , $arrayRolTrans )){
return true ;
}
}
return false ;
}
2011-05-10 18:22:34 +00:00
function getTransicion ( $inicial , $final ) {
$transicion = " " ;
2011-04-04 15:16:10 +00:00
$consulta = " SELECT transicion, rol FROM " . $this -> objeto . " _transiciones WHERE inicial=' $inicial ' AND final=' $final ' " ;
$bd = new BD ();
$resultado = $bd -> execQuery ( $consulta );
while ( $rows = mysql_fetch_assoc ( $resultado )){
$rol = $rows [ " rol " ];
if ( $this -> tienePermisos ( $rows [ " rol " ])){
$transicion = $rows [ " transicion " ];
}
}
return $transicion ;
}
}
?>