1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35:
36: class Mage_Log_Model_Resource_Visitor_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
37: {
38: 39: 40: 41: 42:
43: protected $_visitorTable;
44:
45: 46: 47: 48: 49:
50: protected $_visitorInfoTable;
51:
52: 53: 54: 55: 56:
57: protected $_customerTable;
58:
59: 60: 61: 62: 63:
64: protected $_urlTable;
65:
66: 67: 68: 69: 70:
71: protected $_urlInfoTable;
72:
73: 74: 75: 76: 77:
78: protected $_summaryTable;
79:
80: 81: 82: 83: 84:
85: protected $_summaryTypeTable;
86:
87: 88: 89: 90: 91:
92: protected $_quoteTable;
93:
94: 95: 96: 97: 98:
99: protected $_isOnlineFilterUsed = false;
100:
101: 102: 103: 104: 105:
106: protected $_fieldMap = array(
107: 'customer_firstname' => 'customer_firstname_table.value',
108: 'customer_lastname' => 'customer_lastname_table.value',
109: 'customer_email' => 'customer_email_table.email',
110: 'customer_id' => 'customer_table.customer_id',
111: 'url' => 'url_info_table.url'
112: );
113:
114: 115: 116:
117: protected function _construct()
118: {
119: $this->_init('log/visitor');
120:
121: $this->_visitorTable = $this->getTable('log/visitor');
122: $this->_visitorInfoTable = $this->getTable('log/visitor_info');
123: $this->_urlTable = $this->getTable('log/url_table');
124: $this->_urlInfoTable = $this->getTable('log/url_info_table');
125: $this->_customerTable = $this->getTable('log/customer');
126: $this->_summaryTable = $this->getTable('log/summary_table');
127: $this->_summaryTypeTable = $this->getTable('log/summary_type_table');
128: $this->_quoteTable = $this->getTable('log/quote_table');
129: }
130:
131: 132: 133: 134: 135:
136: public function showCustomersOnly()
137: {
138: $this->getSelect()
139: ->where('customer_table.customer_id > 0')
140: ->group('customer_table.customer_id');
141:
142: return $this;
143: }
144:
145: 146: 147: 148: 149: 150: 151:
152: protected function _getGroupByDateFormat($type)
153: {
154: switch ($type) {
155: case 'day':
156: $format = '%Y-%m-%d';
157: break;
158: default:
159: case 'hour':
160: $format = '%Y-%m-%d %H';
161: break;
162: }
163: return $format;
164: }
165:
166: 167: 168: 169: 170: 171: 172:
173: protected function _getRangeByType($typeCode)
174: {
175: switch ($typeCode)
176: {
177: case 'day':
178: $range = 'DAY';
179: break;
180: case 'hour':
181: $range = 'HOUR';
182: break;
183: case 'minute':
184: default:
185: $range = 'MINUTE';
186: break;
187:
188: }
189:
190: return $range;
191: }
192:
193: 194: 195: 196: 197: 198: 199:
200: public function addFieldToFilter($fieldName, $condition = null)
201: {
202: if ($fieldName == 'type' && is_array($condition) && isset($condition['eq'])) {
203: $fieldName = 'customer_id';
204: if ($condition['eq'] === Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR) {
205: $condition = array('null' => 1);
206: } else {
207: $condition = array('moreq' => 1);
208: }
209: }
210: return parent::addFieldToFilter($this->_getFieldMap($fieldName), $condition);
211: }
212:
213: 214: 215: 216: 217: 218:
219: protected function _getFieldMap($fieldName)
220: {
221: if(isset($this->_fieldMap[$fieldName])) {
222: return $this->_fieldMap[$fieldName];
223: } else {
224: return 'main_table.' . $fieldName;
225: }
226: }
227:
228: 229: 230: 231: 232: 233: 234:
235: public function load($printQuery = false, $logQuery = false)
236: {
237: if ($this->isLoaded()) {
238: return $this;
239: }
240: Mage::dispatchEvent('log_visitor_collection_load_before', array('collection' => $this));
241: return parent::load($printQuery, $logQuery);
242: }
243:
244: 245: 246: 247: 248:
249: public function getIsOnlineFilterUsed()
250: {
251: return $this->_isOnlineFilterUsed;
252: }
253:
254: 255: 256: 257: 258:
259: public function addVisitorStoreFilter($storeIds)
260: {
261: $this->getSelect()->where('visitor_table.store_id IN (?)', $storeIds);
262: }
263: }
264: