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