<?php namespace App\Models;

use CodeIgniter\Database\ConnectionInterface;

class EmpresesModel
{
    protected $db;

    public  function __construct(ConnectionInterface &$db)
    {
        $this->db =& $db;
    }

    /*
     * Get all rows from table
     */
    function getAll($id){
        $builder = $this->db->table('empreses');
        $builder->join('sys_users', 'sys_users.empresa_id_user = empreses.id_empresa', 'left');
        $builder->where('sys_users.id', $id);
        $builder->orderBy('empreses.id_empresa', 'DESC');
        $query = $builder->get()->getResult();
        return $query;
    }

    function getAllAdmin(){
        $builder = $this->db->table('empreses');
        $builder->orderBy('empreses.id_empresa', 'DESC');
        $query = $builder->get()->getResult();
        return $query;
    }

}