1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: 17: 18: 19: 20: 21:
22: class cApiSearchTrackingCollection extends ItemCollection {
23:
24: 25: 26:
27: public function __construct() {
28: global $cfg;
29: parent::__construct($cfg['tab']['search_tracking'], 'idsearchtracking');
30:
31: $this->_setItemClass('cApiSearchTracking');
32: }
33:
34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48:
49: public function create($searchTerm, $searchResults, $timestamp = "", $idclient = 0, $idlang = 0) {
50: $item = $this->createNewItem();
51: $item->set("searchterm", $searchTerm);
52: $item->set("results", $searchResults);
53: $item->set("datesearched", ($timestamp == "") ? date('Y-m-d H:i:s') : $timestamp);
54: $item->set("idclient", ($idclient == 0) ? cRegistry::getClientId() : $idclient);
55: $item->set("idlang", ($idlang == 0) ? cRegistry::getLanguageId() : $idlang);
56:
57: return $item->store();
58: }
59:
60: 61: 62: 63: 64: 65: 66: 67: 68:
69: public function trackSearch($searchTerm, $resultCount) {
70: if (getEffectiveSetting("search", "term_tracking", "on") != "on") {
71: return false;
72: }
73:
74: return $this->create($searchTerm, $resultCount);
75: }
76:
77: 78: 79: 80: 81: 82: 83: 84: 85: 86:
87: public function selectPopularSearchTerms($idclient = 0, $idlang = 0) {
88: return $this->select('idclient=' . (($idclient == 0) ? cRegistry::getClientId() : $idclient) . ' AND idlang=' . (($idlang == 0) ? cRegistry::getLanguageId() : $idlang), 'searchterm', 'COUNT(searchterm) DESC');
89: }
90:
91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102:
103: public function selectSearchTerm($term, $idclient = 0, $idlang = 0) {
104: return $this->select('searchterm=\'' . addslashes($term) . '\' AND idclient=' . (($idclient == 0) ? cRegistry::getClientId() : $idclient) . ' AND idlang=' . (($idlang == 0) ? cRegistry::getLanguageId() : $idlang), '', 'datesearched DESC');
105: }
106:
107: }
108:
109: 110: 111: 112: 113: 114:
115: class cApiSearchTracking extends Item {
116:
117: 118: 119: 120: 121: 122:
123: public function __construct($mId = false) {
124: global $cfg;
125:
126: parent::__construct($cfg['tab']['search_tracking'], 'idsearchtracking');
127: $this->setFilters(array(
128: 'addslashes'
129: ), array(
130: 'stripslashes'
131: ));
132:
133: if ($mId !== false) {
134: $this->loadByPrimaryKey($mId);
135: }
136: }
137:
138: }
139: