<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Description of dashboard_model
 *
 * @author Igor Ratsun
 */
class dashboard_model  extends CI_Model {
    
    public function get_items($limit = 0, $offset = 0) {
        if (!empty($limit)) {
            $this->db->limit($limit)->offset($offset);
        }
        
        $data = $this->db
                ->select('au.login, co.ip, co.text, co.date, ar.acl_resource_name, aa.acl_action_name')
                ->join('acl_user au', 'au.id_acl_user=co.id_user', 'left')
                ->join('acl_resource ar', 'ar.id_acl_resource = co.id_acl_resource', 'left')
                ->join('acl_action aa', 'aa.id_acl_action = co.id_acl_action', 'left')
                ->order_by('co.date', 'DESC')
                ->get('ciext_observer co')
                ->result_array();
        
        // Prepare data
        $rs = array();
        foreach ($data as $row) {
            $row['time'] = date('H:i:s', strtotime($row['date']));
            $row['date'] = date('d.m.Y', strtotime($row['date']));
            if ($this->rt_user->isAllowed($row['acl_resource_name'], $row['acl_action_name'])) {
                $rs[] = $row;
            }
        }
        
        return $rs;
    }
    
}

