PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/MXWest/magento-ce-1.5.1.0
PHP | 121 lines | 37 code | 13 blank | 71 comment | 0 complexity | 15b7f4c8d38b0a2d6a36694074ec3387 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  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) 2010 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_Mysql4_Customer
  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. * Database read connection
  73. *
  74. * @var Zend_Db_Adapter_Abstract
  75. */
  76. protected $_read;
  77. /**
  78. * Database write connection
  79. *
  80. * @var Zend_Db_Adapter_Abstract
  81. */
  82. protected $_write;
  83. public function __construct()
  84. {
  85. $resource = Mage::getSingleton('core/resource');
  86. $this->_visitorTable = $resource->getTableName('log/visitor');
  87. $this->_visitorInfoTable= $resource->getTableName('log/visitor_info');
  88. $this->_urlTable = $resource->getTableName('log/url_table');
  89. $this->_urlInfoTable = $resource->getTableName('log/url_info_table');
  90. $this->_customerTable = $resource->getTableName('log/customer');
  91. $this->_quoteTable = $resource->getTableName('log/quote_table');
  92. $this->_read = $resource->getConnection('log_read');
  93. $this->_write = $resource->getConnection('log_write');
  94. }
  95. public function load($object, $customerId)
  96. {
  97. $select = $this->_read->select();
  98. $select->from($this->_customerTable, array('login_at', 'logout_at'))
  99. ->joinInner($this->_visitorTable, $this->_visitorTable.'.visitor_id='.$this->_customerTable.'.visitor_id', array('last_visit_at'))
  100. ->joinInner($this->_visitorInfoTable, $this->_visitorTable.'.visitor_id='.$this->_visitorInfoTable.'.visitor_id', array('http_referer', 'remote_addr'))
  101. ->joinInner($this->_urlInfoTable, $this->_urlInfoTable.'.url_id='.$this->_visitorTable.'.last_url_id', array('url'))
  102. ->where($this->_read->quoteInto($this->_customerTable.'.customer_id=?', $customerId))
  103. ->order($this->_customerTable.'.login_at desc')
  104. ->limit(1);
  105. $object->setData($this->_read->fetchRow($select));
  106. return $object;
  107. }
  108. }