/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php

https://bitbucket.org/acidel/buykoala · PHP · 204 lines · 144 code · 24 blank · 36 comment · 12 complexity · 9ad73178ef63da419ad5ebc176477536 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_Adminhtml
  23. * @copyright Copyright (c) 2011 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 account form block
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Customer_Edit_Tab_View
  34. extends Mage_Adminhtml_Block_Template
  35. implements Mage_Adminhtml_Block_Widget_Tab_Interface
  36. {
  37. protected $_customer;
  38. protected $_customerLog;
  39. public function getCustomer()
  40. {
  41. if (!$this->_customer) {
  42. $this->_customer = Mage::registry('current_customer');
  43. }
  44. return $this->_customer;
  45. }
  46. public function getGroupName()
  47. {
  48. if ($groupId = $this->getCustomer()->getGroupId()) {
  49. return Mage::getModel('customer/group')
  50. ->load($groupId)
  51. ->getCustomerGroupCode();
  52. }
  53. }
  54. /**
  55. * Load Customer Log model
  56. *
  57. * @return Mage_Log_Model_Customer
  58. */
  59. public function getCustomerLog()
  60. {
  61. if (!$this->_customerLog) {
  62. $this->_customerLog = Mage::getModel('log/customer')
  63. ->loadByCustomer($this->getCustomer()->getId());
  64. }
  65. return $this->_customerLog;
  66. }
  67. public function getCreateDate()
  68. {
  69. $date = Mage::app()->getLocale()->date($this->getCustomer()->getCreatedAtTimestamp());
  70. return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
  71. }
  72. public function getStoreCreateDate()
  73. {
  74. $date = Mage::app()->getLocale()->storeDate(
  75. $this->getCustomer()->getStoreId(),
  76. $this->getCustomer()->getCreatedAtTimestamp(),
  77. true
  78. );
  79. return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
  80. }
  81. public function getStoreCreateDateTimezone()
  82. {
  83. return Mage::app()->getStore($this->getCustomer()->getStoreId())
  84. ->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
  85. }
  86. public function getLastLoginDate()
  87. {
  88. if ($date = $this->getCustomerLog()->getLoginAtTimestamp()) {
  89. $date = Mage::app()->getLocale()->date($date);
  90. return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
  91. }
  92. return Mage::helper('customer')->__('Never');
  93. }
  94. public function getStoreLastLoginDate()
  95. {
  96. if ($date = $this->getCustomerLog()->getLoginAtTimestamp()) {
  97. $date = Mage::app()->getLocale()->storeDate(
  98. $this->getCustomer()->getStoreId(),
  99. $date,
  100. true
  101. );
  102. return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
  103. }
  104. return Mage::helper('customer')->__('Never');
  105. }
  106. public function getStoreLastLoginDateTimezone()
  107. {
  108. return Mage::app()->getStore($this->getCustomer()->getStoreId())
  109. ->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
  110. }
  111. public function getCurrentStatus()
  112. {
  113. $log = $this->getCustomerLog();
  114. if ($log->getLogoutAt() ||
  115. strtotime(now())-strtotime($log->getLastVisitAt())>Mage_Log_Model_Visitor::getOnlineMinutesInterval()*60) {
  116. return Mage::helper('customer')->__('Offline');
  117. }
  118. return Mage::helper('customer')->__('Online');
  119. }
  120. public function getIsConfirmedStatus()
  121. {
  122. $this->getCustomer();
  123. if (!$this->_customer->getConfirmation()) {
  124. return Mage::helper('customer')->__('Confirmed');
  125. }
  126. if ($this->_customer->isConfirmationRequired()) {
  127. return Mage::helper('customer')->__('Not confirmed, cannot login');
  128. }
  129. return Mage::helper('customer')->__('Not confirmed, can login');
  130. }
  131. public function getCreatedInStore()
  132. {
  133. return Mage::app()->getStore($this->getCustomer()->getStoreId())->getName();
  134. }
  135. public function getStoreId()
  136. {
  137. return $this->getCustomer()->getStoreId();
  138. }
  139. public function getBillingAddressHtml()
  140. {
  141. $html = '';
  142. if ($address = $this->getCustomer()->getPrimaryBillingAddress()) {
  143. $html = $address->format('html');
  144. }
  145. else {
  146. $html = Mage::helper('customer')->__('The customer does not have default billing address.');
  147. }
  148. return $html;
  149. }
  150. public function getAccordionHtml()
  151. {
  152. return $this->getChildHtml('accordion');
  153. }
  154. public function getSalesHtml()
  155. {
  156. return $this->getChildHtml('sales');
  157. }
  158. public function getTabLabel()
  159. {
  160. return Mage::helper('customer')->__('Customer View');
  161. }
  162. public function getTabTitle()
  163. {
  164. return Mage::helper('customer')->__('Customer View');
  165. }
  166. public function canShowTab()
  167. {
  168. if (Mage::registry('current_customer')->getId()) {
  169. return true;
  170. }
  171. return false;
  172. }
  173. public function isHidden()
  174. {
  175. if (Mage::registry('current_customer')->getId()) {
  176. return false;
  177. }
  178. return true;
  179. }
  180. }