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 = $this->createNewItem();
68:
69: $oItem->set('visited', $iVisited);
70: $oItem->set('idcatart', $iIdCatArt);
71: $oItem->set('idlang', $iIdLang);
72: $oItem->set('idclient', $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: class cApiStat extends Item {
110:
111: 112: 113: 114: 115:
116: public function __construct($mId = false) {
117: global $cfg;
118: parent::__construct($cfg['tab']['stat'], 'idstat');
119: $this->setFilters(array(), array());
120: if ($mId !== false) {
121: $this->loadByPrimaryKey($mId);
122: }
123: }
124:
125: 126: 127:
128: public function increment() {
129: $this->set('visited', $this->get('visited') + 1);
130: $this->store();
131: }
132:
133: 134: 135: 136: 137: 138: 139:
140: public function setField($name, $value, $bSafe = true) {
141: switch ($name) {
142: case 'visited':
143: $value = (int) $value;
144: break;
145: case 'idcatart':
146: $value = (int) $value;
147: break;
148: case 'idlang':
149: $value = (int) $value;
150: break;
151: case 'idclient':
152: $value = (int) $value;
153: break;
154: }
155:
156: return parent::setField($name, $value, $bSafe);
157: }
158:
159: }
160: