<?php
class user_class
{
    private $UserId;

    private $UserName;

    private $UserRoleId;

    private $UserPassword;

    public function findUser( $userId )
    {
        $s_Sql = "SELECT * FROM SEG_Usuario WHERE IdUsuario='" . $userId . "' and DeshabilitadoFlg='N';";
        $o_Resource = Conexion::getConexion();
        $o_Statement = $o_Resource->prepareStatement( $s_Sql );
        $o_ResultSet = $o_Statement->executeQuery();
        $i_NumRows   = $o_ResultSet->getRecordCount();
        
        //$user = $result ? mysql_fetch_object( $result ) : null;
        
        if( $i_NumRows > 0 )
        {
            $o_ResultSet->next();
            $user = $o_ResultSet->getRow(); //devuele array
            $this->setUserId( $user['IdUsuario'] );
            $this->setUserName( $user['UsuarioNombre'] );
            $this->setUserRoleId( $user['IdRol'] );
            $this->setUserPassword( $user['UsuarioPassword'] );
            return true;
        }
        return false;
    }

    private function setUserId( $value )
    {
        $this->UserId = $value;
    }

    private function setUserName( $value )
    {
        $this->UserName = $value;
    }

    private function setUserRoleId( $value )
    {
        $this->UserRoleId = $value;
    }

    private function setUserPassword( $value )
    {
        $this->UserPassword = $value;
    }

    public function getUserId()
    {
        return $this->UserId;
    }

    public function getUserName()
    {
        return $this->UserName;
    }

    public function getUserRoleId()
    {
        return $this->UserRoleId;
    }

    public function getUserPassword()
    {
        return $this->UserPassword;
    }

    public static function retrieveUserId()
    {
        $userId = null;
        if( @class_exists( sfContext, false ) )
        {
            if( sfContext::hasInstance() )
            {
                $userId = sfContext::getInstance()->getUser()->getUserId();
            }
        }
        return $userId;
    }

    public static function retrieveRoleId()
    {
        $roleId = null;
        if( @class_exists( sfContext, false ) )
        {
            if( sfContext::hasInstance() )
            {
                $roleId = sfContext::getInstance()->getUser()->getRoleId();
            }
        }
        return $roleId;
    }
}