1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
<?php
class SpotStatistics {
protected $_db;
private $_cache;
function __construct(SpotDb $db) {
$this->_db = $db;
$this->_cache = new SpotCache($db);
} # ctor
function getSpotCountPerHour($limit, $lastUpdate) {
$resourceid = $this->getResourceid('spotsperhour', $limit);
$rs = $this->_cache->getCache($resourceid, SpotCache::StatisticsData);
if (!$rs || (int) $rs['stamp'] < $lastUpdate) {
$data = $this->_db->getSpotCountPerHour($limit);
$this->_cache->saveCache($resourceid, SpotCache::StatisticsData, '', $data);
} else {
$data = $rs['content'];
} # else
return $data;
} # getSpotCountPerHour
function getSpotCountPerWeekday($limit, $lastUpdate) {
$resourceid = $this->getResourceid('spotsperweekday', $limit);
$rs = $this->_cache->getCache($resourceid, SpotCache::StatisticsData);
if (!$rs || (int) $rs['stamp'] < $lastUpdate) {
$data = $this->_db->getSpotCountPerWeekday($limit);
$this->_cache->saveCache($resourceid, SpotCache::StatisticsData, '', $data);
} else {
$data = $rs['content'];
} # else
return $data;
} # getSpotCountPerWeekday
function getSpotCountPerMonth($limit, $lastUpdate) {
$resourceid = $this->getResourceid('spotspermonth', $limit);
$rs = $this->_cache->getCache($resourceid, SpotCache::StatisticsData);
if (!$rs || (int) $rs['stamp'] < $lastUpdate) {
$data = $this->_db->getSpotCountPerMonth($limit);
$this->_cache->saveCache($resourceid, SpotCache::StatisticsData, '', $data);
} else {
$data = $rs['content'];
} # else
return $data;
} # getSpotCountPerMonth
function getSpotCountPerCategory($limit, $lastUpdate) {
$resourceid = $this->getResourceid('spotspercategory', $limit);
$rs = $this->_cache->getCache($resourceid, SpotCache::StatisticsData);
if (!$rs || (int) $rs['stamp'] < $lastUpdate) {
$data = $this->_db->getSpotCountPerCategory($limit);
$this->_cache->saveCache($resourceid, SpotCache::StatisticsData, '', $data);
} else {
$data = $rs['content'];
} # else
return $data;
} # getSpotCountPerCategory
function getResourceid($name, $limit, $language=false) {
if ($limit == '') {
$resourceid = $name . '.all';
} else {
$resourceid = $name . '.' . $limit;
} # else
if ($language) {
$resourceid .= '.' . $language;
} # if
return $resourceid;
} # getResourceid
} # class SpotStatistics
|