1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cApiStatCollection extends ItemCollection {
24:
25: 26: 27:
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['stat'], 'idstat');
31: $this->_setItemClass('cApiStat');
32:
33:
34: $this->_setJoinPartner('cApiCategoryArticleCollection');
35: $this->_setJoinPartner('cApiLanguageCollection');
36: $this->_setJoinPartner('cApiClientCollection');
37: }
38:
39: 40: 41: 42: 43: 44: 45: 46:
47: public function trackVisit($iIdCatArt, $iIdLang, $iIdClient) {
48: $oStat = $this->fetchByCatArtAndLang($iIdCatArt, $iIdLang);
49: if (is_object($oStat)) {
50: $oStat->increment();
51: } else {
52: $this->create($iIdCatArt, $iIdLang, $iIdClient);
53: }
54: }
55:
56: 57: 58: 59: 60: 61: 62: 63: 64:
65: public function create($iIdCatArt, $iIdLang, $iIdClient, $iVisited = 1) {
66: $oItem = $this->createNewItem();
67:
68: $oItem->set('visited', $iVisited);
69: $oItem->set('idcatart', $iIdCatArt);
70: $oItem->set('idlang', $iIdLang);
71: $oItem->set('idclient', $iIdClient);
72: $oItem->store();
73:
74: return $oItem;
75: }
76:
77: 78: 79: 80: 81: 82: 83:
84: public function fetchByCatArtAndLang($iIdCatArt, $iIdLang) {
85: $this->select('idcatart=' . (int) $iIdCatArt . ' AND idlang=' . (int) $iIdLang);
86: return $this->next();
87: }
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:
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: 127: 128:
129: public function increment() {
130: $this->set('visited', $this->get('visited') + 1);
131: $this->store();
132: }
133:
134: 135: 136: 137: 138: 139: 140: 141: 142:
143: public function setField($name, $value, $bSafe = true) {
144: switch ($name) {
145: case 'visited':
146: $value = (int) $value;
147: break;
148: case 'idcatart':
149: $value = (int) $value;
150: break;
151: case 'idlang':
152: $value = (int) $value;
153: break;
154: case 'idclient':
155: $value = (int) $value;
156: break;
157: }
158:
159: return parent::setField($name, $value, $bSafe);
160: }
161:
162: }
163: