File size: 1,056 Bytes
dbf1813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require_once __DIR__ . "../../config/DataAccess.php";
require_once __DIR__ . "../../models/Category.php";

class ControllerCategoria
{
    private $queyAll;
    private $listCategorys;

    public function __construct()
    {
        $this->listCategorys = array();
        $this->queyAll = "SELECT * FROM categoria;";
    }

    public function getAllCategories() : array
    {
        $this->listCategorys = array();
        try {
            $acces = new DataAccess();
            $results = $acces->executeQueryGet($this->queyAll);

            if (!$results->num_rows) {
                return ["message" => "Sin categorias"];
            }

            while ($row = $results->fetch_assoc()) {
                array_push($this->listCategorys, new Category($row["id_categoria"], $row["nombre_categoria"]));
            }

            $acces->closeConection();
            $acces = null;
            return $this->listCategorys;
        } catch (\Throwable $th) {
            return ["message" => "Error optener los datos"];
        }
    }
}

?>