Add Controllers from local project
Browse files
controllers/controller_category.php
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
require_once __DIR__ . "../../config/DataAccess.php";
|
| 3 |
+
require_once __DIR__ . "../../models/Category.php";
|
| 4 |
+
|
| 5 |
+
class ControllerCategoria
|
| 6 |
+
{
|
| 7 |
+
private $queyAll;
|
| 8 |
+
private $listCategorys;
|
| 9 |
+
|
| 10 |
+
public function __construct()
|
| 11 |
+
{
|
| 12 |
+
$this->listCategorys = array();
|
| 13 |
+
$this->queyAll = "SELECT * FROM categoria;";
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
public function getAllCategories() : array
|
| 17 |
+
{
|
| 18 |
+
$this->listCategorys = array();
|
| 19 |
+
try {
|
| 20 |
+
$acces = new DataAccess();
|
| 21 |
+
$results = $acces->executeQueryGet($this->queyAll);
|
| 22 |
+
|
| 23 |
+
if (!$results->num_rows) {
|
| 24 |
+
return ["message" => "Sin categorias"];
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
while ($row = $results->fetch_assoc()) {
|
| 28 |
+
array_push($this->listCategorys, new Category($row["id_categoria"], $row["nombre_categoria"]));
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
$acces->closeConection();
|
| 32 |
+
$acces = null;
|
| 33 |
+
return $this->listCategorys;
|
| 34 |
+
} catch (\Throwable $th) {
|
| 35 |
+
return ["message" => "Error optener los datos"];
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
?>
|
controllers/controller_galery.php
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
require_once __DIR__ . "../../config/DataAccess.php";
|
| 3 |
+
require_once __DIR__ . "../../models/ImageGalery.php";
|
| 4 |
+
|
| 5 |
+
class ControllerGaleria
|
| 6 |
+
{
|
| 7 |
+
private $listImages;
|
| 8 |
+
private $queryImages;
|
| 9 |
+
|
| 10 |
+
public function __construct()
|
| 11 |
+
{
|
| 12 |
+
$this->listImages = array();
|
| 13 |
+
$this->queryImages = "SELECT id_imagen, url_imagen, nombre_lugar FROM galeria_lugar";
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
public function getGalery($id_place) : array
|
| 17 |
+
{
|
| 18 |
+
$this->queryImages = "$this->queryImages WHERE id_lugar = $id_place;";
|
| 19 |
+
$this->listImages = array();
|
| 20 |
+
try {
|
| 21 |
+
$acc = new DataAccess();
|
| 22 |
+
$results = $acc->executeQueryGet($this->queryImages);
|
| 23 |
+
|
| 24 |
+
if (!$results->num_rows) {
|
| 25 |
+
return ["message" => "No data"];
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
while ($row = $results->fetch_assoc()) {
|
| 29 |
+
array_push($this->listImages, new ImageGalery($row["id_imagen"], $row["url_imagen"], $row["nombre_lugar"]));
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
$acc->closeConection();
|
| 33 |
+
$acc = null;
|
| 34 |
+
return $this->listImages;
|
| 35 |
+
} catch (\Throwable $th) {
|
| 36 |
+
return ["message" => "Error al optener los datos"];
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
controllers/controller_locate.php
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
require_once __DIR__ . "../../config/DataAccess.php";
|
| 3 |
+
require_once __DIR__ . "../../models/Locate.php";
|
| 4 |
+
|
| 5 |
+
class ControllerLocate
|
| 6 |
+
{
|
| 7 |
+
private $queryLocate;
|
| 8 |
+
|
| 9 |
+
public function __construct()
|
| 10 |
+
{
|
| 11 |
+
$this->queryLocate = "SELECT latitud, altitud, longitud FROM lugar_turistico";
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
public function getPlaceLocate($id_place)
|
| 15 |
+
{
|
| 16 |
+
$this->queryLocate = "$this->queryLocate WHERE id_lugar = $id_place;";
|
| 17 |
+
try {
|
| 18 |
+
$conAcc = new DataAccess();
|
| 19 |
+
$results = $conAcc->executeQueryGet($this->queryLocate);
|
| 20 |
+
|
| 21 |
+
if (!$results->num_rows) {
|
| 22 |
+
return ["message" => "Localizacion no disponible"];
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
$row = $results->fetch_assoc();
|
| 26 |
+
|
| 27 |
+
$arrLocate = [new Locate($row["latitud"], $row["altitud"], $row["longitud"])];
|
| 28 |
+
|
| 29 |
+
$conAcc->closeConection();
|
| 30 |
+
$conAcc = null;
|
| 31 |
+
return $arrLocate;
|
| 32 |
+
} catch (\Throwable $th) {
|
| 33 |
+
return ["message" => "Error al optener informacion"];
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
}
|
controllers/controller_place.php
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
require_once __DIR__ . "../../config/DataAccess.php";
|
| 3 |
+
require_once __DIR__ . "../../models/Place.php";
|
| 4 |
+
require_once __DIR__ . "../../models/Trasnport.php";
|
| 5 |
+
require_once __DIR__ . "../../models/Category.php";
|
| 6 |
+
require_once __DIR__ . "../../models/DetailsPlace.php";
|
| 7 |
+
|
| 8 |
+
class ControllerPlace
|
| 9 |
+
{
|
| 10 |
+
private $listPlaces;
|
| 11 |
+
private $queryListPlaces;
|
| 12 |
+
private $queryDetailsPlace;
|
| 13 |
+
private $details;
|
| 14 |
+
|
| 15 |
+
public function __construct()
|
| 16 |
+
{
|
| 17 |
+
$this->listPlaces = array();
|
| 18 |
+
$this->details = array();
|
| 19 |
+
$this->queryListPlaces = "SELECT * FROM lista_lugares;";
|
| 20 |
+
$this->queryDetailsPlace = "SELECT * FROM detalles_lugar";
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
public function getListPlaces()
|
| 24 |
+
{
|
| 25 |
+
$this->listPlaces = array();
|
| 26 |
+
try {
|
| 27 |
+
$acData = new DataAccess();
|
| 28 |
+
$results = $acData->executeQueryGet($this->queryListPlaces);
|
| 29 |
+
|
| 30 |
+
if (!$results->num_rows) {
|
| 31 |
+
return ["message" => "Sin datos de lugares"];
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
while ($row = $results->fetch_assoc()) {
|
| 35 |
+
$idLugar = $row["id_lugar"];
|
| 36 |
+
|
| 37 |
+
if (!isset($this->listPlaces[$idLugar])) {
|
| 38 |
+
$this->listPlaces[$idLugar] = new Place($idLugar, $row["nombre_lugar"], $row["portada"]);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
$nombreCategoria = $row["nombre_categoria"];
|
| 42 |
+
|
| 43 |
+
if (!$this->listPlaces[$idLugar]->isExistCategory($nombreCategoria)) {
|
| 44 |
+
$this->listPlaces[$idLugar]->addCategory(new Category(false, $nombreCategoria));
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
$nombreTransporte = $row["nombre_vehiculo"];
|
| 48 |
+
|
| 49 |
+
if (!$this->listPlaces[$idLugar]->isExistTransports($nombreTransporte)) {
|
| 50 |
+
$this->listPlaces[$idLugar]->addTransport(new Transport($nombreTransporte, $row["tiempo_estimado"]));
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
$acData->closeConection();
|
| 55 |
+
$acData = null;
|
| 56 |
+
|
| 57 |
+
$resPlace = array();
|
| 58 |
+
|
| 59 |
+
foreach ($this->listPlaces as $place) {
|
| 60 |
+
array_push($resPlace, $place->getRawPlace());
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
return $resPlace;
|
| 64 |
+
} catch (Exception $th) {
|
| 65 |
+
return ["message" => "Fallo en optener los datos " . $th->getMessage()];
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
public function getDetailsPlace($idPlace)
|
| 70 |
+
{
|
| 71 |
+
$this->queryDetailsPlace = "$this->queryDetailsPlace WHERE id_lugar = $idPlace;";
|
| 72 |
+
$isCreateObjDetail = false;
|
| 73 |
+
try {
|
| 74 |
+
$acData = new DataAccess();
|
| 75 |
+
$results = $acData->executeQueryGet($this->queryDetailsPlace);
|
| 76 |
+
|
| 77 |
+
if (!$results->num_rows) {
|
| 78 |
+
return ["message" => "Sin detalles del lugar"];
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
while ($row = $results->fetch_assoc()) {
|
| 82 |
+
if (!$isCreateObjDetail) {
|
| 83 |
+
$this->details = new DetailsPlace($row["descripcion"], $row["descripcion_flora_fauna"], $row["tiempo_ideal"], $row["presupuesto_estimado"], $row["nombre_localidad"], $row["superfice_estimada"], $row["protegido"], $row["cobran"]);
|
| 84 |
+
$isCreateObjDetail = true;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
$medida_ambiental = $row["nombre_medida_ambiental"];
|
| 88 |
+
if (!$this->details->isThereEnvironmentalMeasure($medida_ambiental) && $medida_ambiental!=null) {
|
| 89 |
+
$this->details->addEnvironmentalMeasure($medida_ambiental);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
$medida_seguridad = $row["nombre_medida_seguridad"];
|
| 93 |
+
if (!$this->details->isThereSecurityMeasure($medida_seguridad) && $medida_seguridad != null) {
|
| 94 |
+
$this->details->addSecurityMeasure($medida_seguridad);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
$estacion = $row["nombre_estacion"];
|
| 98 |
+
if (!$this->details->isThereSeason($estacion) && $estacion != null) {
|
| 99 |
+
$this->details->addSeaon($estacion);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
$actividad = $row["nombre_actividad"];
|
| 103 |
+
if (!$this->details->isThereActivity($actividad) && $actividad != null) {
|
| 104 |
+
$this->details->addActivity($actividad);
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
$acData->closeConection();
|
| 109 |
+
$acData = null;
|
| 110 |
+
return $this->details->getRawDetails();
|
| 111 |
+
} catch (Exception $th) {
|
| 112 |
+
return ["message" => "Fallo al optener los datos " . $th->getMessage()];
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
}
|