<?php
class Acl_role extends MY_Model
{
	const DB_TABLE = 'acl_role';
    const DB_TABLE_PK = 'acl_role_id';

    public function get($offset=0, $limit=0)
    {
    	$q = $this->db->query("SELECT * FROM `acl_role` ORDER BY `role`");
    	return $q->result();
    }

    public function loadByUserID($user_id)
    {
    	$query = $this->db->query("SELECT r.*, r2.user_id, IF(r2.acl_role_id IS NULL, 0, 1) AS `active`
    	                          FROM `acl_role` AS r
    	                          LEFT JOIN `acl_user_role` AS r2 ON r.acl_role_id=r2.acl_role_id AND r2.user_id=?
    	                          GROUP BY r.acl_role_id
    	                          ORDER BY r.`role`",
    	                          array($user_id));

        return $query->result();
    }
}
