From 883f5ffe6609b0caa02244e1a37d7842d3a00890 Mon Sep 17 00:00:00 2001 From: juanfco86 Date: Thu, 6 Oct 2022 11:30:41 +0200 Subject: [PATCH 1/3] 2 tables in 1 view --- config/database.php | 12 ++++++++ controllers/Conductores.php | 15 ++++++++++ controllers/Vehiculos.php | 14 +++++++++ index.php | 13 +++++++++ models/ConductoresModel.php | 23 +++++++++++++++ models/VehiculosModel.php | 21 ++++++++++++++ views/conductores/conductores.php | 47 +++++++++++++++++++++++++++++++ views/vehiculos/vehiculos.php | 47 +++++++++++++++++++++++++++++++ 8 files changed, 192 insertions(+) create mode 100644 config/database.php create mode 100644 controllers/Conductores.php create mode 100644 controllers/Vehiculos.php create mode 100644 index.php create mode 100644 models/ConductoresModel.php create mode 100644 models/VehiculosModel.php create mode 100644 views/conductores/conductores.php create mode 100644 views/vehiculos/vehiculos.php diff --git a/config/database.php b/config/database.php new file mode 100644 index 0000000..fcb6186 --- /dev/null +++ b/config/database.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/controllers/Conductores.php b/controllers/Conductores.php new file mode 100644 index 0000000..5fcbb24 --- /dev/null +++ b/controllers/Conductores.php @@ -0,0 +1,15 @@ +get_conductores(); + + require_once("views/conductores/conductores.php"); + } + } + + +?> \ No newline at end of file diff --git a/controllers/Vehiculos.php b/controllers/Vehiculos.php new file mode 100644 index 0000000..92c4fb3 --- /dev/null +++ b/controllers/Vehiculos.php @@ -0,0 +1,14 @@ +get_vehiculos(); + + require_once("views/vehiculos/vehiculos.php"); + } + } + +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..ebd9b29 --- /dev/null +++ b/index.php @@ -0,0 +1,13 @@ +index(); + + $control2 = new ConductoresController(); + $control2->index(); + +?> \ No newline at end of file diff --git a/models/ConductoresModel.php b/models/ConductoresModel.php new file mode 100644 index 0000000..9bfe056 --- /dev/null +++ b/models/ConductoresModel.php @@ -0,0 +1,23 @@ +db = Conectar::conexion(); + $this->conductores = array(); + } + + public function get_conductores() { + $sql = "SELECT * FROM conductores"; + $resultado = $this->db->query($sql); + while($row = $resultado->fetch_assoc()) { + $this->conductores[] = $row; + } + return $this->conductores; + } + + } + +?> \ No newline at end of file diff --git a/models/VehiculosModel.php b/models/VehiculosModel.php new file mode 100644 index 0000000..88184fb --- /dev/null +++ b/models/VehiculosModel.php @@ -0,0 +1,21 @@ +db = Conectar::conexion(); + $this->vehiculos = array(); + + } + public function get_vehiculos() { + $sql = "SELECT * FROM vehiculos"; + $resultado = $this->db->query($sql); + while($row = $resultado->fetch_assoc()) { + $this->vehiculos[] = $row; + } + return $this->vehiculos; + } + } + +?> \ No newline at end of file diff --git a/views/conductores/conductores.php b/views/conductores/conductores.php new file mode 100644 index 0000000..823cfca --- /dev/null +++ b/views/conductores/conductores.php @@ -0,0 +1,47 @@ + + + + + + + + + <?php echo $data['titulo']; ?> + + + +

+ + Agregar + + + + + + + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> + +
NombreApellidoEdadGeneroDNI
".$dato['nombre']."".$dato['apellido']."".$dato['edad']."".$dato['genero']."".$dato['DNI']."
+ + + \ No newline at end of file diff --git a/views/vehiculos/vehiculos.php b/views/vehiculos/vehiculos.php new file mode 100644 index 0000000..9dbbefd --- /dev/null +++ b/views/vehiculos/vehiculos.php @@ -0,0 +1,47 @@ + + + + + + + + + <?php echo $data['titulo']; ?> + + + +

+ + Agregar + + + + + + + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> + +
MarcaModeloAñoColorPlaca
".$dato['marca']."".$dato['modelo']."".$dato['anio']."".$dato['color']."".$dato['placa']."
+ + + \ No newline at end of file From 085ee68e1188f5f11ab424110fc1a25d66cc3ed5 Mon Sep 17 00:00:00 2001 From: juanfco86 Date: Thu, 6 Oct 2022 16:57:18 +0200 Subject: [PATCH 2/3] mvc vehicules complete, new, routes and modify --- config/config.php | 6 +++ controllers/Vehiculos.php | 59 +++++++++++++++++++++++++ core/routes.php | 28 ++++++++++++ index.php | 29 ++++++++++-- models/VehiculosModel.php | 22 +++++++++ views/vehiculos/vehiculos.php | 6 ++- views/vehiculos/vehiculos_modificar.php | 47 ++++++++++++++++++++ views/vehiculos/vehiculos_nuevo.php | 44 ++++++++++++++++++ 8 files changed, 236 insertions(+), 5 deletions(-) create mode 100644 config/config.php create mode 100644 core/routes.php create mode 100644 views/vehiculos/vehiculos_modificar.php create mode 100644 views/vehiculos/vehiculos_nuevo.php diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..5500506 --- /dev/null +++ b/config/config.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/controllers/Vehiculos.php b/controllers/Vehiculos.php index 92c4fb3..664eaaa 100644 --- a/controllers/Vehiculos.php +++ b/controllers/Vehiculos.php @@ -1,6 +1,10 @@ insertar($marca, $modelo, $anio, $color, $placa); + + $data["titulo"] = "Vehiculos"; + $this->index(); + } + + public function modificar($id) { + $vehiculos = new Vehiculos_model(); + + $data["id"] = $id; + $data["vehiculos"] = $vehiculos->get_vehiculo($id); + $data["titulo"] = "Vehiculos"; + require_once("views/vehiculos/vehiculos_modificar.php"); + } + + public function actualizar() { + + $id = $_POST['id']; + $marca = $_POST['marca']; + $modelo = $_POST['modelo']; + $anio = $_POST['anio']; + $color = $_POST['color']; + $placa = $_POST['placa']; + + $vehiculos = new Vehiculos_model(); + $vehiculos->modificar($id, $marca, $modelo, $anio, $color, $placa); + + $data["titulo"] = "Vehiculos"; + $this->index(); + } + + public function eliminar($id) { + + $vehiculos = new Vehiculos_model(); + $vehiculos->eliminar($id); + + $data["titulo"] = "Vehiculos"; + $this->index(); + } + } ?> \ No newline at end of file diff --git a/core/routes.php b/core/routes.php new file mode 100644 index 0000000..01ac34d --- /dev/null +++ b/core/routes.php @@ -0,0 +1,28 @@ +$accion(); + } else { + $controller->$accion($id); + } + } else { + $controller->ACCION_PRINCIPAL(); + } + } + +?> \ No newline at end of file diff --git a/index.php b/index.php index ebd9b29..68ef036 100644 --- a/index.php +++ b/index.php @@ -1,13 +1,34 @@ index(); + // $control = new VehiculosController(); + // $control->index(); - $control2 = new ConductoresController(); - $control2->index(); + // $control2 = new ConductoresController(); + // $control2->index(); + + if (isset($_GET['c'])) { + $controlador = cargarControlador($_GET['c']); + + if (isset($_GET['a'])) { + if(isset($_GET['id'])) { + cargarAccion($controlador, $_GET['a'], $_GET['id']); + } else { + cargarAccion($controlador, $_GET['a']); + } + } else { + cargarAccion($controlador, ACCION_PRINCIPAL); + } + + } else { + $controlador = cargarControlador(CONTROLADOR_PRINCIPAL); + $accionTmp = ACCION_PRINCIPAL; + $controlador->$accionTmp(); + } ?> \ No newline at end of file diff --git a/models/VehiculosModel.php b/models/VehiculosModel.php index 88184fb..09d0107 100644 --- a/models/VehiculosModel.php +++ b/models/VehiculosModel.php @@ -16,6 +16,28 @@ public function get_vehiculos() { } return $this->vehiculos; } + + public function insertar($marca, $modelo, $anio, $color, $placa) { + $resultado = $this->db->query("INSERT INTO vehiculos (marca, modelo, anio, color, placa) VALUES ('$marca', '$modelo', '$anio', '$color', '$placa')"); + return $this->resultado; + } + + public function modificar($id, $marca, $modelo, $anio, $color, $placa) { + $resultado = $this->db->query("UPDATE vehiculos SET marca='$marca', modelo='$modelo', anio='$anio', color='$color', placa='$placa' WHERE id = '$id'"); + } + + public function eliminar($id) { + $resultado = $this->db->query("DELETE FROM vehiculos WHERE id = '$id'"); + } + + public function get_vehiculo($id) { + $sql = "SELECT * FROM vehiculos WHERE id='$id' LIMIT 1"; + $resultado = $this->db->query($sql); + $row = $resultado->fetch_assoc(); + + return $row; + } + } ?> \ No newline at end of file diff --git a/views/vehiculos/vehiculos.php b/views/vehiculos/vehiculos.php index 9dbbefd..77cf18d 100644 --- a/views/vehiculos/vehiculos.php +++ b/views/vehiculos/vehiculos.php @@ -16,7 +16,7 @@

- Agregar + Agregar @@ -26,6 +26,8 @@ + + @@ -37,6 +39,8 @@ echo ""; echo ""; echo ""; + echo ""; + echo ""; echo ""; } ?> diff --git a/views/vehiculos/vehiculos_modificar.php b/views/vehiculos/vehiculos_modificar.php new file mode 100644 index 0000000..1a84c56 --- /dev/null +++ b/views/vehiculos/vehiculos_modificar.php @@ -0,0 +1,47 @@ + + + + + + + + + <?php // echo $data['titulo']; ?> + + + +

+ + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +

+ + + + + + \ No newline at end of file diff --git a/views/vehiculos/vehiculos_nuevo.php b/views/vehiculos/vehiculos_nuevo.php new file mode 100644 index 0000000..53af727 --- /dev/null +++ b/views/vehiculos/vehiculos_nuevo.php @@ -0,0 +1,44 @@ + + + + + + + + + <?php // echo $data['titulo']; ?> + + + +

+ + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +

+ + + + + + \ No newline at end of file From ee2f292ed0ed729ee10e02b8155dc2abad1f3aac Mon Sep 17 00:00:00 2001 From: juanfco86 Date: Thu, 6 Oct 2022 17:44:40 +0200 Subject: [PATCH 3/3] table conductores add with all functions --- config/config.php | 1 + controllers/Conductores.php | 66 +++++++++++++++++++-- core/routes.php | 13 ++++ index.php | 19 ++++++ models/ConductoresModel.php | 26 +++++++- views/conductores/conductores.php | 10 +++- views/conductores/conductores_modificar.php | 47 +++++++++++++++ views/conductores/conductores_nuevo.php | 44 ++++++++++++++ views/vehiculos/vehiculos.php | 2 + views/vehiculos/vehiculos_nuevo.php | 4 +- 10 files changed, 221 insertions(+), 11 deletions(-) create mode 100644 views/conductores/conductores_modificar.php create mode 100644 views/conductores/conductores_nuevo.php diff --git a/config/config.php b/config/config.php index 5500506..5b85a81 100644 --- a/config/config.php +++ b/config/config.php @@ -1,6 +1,7 @@ \ No newline at end of file diff --git a/controllers/Conductores.php b/controllers/Conductores.php index 5fcbb24..666d0cf 100644 --- a/controllers/Conductores.php +++ b/controllers/Conductores.php @@ -1,15 +1,73 @@ get_conductores(); + $conductores = new Conductores_model(); + $data["tituloC"] = "Conductores"; + $data["conductores"] = $conductores->get_conductores(); require_once("views/conductores/conductores.php"); } + + public function nuevo() { + $data["tituloC"] = "Conductores"; + require_once("views/conductores/conductores_nuevo.php"); + } + + public function guarda() { + + $nombre = $_POST['nombre']; + $apellido = $_POST['apellido']; + $edad = $_POST['edad']; + $genero = $_POST['genero']; + $DNI = $_POST['DNI']; + + $conductores = new Conductores_model(); + $conductores->insertar($nombre, $apellido, $edad, $genero, $DNI); + + //$data["tituloC"] = "Conductores"; + $this->index(); + } + + public function modificar($id) { + $conductores = new Conductores_model(); + + $data["id"] = $id; + $data["conductores"] = $conductores->get_conductor($id); + $data["titulo"] = "Conductores"; + require_once("views/conductores/conductores_modificar.php"); + } + + public function actualizar() { + + $id = $_POST['id']; + $nombre = $_POST['nombre']; + $apellido = $_POST['apellido']; + $edad = $_POST['edad']; + $genero = $_POST['genero']; + $DNI = $_POST['DNI']; + + $conductores = new Conductores_model(); + $conductores->modificar($id, $nombre, $apellido, $edad, $genero, $DNI); + + $data["titulo"] = "Conductores"; + $this->index(); + } + + public function eliminar($id) { + + $conductores = new Conductores_model(); + $conductores->eliminar($id); + + $data["titulo"] = "Conductores"; + $this->index(); + } + } - ?> \ No newline at end of file diff --git a/core/routes.php b/core/routes.php index 01ac34d..fe94023 100644 --- a/core/routes.php +++ b/core/routes.php @@ -13,6 +13,19 @@ function cargarControlador($controlador) { return $control; } + function cargarControlador2($controlador) { + $nombreControlador = ucwords($controlador."Controller"); + $archivoControlador = 'controllers/'.ucwords($controlador).'.php'; + + if(!is_file($archivoControlador)) { + $archivoControlador = 'controllers/'.CONTROLADOR_SECUNDARIO.'.php'; + } + //echo $archivoControlador; + require_once($archivoControlador); + $control = new $nombreControlador(); + return $control; + } + function cargarAccion($controller, $accion, $id = null) { if (isset($accion) && method_exists($controller, $accion)) { if ($id == null) { diff --git a/index.php b/index.php index 68ef036..6cf0e43 100644 --- a/index.php +++ b/index.php @@ -31,4 +31,23 @@ $controlador->$accionTmp(); } + if (isset($_GET['c'])) { + $controlador = cargarControlador2($_GET['c']); + + if (isset($_GET['a'])) { + if(isset($_GET['id'])) { + cargarAccion($controlador, $_GET['a'], $_GET['id']); + } else { + cargarAccion($controlador, $_GET['a']); + } + } else { + cargarAccion($controlador, ACCION_PRINCIPAL); + } + + } else { + $controlador = cargarControlador(CONTROLADOR_SECUNDARIO); + $accionTmp = ACCION_PRINCIPAL; + $controlador->$accionTmp(); + } + ?> \ No newline at end of file diff --git a/models/ConductoresModel.php b/models/ConductoresModel.php index 9bfe056..5db1ba1 100644 --- a/models/ConductoresModel.php +++ b/models/ConductoresModel.php @@ -1,14 +1,13 @@ db = Conectar::conexion(); $this->conductores = array(); - } + } public function get_conductores() { $sql = "SELECT * FROM conductores"; $resultado = $this->db->query($sql); @@ -17,6 +16,27 @@ public function get_conductores() { } return $this->conductores; } + + public function insertar($nombre, $apellido, $edad, $genero, $DNI) { + $resultado = $this->db->query("INSERT INTO conductores (nombre, apellido, edad, genero, DNI) VALUES ('$nombre', '$apellido', '$edad', '$genero', '$DNI')"); + return $resultado; + } + + public function modificar($id, $nombre, $apellido, $edad, $genero, $DNI) { + $resultado = $this->db->query("UPDATE conductores SET nombre='$nombre', apellido='$apellido', edad='$edad', genero='$genero', DNI='$DNI' WHERE id = '$id'"); + } + + public function eliminar($id) { + $resultado = $this->db->query("DELETE FROM conductores WHERE id = '$id'"); + } + + public function get_conductor($id) { + $sql = "SELECT * FROM conductores WHERE id='$id' LIMIT 1"; + $resultado = $this->db->query($sql); + $row = $resultado->fetch_assoc(); + + return $row; + } } diff --git a/views/conductores/conductores.php b/views/conductores/conductores.php index 823cfca..dc462e1 100644 --- a/views/conductores/conductores.php +++ b/views/conductores/conductores.php @@ -10,13 +10,13 @@ - <?php echo $data['titulo']; ?> + <?php // echo $data['titulo']; ?>

- Agregar + Agregar
Año Color PlacaEditarEliminar
".$dato['anio']."".$dato['color']."".$dato['placa']."ModificarEliminar
@@ -26,6 +26,8 @@ + + @@ -37,11 +39,15 @@ echo ""; echo ""; echo ""; + echo ""; + echo ""; echo ""; } ?>
Edad Genero DNIEditarEliminar
".$dato['edad']."".$dato['genero']."".$dato['DNI']."ModificarEliminar
+ + Atras \ No newline at end of file diff --git a/views/conductores/conductores_modificar.php b/views/conductores/conductores_modificar.php new file mode 100644 index 0000000..eb06625 --- /dev/null +++ b/views/conductores/conductores_modificar.php @@ -0,0 +1,47 @@ + + + + + + + + + <?php // echo $data['tituloC']; ?> + + + +

+ +
+ + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +

+ + +
+ + + \ No newline at end of file diff --git a/views/conductores/conductores_nuevo.php b/views/conductores/conductores_nuevo.php new file mode 100644 index 0000000..63cf9df --- /dev/null +++ b/views/conductores/conductores_nuevo.php @@ -0,0 +1,44 @@ + + + + + + + + + <?php echo $data['tituloC']; ?> + + + +

+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +

+ + +
+ + + \ No newline at end of file diff --git a/views/vehiculos/vehiculos.php b/views/vehiculos/vehiculos.php index 77cf18d..8336039 100644 --- a/views/vehiculos/vehiculos.php +++ b/views/vehiculos/vehiculos.php @@ -46,6 +46,8 @@ ?> + + Atras \ No newline at end of file diff --git a/views/vehiculos/vehiculos_nuevo.php b/views/vehiculos/vehiculos_nuevo.php index 53af727..9d18f65 100644 --- a/views/vehiculos/vehiculos_nuevo.php +++ b/views/vehiculos/vehiculos_nuevo.php @@ -10,11 +10,11 @@ - <?php // echo $data['titulo']; ?> + <?php echo $data['titulo']; ?> -

+