|
1
|
|
|
<?php |
|
2
|
|
|
namespace src\factory; |
|
3
|
|
|
|
|
4
|
|
|
use src\FactoryClassInterface; |
|
5
|
|
|
use src\pdodatabase\conexion\CrearConexionBaseDeDatos; |
|
6
|
|
|
use src\pdodatabase\consultas\select\ConsultaJoinWhere; |
|
7
|
|
|
use src\pdodatabase\ejecutar\EjecutarConsultaConDatos; |
|
8
|
|
|
use src\pdodatabase\elementos\Campos; |
|
9
|
|
|
use src\pdodatabase\elementos\Join as ElementosJoin; |
|
10
|
|
|
use src\pdodatabase\elementos\Joins; |
|
11
|
|
|
use src\pdodatabase\elementos\NombreColumnaJoin; |
|
12
|
|
|
use src\pdodatabase\elementos\Tabla; |
|
13
|
|
|
use src\pdodatabase\elementos\TipoDeJoin; |
|
14
|
|
|
use src\pdodatabase\elementos\ValidadorDeParametrosWhereAndOthers; |
|
15
|
|
|
use src\pdodatabase\elementos\WhereAnd; |
|
16
|
|
|
use src\pdodatabase\sentencias\select\SentenciaJoinWhere; |
|
17
|
|
|
|
|
18
|
|
|
class JoinWhereAnd implements FactoryClassInterface |
|
19
|
|
|
{ |
|
20
|
|
|
private $_joins = []; |
|
21
|
|
|
|
|
22
|
1 |
|
public function crear(array $array): ConsultaJoinWhere |
|
23
|
|
|
{ |
|
24
|
1 |
|
$conexion = new CrearConexionBaseDeDatos; |
|
25
|
1 |
|
$conexion = $conexion->crear([]); |
|
26
|
|
|
|
|
27
|
1 |
|
$sentencia = new SentenciaJoinWhere( |
|
28
|
1 |
|
new Joins( |
|
29
|
1 |
|
new Tabla($array['tabla']), |
|
30
|
1 |
|
new Campos($array['campos']), |
|
31
|
1 |
|
$this->obtenerJoins($array) |
|
32
|
|
|
), |
|
33
|
1 |
|
new WhereAnd( |
|
34
|
1 |
|
new ValidadorDeParametrosWhereAndOthers($array['where']) |
|
35
|
|
|
) |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
1 |
|
return new ConsultaJoinWhere( |
|
39
|
1 |
|
new EjecutarConsultaConDatos( |
|
40
|
1 |
|
$conexion |
|
41
|
|
|
), |
|
42
|
|
|
$sentencia |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
private function obtenerJoins(array $array): array |
|
47
|
|
|
{ |
|
48
|
1 |
|
foreach ($array['join'] as $value) |
|
49
|
|
|
{ |
|
50
|
1 |
|
array_push($this->_joins, $this->crearJoin($value, $array['tabla'])); |
|
51
|
|
|
|
|
52
|
1 |
|
$this->multilplesJoin($value, $value['tabla']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
return $this->_joins; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
private function crearJoin(array $array, string $tablaPadre): ElementosJoin |
|
59
|
|
|
{ |
|
60
|
1 |
|
return new ElementosJoin( |
|
61
|
1 |
|
new TipoDeJoin($array['tipo']), |
|
62
|
1 |
|
new Tabla($tablaPadre), |
|
63
|
1 |
|
new Tabla($array['tabla']), |
|
64
|
1 |
|
new Campos($array['campos']), |
|
65
|
1 |
|
new NombreColumnaJoin($array['key']) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
private function multilplesJoin(array $value, string $tablaPadre): void |
|
70
|
|
|
{ |
|
71
|
1 |
|
if(isset($value['join'])) |
|
72
|
|
|
{ |
|
73
|
1 |
|
foreach ($value['join'] as $value) |
|
74
|
|
|
{ |
|
75
|
1 |
|
array_push($this->_joins, $this->crearJoin($value, $tablaPadre)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
$this->multilplesJoin($value, $value['tabla']); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |