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