1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cApiStatCollection extends ItemCollection {
25:
26: 27: 28:
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['stat'], 'idstat');
32: $this->_setItemClass('cApiStat');
33:
34:
35: $this->_setJoinPartner('cApiCategoryArticleCollection');
36: $this->_setJoinPartner('cApiLanguageCollection');
37: $this->_setJoinPartner('cApiClientCollection');
38: }
39:
40: 41: 42: 43: 44: 45: 46: 47:
48: public function trackVisit($iIdCatArt, $iIdLang, $iIdClient) {
49: $oStat = $this->fetchByCatArtAndLang($iIdCatArt, $iIdLang);
50: if (is_object($oStat)) {
51: $oStat->increment();
52: } else {
53: $this->create($iIdCatArt, $iIdLang, $iIdClient);
54: }
55: }
56:
57: 58: 59: 60: 61: 62: 63: 64: 65:
66: public function create($iIdCatArt, $iIdLang, $iIdClient, $iVisited = 1) {
67: $oItem = parent::createNewItem();
68:
69: $oItem->set('visited', (int) $iVisited);
70: $oItem->set('idcatart', (int) $iIdCatArt);
71: $oItem->set('idlang', (int) $iIdLang);
72: $oItem->set('idclient', (int) $iIdClient);
73: $oItem->store();
74:
75: return $oItem;
76: }
77:
78: 79: 80: 81: 82: 83: 84:
85: public function fetchByCatArtAndLang($iIdCatArt, $iIdLang) {
86: $this->select('idcatart=' . (int) $iIdCatArt . ' AND idlang=' . (int) $iIdLang);
87: return $this->next();
88: }
89:
90: 91: 92: 93: 94: 95: 96:
97: public function deleteByCategoryArticleAndLanguage($idcatart, $idlang) {
98: $where = 'idcatart = ' . (int) $idcatart . ' AND idlang = ' . (int) $idlang;
99: return $this->deleteByWhereClause($where);
100: }
101:
102: }
103:
104: 105: 106: 107: 108: 109:
110: class cApiStat extends Item {
111:
112: 113: 114: 115: 116:
117: public function __construct($mId = false) {
118: global $cfg;
119: parent::__construct($cfg['tab']['stat'], 'idstat');
120: $this->setFilters(array(), array());
121: if ($mId !== false) {
122: $this->loadByPrimaryKey($mId);
123: }
124: }
125:
126: public function increment() {
127: $this->set('visited', $this->get('visited') + 1);
128: $this->store();
129: }
130:
131: }
132: