From d7c4ce9fb653932c37026672cce7e4fda1e2f3bc Mon Sep 17 00:00:00 2001 From: oriolreverte36 Date: Mon, 18 Nov 2024 01:02:52 +0100 Subject: [PATCH 1/3] feat: added new routes --- docker/database/start-scripts/1-seed.sql | 187 ++++++++--------------- src/app/routes.php | 13 ++ 2 files changed, 75 insertions(+), 125 deletions(-) diff --git a/docker/database/start-scripts/1-seed.sql b/docker/database/start-scripts/1-seed.sql index 52689a81..30a4e040 100644 --- a/docker/database/start-scripts/1-seed.sql +++ b/docker/database/start-scripts/1-seed.sql @@ -1,125 +1,62 @@ ---* Roles, users, contracts and machines -INSERT INTO roles (name) -VALUES ('Administrador'), - ('Gerente'), - ('Trabajador'); -INSERT INTO workers ( - company, - name, - dni, - password, - email, - role_id - ) -VALUES ( - 'TechCorp', - 'Carlos García', - '12345678A', - 'hashedpassword1', - 'carlos.garcia@example.com', - 1 - ), - ( - 'InnovaTech', - 'Ana Martínez', - '23456789B', - 'hashedpassword2', - 'ana.martinez@example.com', - 2 - ), - ( - 'DesignWorks', - 'José Rodríguez', - '34567890C', - 'hashedpassword3', - 'jose.rodriguez@example.com', - 3 - ); -INSERT INTO contracts ( - name, - start_date, - end_date, - invoice_proposed, - invoice_agreed, - invoice_paid - ) -VALUES ( - 'Ayuntamiento de Valencia', - '2021-01-01', - '2021-12-31', - 1000.00, - 900.00, - 900.00 - ), - ( - 'Administración General del Estado', - '2021-01-01', - '2021-12-31', - 2000.00, - 1800.00, - 1800.00 - ), - ( - 'Ayuntamiento de Carlet', - '2021-01-01', - '2021-12-31', - 3000.00, - 2700.00, - 2700.00 - ); -INSERT INTO machines (name, max_basket_size) -VALUES ('Cesta elevadora', 200.00), - ('Plataforma elevadora', 300.00), - ('Tijera elevadora', 400.00); ---* Tree, task and pruning types -INSERT INTO tree_types (family, genus, species) -VALUES ('Fagaceae', 'Quercus', 'Quercus robur'), - ('Pinaceae', 'Pinus', 'Pinus sylvestris'), - ('Sapindaceae', 'Acer', 'Acer campestre'); -INSERT INTO task_types (name) -VALUES ('Abono arbustos'), - ('Podar setos'), - ('Abono setos'); -INSERT INTO pruning_types (name, description) -VALUES ( - 'A', - 'Poda de mantenimiento en árbol tipo A, caduco, de p.c. entre 41/80 cm.' - ), - ( - 'B', - 'Poda de mantenimiento en árbol tipo B, caduco, de p.c. mayor de 81 cm.' - ), - ( - 'C', - 'Poda de mantenimiento en árbol tipo C, perenne, de p.c. entre 41/60 cm.' - ); ---* Points and zones -INSERT INTO points (latitude, longitude) -VALUES (40.416775, -3.703790), - (40.416776, -3.703795), - (40.416777, -3.703800); -INSERT INTO zones (name, postal_code, point_id) -VALUES ('Zona 1', '46001', 1), - ('Zona 2', '46002', 2), - ('Zona 3', '46003', 3); ---* Elements and incidences -INSERT INTO elements (name, zone_id, point_id, tree_type_id) -VALUES ('Árbol 1', 1, 1, 1), - ('Árbol 2', 2, 2, 2), - ('Árbol 3', 3, 3, 3); -INSERT INTO incidences (name, element_id, description) -VALUES ('Rama caída', 1, 'Rama caída en el suelo'), - ('Banco roto', 2, 'Banco roto en el parque'), - ( - 'Fuente sin agua', - 3, - 'Fuente sin agua en el parque' - ), - ( - 'Árbol enfermo', - 1, - 'Árbol con signos de enfermedad' - ), - ('Banco pintado', 2, 'Banco pintado con grafitis'), - ('Fuente con fuga', 3, 'Fuente con fuga de agua'); ---TODO: tasks, routes and works \ No newline at end of file +-- Insert sample roles (Admin, Manager, Worker) +INSERT INTO roles (name) VALUES +('Administrador'), +('Gerente'), +('Trabajador'); + +-- Insert sample workers (Spanish users) +INSERT INTO workers (company, name, dni, password, email, role_id, created_at, updated_at, deleted_at) VALUES +('TechCorp', 'Carlos García', '12345678A', 'hashedpassword1', 'carlos.garcia@example.com', 1, NOW(), NOW(), NULL), -- Admin +('InnovaTech', 'Ana Martínez', '23456789B', 'hashedpassword2', 'ana.martinez@example.com', 2, NOW(), NOW(), NULL), -- Manager +('DesignWorks', 'José Rodríguez', '34567890C', 'hashedpassword3', 'jose.rodriguez@example.com', 3, NOW(), NOW(), NULL); -- Worker + +-- Insert sample tree types +INSERT INTO tree_types (family, genus, species) VALUES +('Fagaceae', 'Quercus', 'Quercus robur'), +('Pinaceae', 'Pinus', 'Pinus sylvestris'), +('Sapindaceae', 'Acer', 'Acer campestre'); + +-- Insert sample contracts +INSERT INTO contracts (name, start_date, end_date, invoice_proposed, invoice_agreed, invoice_paid) VALUES +('Ayuntamiento de Valencia', '2021-01-01', '2021-12-31', 1000.00, 900.00, 900.00), +('Administración General del Estado', '2021-01-01', '2021-12-31', 2000.00, 1800.00, 1800.00), +('Ayuntamiento de Carlet', '2021-01-01', '2021-12-31', 3000.00, 2700.00, 2700.00); + +-- Insert sample task types +INSERT INTO task_types (name) VALUES +('Abono arbustos'), +('Podar setos'), +('Abono setos'); + +-- Insert sample pruning types +INSERT INTO pruning_types (name, description) VALUES +('A', 'Poda de mantenimiento en árbol tipo A, caduco, de p.c. entre 41/80 cm.'), +('B', 'Poda de mantenimiento en árbol tipo B, caduco, de p.c. mayor de 81 cm.'), +('C', 'Poda de mantenimiento en árbol tipo C, perenne, de p.c. entre 41/60 cm.'); + +-- Insert sample points +INSERT INTO points (latitude, longitude) VALUES +(40.416775, -3.703790), +(40.416776, -3.703795), +(40.416777, -3.703800); + +-- Insert sample zones +INSERT INTO zones (name, postal_code, point_id) VALUES +('Zona 1', '46001', 1), +('Zona 2', '46002', 2), +('Zona 3', '46003', 3); + +-- Insert sample elements +INSERT INTO elements (name, zone_id, point_id, tree_type_id) VALUES +('Árbol 1', 1, 1, 1), +('Árbol 2', 2, 2, 2), +('Árbol 3', 3, 3, 3); + +-- Insert sample incidences +INSERT INTO incidences (name, element_id, description) VALUES +('Rama caída', 1, 'Rama caída en el suelo'), +('Banco roto', 2, 'Banco roto en el parque'), +('Fuente sin agua', 3, 'Fuente sin agua en el parque'), +('Árbol enfermo', 1, 'Árbol con signos de enfermedad'), +('Banco pintado', 2, 'Banco pintado con grafitis'), +('Fuente con fuga', 3, 'Fuente con fuga de agua'); diff --git a/src/app/routes.php b/src/app/routes.php index fe2859f1..e59458f6 100644 --- a/src/app/routes.php +++ b/src/app/routes.php @@ -15,6 +15,7 @@ use App\Controllers\CHome; use App\Controllers\CAuth; +use App\Controllers\CIncidence; return $routes = [ "GET" => [ @@ -25,6 +26,18 @@ "/login" => [ "controller" => CAuth::class, "method" => "index" + ], + "/incidence" => [ + "controller" => CIncidence::class, + "method"=> "index" + ], + "/incidence/create" => [ + "controller" => CIncidence::class, + "method"=> "get" + ], + "/incidence/all" => [ + "controller" => CIncidence::class, + "method"=> "findall" ] ], ]; From 5082041cd35c806d73476c2600e10e8a50e0b3e1 Mon Sep 17 00:00:00 2001 From: oriolreverte36 Date: Mon, 18 Nov 2024 01:04:52 +0100 Subject: [PATCH 2/3] feat: new views created to view the incidents and be able to create TODO: the method to create a new incident needs to be updated Added a new get method in the controller to obtain all the elements --- src/app/Controllers/CIncidence.php | 27 +++++++++++++- src/app/Views/Incidence.php | 39 +++++++------------- src/app/Views/Incidence/Create.php | 35 ++++++++++++++++++ src/app/Views/Incidence/SeeAllIncidences.php | 27 ++++++++++++++ 4 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 src/app/Views/Incidence/Create.php create mode 100644 src/app/Views/Incidence/SeeAllIncidences.php diff --git a/src/app/Controllers/CIncidence.php b/src/app/Controllers/CIncidence.php index a30b9e49..bb65b3eb 100644 --- a/src/app/Controllers/CIncidence.php +++ b/src/app/Controllers/CIncidence.php @@ -4,17 +4,42 @@ use App\Core\View; use App\Models\MIncidence; +use App\Models\MElement; class CIncidence { public function index() { - $incidences = MIncidence::findAll(); View::render([ "view" => "Incidence", "title" => "Incidences", "layout" => "MainLayout", + ]); + } + + public function findall() + { + $incidences = MIncidence::findAll(); + + View::render([ + "view" => "Incidence/SeeAllIncidences", + "title" => "Incidences", + "layout" => "MainLayout", "data" => ["incidences" => $incidences] ]); } + + public function get() + { + $elements = MElement::findAll(); + + View::render([ + "view" => "Incidence/Create", + "title" => "Create Incidence", + "layout" => "MainLayout", + "data" => [ + "elements" => $elements, + ] + ]); + } } diff --git a/src/app/Views/Incidence.php b/src/app/Views/Incidence.php index fe525e7a..ddc538f8 100644 --- a/src/app/Views/Incidence.php +++ b/src/app/Views/Incidence.php @@ -1,26 +1,13 @@ -
- - - - - - - - - - - - - - - - - - - - - - - -
IDElement NameNameDescriptionPhotoIncident Date
getId(); ?>name; ?>element()->name; ?>description; ?>photo; ?>getCreatedAt(); ?>
-
\ No newline at end of file +
+

Incidencias

+

Here you can see your incidences 😁

+
+ + + +
+
diff --git a/src/app/Views/Incidence/Create.php b/src/app/Views/Incidence/Create.php new file mode 100644 index 00000000..a47868c8 --- /dev/null +++ b/src/app/Views/Incidence/Create.php @@ -0,0 +1,35 @@ +
+

Crear Incidencia

+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
diff --git a/src/app/Views/Incidence/SeeAllIncidences.php b/src/app/Views/Incidence/SeeAllIncidences.php new file mode 100644 index 00000000..c972d805 --- /dev/null +++ b/src/app/Views/Incidence/SeeAllIncidences.php @@ -0,0 +1,27 @@ +
+

Todas las Incidencias

+ + + + + + + + + + + + + + + + + + + + + + + +
Element NameNameDescriptionPhotoIncident Date
name; ?>element()->name; ?>description; ?>photo ? $incidence->photo : 'No photo'; ?>getCreatedAt(); ?>
+
From 92eac1be0b0d23a3f8d3b274fb976a7fd32541da Mon Sep 17 00:00:00 2001 From: elbacalau <104230251+elbacalau@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:09:19 +0100 Subject: [PATCH 3/3] Update src/app/Views/Incidence/SeeAllIncidences.php Co-authored-by: Hugoo <69076992+0x1026@users.noreply.github.com> --- src/app/Views/Incidence/SeeAllIncidences.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/Views/Incidence/SeeAllIncidences.php b/src/app/Views/Incidence/SeeAllIncidences.php index c972d805..2128fca5 100644 --- a/src/app/Views/Incidence/SeeAllIncidences.php +++ b/src/app/Views/Incidence/SeeAllIncidences.php @@ -18,7 +18,7 @@ name; ?> element()->name; ?> description; ?> - photo ? $incidence->photo : 'No photo'; ?> + photo ?? 'No photo'; ?> getCreatedAt(); ?>