sernatur/lib/db/asociado.vala

95 lines
3.1 KiB
Vala

namespace Sernatur {
namespace DB {
using Postgres;
using Wrapper;
public class Asociado : GLib.Object {
public string fecha_llegada { get; set; default = ""; }
public string hora_llegada { get; set; default = ""; }
public string fecha_salida { get; set; default = ""; }
public string hora_salida { get; set; default = ""; }
public Tour tour { get; set; default = null; }
public Lugar lugar { get; set; default = null; }
public Asociado (string fecha_llegada = "", string hora_llegada = "", string fecha_salida = "", string hora_salida = "", Tour? tour = null, Lugar? lugar = null) {
this.fecha_llegada = fecha_llegada;
this.hora_llegada = hora_llegada;
this.fecha_salida = fecha_salida;
this.hora_salida = hora_salida;
}
public static Asociado[]? get_all_asociados(Database conn) {
var res = conn.exec ("
SELECT A.fecha_llegada, A.hora_llegada, A.fecha_salida, A.hora_salida
T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region,
L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel
C2.id_ciudad AS id_ciudad_lugar, C2.nombre_ciudad AS nombre_ciudad_lugar,
R2.id_region AS id_region_lugar, R2.nombre_region AS nombre_region_lugar
FROM asociado A
JOIN tour T ON (A.id_tour = T.id_tour)
JOIN ciudad C ON (T.id_cuidad = C.id_ciudad)
JOIN region R ON (C.id_region = R.id_region)
JOIN lugar L ON (A.id_lugar = L.id_lugar)
JOIN ciudad C2 ON (L.id_ciudad = C2.id_ciudad)
JOIN region R2 ON (C2.id_region = R2.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
return null;
#endif
}
var wra = new ResultWrapper (res);
Asociado[] asociados = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var asociado = new Asociado (wra.get_string_n (i, "fecha_llegada"),
wra.get_string_n (i, "hora_llegada"),
wra.get_string_n (i, "fecha_salida"),
wra.get_string_n (i, "hora_salida"),
new Tour (wra.get_int_n (i, "id_tour"),
wra.get_string_n (i, "nombre_tour"),
wra.get_int_n (i, "costo_indiv"),
wra.get_int_n (i, "costo_grupal"),
wra.get_int_n (i, "minima_personas"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
),
new Lugar (wra.get_int_n (i, "id_lugar"),
wra.get_string_n (i, "nombre_tour"),
wra.get_int_n (i, "valor_entrada"),
wra.get_int_n (i, "nivel"),
new Ciudad (wra.get_int_n (i, "id_ciudad_lugar"),
wra.get_string_n (i, "nombre_ciudad_lugar"),
new Region (wra.get_int_n (i, "id_region_lugar"),
wra.get_string_n (i, "nombre_region_lugar")
)
)
)
);
asociados += asociado;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return asociados;
}
}
}
}