<?php
class Vehiculo{

	private $cn = null;

	function __construct(){
		$this->cn = conectarDB();
	}

	public function usuario($patente){
		$query = 'SELECT usu_id AS id,usu_apodo AS apodo
					FROM vehiculo LEFT JOIN usu_posee_veh ON veh_id = vehiculo_veh_id LEFT JOIN usuario ON usu_id = usuario_usu_id
					WHERE veh_patente = ?;';
		$rs = $this->cn->Execute($query,array($patente));
		if(!empty($rs) && !$rs->EOF){
			$usuarios = $rs->GetArray();
			$rs->Close();
			return $usuarios;
		}
		return false;
	}

	public function carroceria($patente,$usu_id){
		$query = 'SELECT carroceria_car_id AS id
					FROM vehiculo LEFT JOIN usu_posee_veh ON veh_id = vehiculo_veh_id LEFT JOIN usuario ON usu_id = usuario_usu_id
					WHERE usu_id = ? AND veh_patente = ? LIMIT 1;';
		$rs = $this->cn->Execute($query,array($usu_id,$patente));
		if(!empty($rs) && !$rs->EOF){
			$carroceria = $rs->GetArray();
			$rs->Close();
			return $carroceria[0]['id'];
		}
		return false;
	}

	function __destruct(){
		$this->cn->Close();
	}
}
?>