<?php
/*
+--------------------------------------------------------------------------
|   TanyaCMS - Question and Answer Sofware
|   -----------------------------------------------------------------------
|   by fbschool dev team
|   (c) 2011 - 2012 FBSCHOOL
|   http://www.fbschool.com/tanyacms
|   -----------------------------------------------------------------------
|   This is NOT a freeware, use is subject to license terms
|   Support: 13455n@gmail.com
+--------------------------------------------------------------------------
*/


if (!defined('IN_TANYACMS'))
{
	die;
}

class statistic_class extends ASK_MODEL
{
	public function get_user_register_list_by_day($start_time = null, $end_time = null, $valid_email = false)
	{
		if (!$start_time)
		{
			$start_time = strtotime('Last week');
		}
		
		if (!$end_time)
		{
			$end_time = strtotime('Today');
		}		
		
		$data = array();
		
		if ($result = $this->query_all("SELECT COUNT(uid) AS num, FROM_UNIXTIME(reg_time, '%Y-%m-%d') AS reg_date FROM " . get_table('users') . " WHERE reg_time BETWEEN " . $start_time . " AND " . $end_time . " GROUP BY reg_date ASC"))
		{
			foreach ($result AS $key => $val)
			{
				$data[$val['reg_date']] = array(
					'date' => strtotime($val['reg_date']),
					'visits' => $val['num']
				);
			}
		}
		
		return $data;
	}
	
	public function get_new_question_by_day($start_time = null, $end_time = null)
	{		
		if (!$start_time)
		{
			$start_time = strtotime('Last week');
		}
		
		if (!$end_time)
		{
			$end_time = strtotime('Today');
		}		
		
		$data = array();
		
		if ($result = $this->query_all("SELECT COUNT(question_id) AS num, FROM_UNIXTIME(add_time, '%Y-%m-%d') AS add_date FROM " . get_table('question') . " WHERE add_time BETWEEN " . $start_time . " AND " . $end_time . " GROUP BY add_date ASC"))
		{
			foreach ($result AS $key => $val)
			{
				$data[$val['add_date']] = array(
					'date' => strtotime($val['add_date']),
					'visits' => $val['num']
				);
			}
		}
		
		return $data;
	}

	public function get_new_answer_by_day($start_time = null, $end_time = null)
	{		
		if (!$start_time)
		{
			$start_time = strtotime('Last week');
		}
		
		if (!$end_time)
		{
			$end_time = strtotime('Today');
		}		
		
		$data = array();
		
		if ($result = $this->query_all("SELECT COUNT(answer_id) AS num, FROM_UNIXTIME(add_time, '%Y-%m-%d') AS add_date FROM " . get_table('answer') . " WHERE add_time BETWEEN " . $start_time . " AND " . $end_time . " GROUP BY add_date ASC"))
		{
			foreach ($result AS $key => $val)
			{
				$data[$val['add_date']] = array(
					'date' => strtotime($val['add_date']),
					'visits' => $val['num']
				);
			}
		}
		
		return $data;
	}
	
	public function get_new_topic_by_day($start_time = null, $end_time = null)
	{		
		if (!$start_time)
		{
			$start_time = strtotime('Last week');
		}
		
		if (!$end_time)
		{
			$end_time = strtotime('Today');
		}		
		
		$data = array();
		
		if ($result = $this->query_all("SELECT COUNT(topic_id) AS num, FROM_UNIXTIME(add_time, '%Y-%m-%d') AS add_date FROM " . get_table('topic') . " WHERE add_time BETWEEN " . $start_time . " AND " . $end_time . " GROUP BY add_date ASC"))
		{
			foreach ($result AS $key => $val)
			{
				$data[$val['add_date']] = array(
					'date' => strtotime($val['add_date']),
					'visits' => $val['num']
				);
			}
		}
		
		return $data;
	}
}
