<?php

    require_once(__DIR__.'/../config/DB/Database.php');

    class usuario 
    {
        private $con;

        /* Campos */
        public $user_id;
        public $firstname;
        public $lasname;
        public $user_name;
        public $user_password;
        public $user_email;
        public $date_added;
        public $permiso;

        public function __construct()
        {
            $this->con = Database::GetConnection();
        }

        public function getObject($results)
        {
            $array = [];

            while($row = $results->fetch_assoc())
            {
                $user = new usuario();
                $user->con->close();
                unset($user->con);
                $user->user_id = $row['user_id'];
                $user->firstname = $row['firstname'];
                $user->lastname = $row['lastname'];
                $user->user_name = $row['user_name'];
                $user->user_email = $row['user_email'];
                $user->date_added = $row['date_added'];
                $user->permiso = $row['permiso'];
                array_push($array,$user);
            }

            return $array;
        }

        public function index()
        {
            $st = $this->con->prepare("SELECT * FROM users;");
            $st->execute();
            $results = $st->get_result();
            $users = $this->getObject($results);
            return $users;
        }
    }