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

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

https://bitbucket.org/jit_bec/shopifine
PHP | 142 lines | 60 code | 15 blank | 67 comment | 5 complexity | 3bfc014e21fcbcc28ef3458070b2d1e7 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. * Log Online visitors 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_Online_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
  34. {
  35. /**
  36. * joined fields array
  37. *
  38. * @var array
  39. */
  40. protected $_fields = array();
  41. /**
  42. * Initialize collection model
  43. *
  44. */
  45. protected function _construct()
  46. {
  47. $this->_init('log/visitor_online');
  48. }
  49. /**
  50. * Add Customer data to collection
  51. *
  52. * @return Mage_Log_Model_Resource_Visitor_Online_Collection
  53. */
  54. public function addCustomerData()
  55. {
  56. $customer = Mage::getModel('customer/customer');
  57. // alias => attribute_code
  58. $attributes = array(
  59. 'customer_lastname' => 'lastname',
  60. 'customer_firstname' => 'firstname',
  61. 'customer_email' => 'email'
  62. );
  63. foreach ($attributes as $alias => $attributeCode) {
  64. $attribute = $customer->getAttribute($attributeCode);
  65. /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
  66. if ($attribute->getBackendType() == 'static') {
  67. $tableAlias = 'customer_' . $attribute->getAttributeCode();
  68. $this->getSelect()->joinLeft(
  69. array($tableAlias => $attribute->getBackend()->getTable()),
  70. sprintf('%s.entity_id=main_table.customer_id', $tableAlias),
  71. array($alias => $attribute->getAttributeCode())
  72. );
  73. $this->_fields[$alias] = sprintf('%s.%s', $tableAlias, $attribute->getAttributeCode());
  74. }
  75. else {
  76. $tableAlias = 'customer_' . $attribute->getAttributeCode();
  77. $joinConds = array(
  78. sprintf('%s.entity_id=main_table.customer_id', $tableAlias),
  79. $this->getConnection()->quoteInto($tableAlias . '.attribute_id=?', $attribute->getAttributeId())
  80. );
  81. $this->getSelect()->joinLeft(
  82. array($tableAlias => $attribute->getBackend()->getTable()),
  83. join(' AND ', $joinConds),
  84. array($alias => 'value')
  85. );
  86. $this->_fields[$alias] = sprintf('%s.value', $tableAlias);
  87. }
  88. }
  89. $this->setFlag('has_customer_data', true);
  90. return $this;
  91. }
  92. /**
  93. * Filter collection by specified website(s)
  94. *
  95. * @param int|array $websiteIds
  96. * @return Mage_Log_Model_Resource_Visitor_Online_Collection
  97. */
  98. public function addWebsiteFilter($websiteIds)
  99. {
  100. if ($this->getFlag('has_customer_data')) {
  101. $this->getSelect()
  102. ->where('customer_email.website_id IN (?)', $websiteIds);
  103. }
  104. return $this;
  105. }
  106. /**
  107. * Add field filter to collection
  108. * If $attribute is an array will add OR condition with following format:
  109. * array(
  110. * array('attribute'=>'firstname', 'like'=>'test%'),
  111. * array('attribute'=>'lastname', 'like'=>'test%'),
  112. * )
  113. *
  114. * @see self::_getConditionSql for $condition
  115. *
  116. * @param string $field
  117. * @param null|string|array $condition
  118. * @return Mage_Eav_Model_Entity_Collection_Abstract
  119. */
  120. public function addFieldToFilter($field, $condition = null)
  121. {
  122. if (isset($this->_fields[$field])) {
  123. $field = $this->_fields[$field];
  124. }
  125. return parent::addFieldToFilter($field, $condition);
  126. }
  127. }