PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/Log/Model/Resource/Customer.php

https://bitbucket.org/mengqing/magento-mirror
PHP | 127 lines | 43 code | 11 blank | 73 comment | 2 complexity | d0417639999cfa08bbb8d764d25f5e20 MD5 | raw file
  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. * Customer log resource
  28. *
  29. * @category Mage
  30. * @package Mage_Log
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Log_Model_Resource_Customer extends Mage_Core_Model_Resource_Db_Abstract
  34. {
  35. /**
  36. * Visitor data table name
  37. *
  38. * @var string
  39. */
  40. protected $_visitorTable;
  41. /**
  42. * Visitor info data table
  43. *
  44. * @var string
  45. */
  46. protected $_visitorInfoTable;
  47. /**
  48. * Customer data table
  49. *
  50. * @var string
  51. */
  52. protected $_customerTable;
  53. /**
  54. * Url info data table
  55. *
  56. * @var string
  57. */
  58. protected $_urlInfoTable;
  59. /**
  60. * Log URL data table name.
  61. *
  62. * @var string
  63. */
  64. protected $_urlTable;
  65. /**
  66. * Log quote data table name.
  67. *
  68. * @var string
  69. */
  70. protected $_quoteTable;
  71. /**
  72. * Resource initialization
  73. */
  74. protected function _construct()
  75. {
  76. $this->_init('log/customer', 'log_id');
  77. $this->_visitorTable = $this->getTable('log/visitor');
  78. $this->_visitorInfoTable = $this->getTable('log/visitor_info');
  79. $this->_urlTable = $this->getTable('log/url_table');
  80. $this->_urlInfoTable = $this->getTable('log/url_info_table');
  81. $this->_customerTable = $this->getTable('log/customer');
  82. $this->_quoteTable = $this->getTable('log/quote_table');
  83. }
  84. /**
  85. * Retrieve select object for load object data
  86. *
  87. * @param string $field
  88. * @param mixed $value
  89. * @param Mage_Log_Model_Customer $object
  90. * @return Varien_Db_Select
  91. */
  92. protected function _getLoadSelect($field, $value, $object)
  93. {
  94. $select = parent::_getLoadSelect($field, $value, $object);
  95. if ($field == 'customer_id') {
  96. // load additional data by last login
  97. $table = $this->getMainTable();
  98. $select
  99. ->joinInner(
  100. array('lvt' => $this->_visitorTable),
  101. "lvt.visitor_id = {$table}.visitor_id",
  102. array('last_visit_at'))
  103. ->joinInner(
  104. array('lvit' => $this->_visitorInfoTable),
  105. 'lvt.visitor_id = lvit.visitor_id',
  106. array('http_referer', 'remote_addr'))
  107. ->joinInner(
  108. array('luit' => $this->_urlInfoTable),
  109. 'luit.url_id = lvt.last_url_id',
  110. array('url'))
  111. ->order("{$table}.login_at DESC")
  112. ->limit(1);
  113. }
  114. return $select;
  115. }
  116. }