PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/magento/app/code/core/Mage/Log/Model/Resource/Visitor/Collection.php

https://bitbucket.org/jit_bec/shopifine
PHP | 263 lines | 105 code | 25 blank | 133 comment | 11 complexity | d940ee8ed34cdca4b813671d4586a4d3 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Log
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Visitor log collection
  28. *
  29. * @category Mage
  30. * @package Mage_Log
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Log_Model_Resource_Visitor_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
  34. {
  35. /**
  36. * Visitor data table name
  37. *
  38. * @var string
  39. */
  40. protected $_visitorTable;
  41. /**
  42. * Visitor data info table name
  43. *
  44. * @var string
  45. */
  46. protected $_visitorInfoTable;
  47. /**
  48. * Customer data table
  49. *
  50. * @var string
  51. */
  52. protected $_customerTable;
  53. /**
  54. * Log URL data table name.
  55. *
  56. * @var string
  57. */
  58. protected $_urlTable;
  59. /**
  60. * Log URL expanded data table name.
  61. *
  62. * @var string
  63. */
  64. protected $_urlInfoTable;
  65. /**
  66. * Aggregator data table.
  67. *
  68. * @var string
  69. */
  70. protected $_summaryTable;
  71. /**
  72. * Aggregator type data table.
  73. *
  74. * @var string
  75. */
  76. protected $_summaryTypeTable;
  77. /**
  78. * Quote data table.
  79. *
  80. * @var string
  81. */
  82. protected $_quoteTable;
  83. /**
  84. * Online filter used flag
  85. *
  86. * @var bool
  87. */
  88. protected $_isOnlineFilterUsed = false;
  89. /**
  90. * Field map
  91. *
  92. * @var array
  93. */
  94. protected $_fieldMap = array(
  95. 'customer_firstname' => 'customer_firstname_table.value',
  96. 'customer_lastname' => 'customer_lastname_table.value',
  97. 'customer_email' => 'customer_email_table.email',
  98. 'customer_id' => 'customer_table.customer_id',
  99. 'url' => 'url_info_table.url'
  100. );
  101. /**
  102. * Collection resource initialization
  103. */
  104. protected function _construct()
  105. {
  106. $this->_init('log/visitor');
  107. $this->_visitorTable = $this->getTable('log/visitor');
  108. $this->_visitorInfoTable = $this->getTable('log/visitor_info');
  109. $this->_urlTable = $this->getTable('log/url_table');
  110. $this->_urlInfoTable = $this->getTable('log/url_info_table');
  111. $this->_customerTable = $this->getTable('log/customer');
  112. $this->_summaryTable = $this->getTable('log/summary_table');
  113. $this->_summaryTypeTable = $this->getTable('log/summary_type_table');
  114. $this->_quoteTable = $this->getTable('log/quote_table');
  115. }
  116. /**
  117. * Filter for customers only
  118. *
  119. * @return Mage_Log_Model_Resource_Visitor_Collection
  120. */
  121. public function showCustomersOnly()
  122. {
  123. $this->getSelect()
  124. ->where('customer_table.customer_id > 0')
  125. ->group('customer_table.customer_id');
  126. return $this;
  127. }
  128. /**
  129. * Get GROUP BY date format
  130. *
  131. * @deprecated since 1.5.0.0
  132. * @param string $type
  133. * @return string
  134. */
  135. protected function _getGroupByDateFormat($type)
  136. {
  137. switch ($type) {
  138. case 'day':
  139. $format = '%Y-%m-%d';
  140. break;
  141. default:
  142. case 'hour':
  143. $format = '%Y-%m-%d %H';
  144. break;
  145. }
  146. return $format;
  147. }
  148. /**
  149. * Get range by type
  150. *
  151. * @deprecated since 1.5.0.0
  152. * @param string $typeCode
  153. * @return string
  154. */
  155. protected function _getRangeByType($typeCode)
  156. {
  157. switch ($typeCode)
  158. {
  159. case 'day':
  160. $range = 'DAY';
  161. break;
  162. case 'hour':
  163. $range = 'HOUR';
  164. break;
  165. case 'minute':
  166. default:
  167. $range = 'MINUTE';
  168. break;
  169. }
  170. return $range;
  171. }
  172. /**
  173. * Filter by customer ID, as 'type' field does not exist
  174. *
  175. * @param string $fieldName
  176. * @param array $condition
  177. * @return Mage_Log_Model_Resource_Visitor_Collection
  178. */
  179. public function addFieldToFilter($fieldName, $condition = null)
  180. {
  181. if ($fieldName == 'type' && is_array($condition) && isset($condition['eq'])) {
  182. $fieldName = 'customer_id';
  183. if ($condition['eq'] === Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR) {
  184. $condition = array('null' => 1);
  185. } else {
  186. $condition = array('moreq' => 1);
  187. }
  188. }
  189. return parent::addFieldToFilter($this->_getFieldMap($fieldName), $condition);
  190. }
  191. /**
  192. * Return field with table prefix
  193. *
  194. * @param string $fieldName
  195. * @return string
  196. */
  197. protected function _getFieldMap($fieldName)
  198. {
  199. if(isset($this->_fieldMap[$fieldName])) {
  200. return $this->_fieldMap[$fieldName];
  201. } else {
  202. return 'main_table.' . $fieldName;
  203. }
  204. }
  205. /**
  206. * Load data
  207. *
  208. * @param boolean $printQuery
  209. * @param boolean $logQuery
  210. * @return Mage_Core_Model_Resource_Db_Collection_Abstract
  211. */
  212. public function load($printQuery = false, $logQuery = false)
  213. {
  214. if ($this->isLoaded()) {
  215. return $this;
  216. }
  217. Mage::dispatchEvent('log_visitor_collection_load_before', array('collection' => $this));
  218. return parent::load($printQuery, $logQuery);
  219. }
  220. /**
  221. * Return true if online filter used
  222. *
  223. * @return boolean
  224. */
  225. public function getIsOnlineFilterUsed()
  226. {
  227. return $this->_isOnlineFilterUsed;
  228. }
  229. /**
  230. * Filter visitors by specified store ids
  231. *
  232. * @param array|int $storeIds
  233. */
  234. public function addVisitorStoreFilter($storeIds)
  235. {
  236. $this->getSelect()->where('visitor_table.store_id IN (?)', $storeIds);
  237. }
  238. }