<?php

/**
 * 'menu_class' table.
 *
 * @package model
 */

class user_class {

    private $UserId;
    private $UserName;
    private $UserRoleId;
    private $IdPadre;
    private $UserPassword;

    public function findUser($userId) {
      /*
      $c = new Criteria();
      $c->add(mnu_userPeer::USER_ID, $userId);
      $user = mnu_userPeer::doSelectOne($c);
      */
      $con = Conexion::getConexion();
      $sql = "SELECT *,c.IdPadre as parent 
      		  FROM mnu_user u
      		  LEFT JOIN cr_colaborador c on c.usuario = u.user_id
      		  LEFT JOIN cr_tipocolaborador_rol tr on tr.IdTipoColaborador = c.IdTipoColaborador
      		  WHERE (c.estado = 'A')
      		  		and c.eliminado <> '1'
      		  		and user_id='".$userId."';";
      $result = mysql_db_query(Conexion::getNameDb(), $sql, $con);
      $user = $result ? mysql_fetch_object($result) : null;
    
      if ($user){
          $this->setUserId($user->user_id);
          $this->setUserName($user->user_name);
          $this->setUserRoleId($user->role_id);
          $this->setUserPassword($user->user_password);
          $this->setIdColaborador($user->IdColaborador);
          $this->setIdPadre($user->IdPadre);
          $this->setIdParent($user->parent);
          
          return true;
      }
      return false;
    }
    private function setUserId($value) {
        $this->UserId = $value;
    } 
    public function setIdPadre($value) {
        $this->IdPadre = $value;
    }
    public function getIdPadre() {
        return $this->IdPadre;
    } 
    public function setIdParent($value) {
        $this->Parent = $value;
    }
    public function getIdParent() {
        return $this->Parent;
    }
    private function setUserName($value) {
        $this->UserName = $value;
    }
    private function setUserRoleId($value) {
        $this->UserRoleId = $value;
    }
    private function setUserPassword($value) {
        $this->UserPassword = $value;
    }
	public function setIdColaborador($value) {
		$this->IdColaborador = $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 function getIdColaborador() {
        return $this->IdColaborador;
    }
    
    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;
    }
    
}