-
Notifications
You must be signed in to change notification settings - Fork 24
/
toba_pers_xml_generador_tablas.php
70 lines (56 loc) · 2.23 KB
/
toba_pers_xml_generador_tablas.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* Esta clase genera xml para los datos generales
* @package Centrales
* @subpackage Personalizacion
*/
class toba_pers_xml_generador_tablas extends toba_pers_xml_generador {
function generar_tablas($path, &$data)
{
// Se agrega por uniformidad de los planes de tablas y componentes
$this->plan->abrir_elemento(toba_pers_xml_elementos::modificadas);
foreach (array_keys($data) as $tabla) {
$path_tabla = $this->get_path_tabla('', $tabla);
$this->agregar_al_plan($tabla, $path_tabla);
$this->generar_tabla($this->get_path_tabla($path, $tabla), $tabla, $data[$tabla]);
}
$this->plan->cerrar_elemento();
}
protected function get_path_tabla($path_inicial, $tabla)
{
$candidato = str_replace('%id%', $tabla
, toba_personalizacion::template_archivo_tabla);
$valido = toba_manejador_archivos::nombre_valido($candidato);
return $path_inicial.$valido;
}
protected function generar_tabla($path, $nombre_tabla, &$tabla)
{
$xml = new toba_xml($path);
$xml->abrir_elemento(toba_pers_xml_elementos::tabla);
$xml->add_atributo(toba_pers_xml_atributos::id, $nombre_tabla, true);
// el contenido es el array con metadata de estado, clave y data
foreach (array_keys($tabla) as $key_contenido) {
$estado = $tabla[$key_contenido]['estado'];
$xml->abrir_elemento(toba_pers_xml_elementos::registro);
$xml->add_atributo(toba_pers_xml_atributos::estado, $estado, true);
if ($this->grabo_clave($estado)) {
$xml->add_atributo(toba_pers_xml_atributos::clave, $tabla[$key_contenido]['clave'], true);
}
foreach (array_eliminar_nulls($tabla[$key_contenido]['data']) as $columna => $valor) {
$xml->abrir_elemento(toba_pers_xml_elementos::columna);
$xml->add_atributo(toba_pers_xml_atributos::nombre, $columna, true);
if ($estado == toba_personalizacion::registro_updated) {
$xml->add_atributo(toba_pers_xml_atributos::valor, $valor['actual'], true);
$xml->add_atributo(toba_pers_xml_atributos::valor_original, $valor['original'], true);
} else { // es un registro nuevo
$xml->add_atributo(toba_pers_xml_atributos::valor, $valor, true);
}
$xml->cerrar_elemento();
}
$xml->cerrar_elemento();
}
$xml->cerrar_elemento();
$xml->cerrar_documento();
}
}
?>