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

class Dashboard_Model extends CI_Model {

	public function __construct() {

	}

	public function get_all_links($userId, $fromDate, $toDate) {

		$this->db->select('links.ID, links.Text, links.Remark, links.Subdomain, links.PhoneNumber, links.FullLink, COUNT(click_log.LinkID) AS ClickCount');
		$this->db->where('links.UserID', $userId);
		$this->db->where('links.Status', 'Y');
        $this->db->join('click_log', 'click_log.LinkID = links.ID', 'left');
        $this->db->group_by('links.ID');
        $this->db->order_by('ClickCount','desc');

        $q = $this->db->get('links');

        return $q->num_rows() > 0 ? $q->result() : false;
	}

	public function get_all_click_counts($userId, $fromDate, $toDate) {


		$this->db->select('COUNT(*) AS TotalClicks');
		$this->db->where('UserID', $userId);
		$this->db->where('Status','Y');
		$this->db->join('links','links.ID = click_log.LinkID','left');

		$q = $this->db->get('click_log');
		
		return $q->row();
	}
}