* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6594 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_CAN_LOAD_FILES_'))
exit;
class StatsVisits extends ModuleGraph
{
private $_html = '';
private $_query = '';
private $_query2 = '';
private $_option;
function __construct()
{
$this->name = 'statsvisits';
$this->tab = 'analytics_stats';
$this->version = 1.0;
$this->author = 'PrestaShop';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Visits and Visitors');
$this->description = $this->l('Display statistics about your visits and visitors.');
}
public function install()
{
return (parent::install() AND $this->registerHook('AdminStatsModules'));
}
public function getTotalVisits()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(c.`id_connections`)
FROM `'._DB_PREFIX_.'connections` c
WHERE c.`date_add` BETWEEN '.ModuleGraph::getDateBetween());
}
public function getTotalGuests()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(DISTINCT c.`id_guest`)
FROM `'._DB_PREFIX_.'connections` c
WHERE c.`date_add` BETWEEN '.ModuleGraph::getDateBetween());
}
public function hookAdminStatsModules($params)
{
$totalVisits = $this->getTotalVisits();
$totalGuests = $this->getTotalGuests();
if (Tools::getValue('export'))
$this->csvExport(array('layers' =>2, 'type' => 'line', 'option' => 3));
$this->_html = '
';
return $this->_html;
}
public function setOption($option, $layers = 1)
{
switch ($option)
{
case 3:
$this->_titles['main'][0] = $this->l('Number of visits and unique visitors');
$this->_titles['main'][1] = $this->l('Visits');
$this->_titles['main'][2] = $this->l('Visitors');
$this->_query[0] = '
SELECT date_add, COUNT(`date_add`) as total
FROM `'._DB_PREFIX_.'connections`
WHERE `date_add` BETWEEN ';
$this->_query[1] = '
SELECT date_add, COUNT(DISTINCT `id_guest`) as total
FROM `'._DB_PREFIX_.'connections`
WHERE `date_add` BETWEEN ';
break;
}
}
protected function getData($layers)
{
$this->setDateGraph($layers, true);
}
protected function setAllTimeValues($layers)
{
for ($i = 0; $i < $layers; $i++)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query[$i].$this->getDate().' GROUP BY LEFT(date_add, 4)');
foreach ($result AS $row)
$this->_values[$i][(int)(substr($row['date_add'], 0, 4))] = (int)($row['total']);
}
}
protected function setYearValues($layers)
{
for ($i = 0; $i < $layers; $i++)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query[$i].$this->getDate().' GROUP BY LEFT(date_add, 7)');
foreach ($result AS $row)
$this->_values[$i][(int)(substr($row['date_add'], 5, 2))] = (int)($row['total']);
}
}
protected function setMonthValues($layers)
{
for ($i = 0; $i < $layers; $i++)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query[$i].$this->getDate().' GROUP BY LEFT(date_add, 10)');
foreach ($result AS $row)
$this->_values[$i][(int)(substr($row['date_add'], 8, 2))] = (int)($row['total']);
}
}
protected function setDayValues($layers)
{
for ($i = 0; $i < $layers; $i++)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query[$i].$this->getDate().' GROUP BY LEFT(date_add, 13)');
foreach ($result AS $row)
$this->_values[$i][(int)(substr($row['date_add'], 11, 2))] = (int)($row['total']);
}
}
}