83 lines
1.8 KiB
PHP
83 lines
1.8 KiB
PHP
|
|
<?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 <> ''";
|
|||
|
|
$bd = new BD();
|
|||
|
|
$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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function getTransicion($inicial, $final){
|
|||
|
|
$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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
?>
|