1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_Customer_Online_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36: 37: 38: 39:
40: public function __construct()
41: {
42: parent::__construct();
43: $this->setId('onlineGrid');
44: $this->setSaveParametersInSession(true);
45: $this->setDefaultSort('last_activity');
46: $this->setDefaultDir('DESC');
47: }
48:
49: 50: 51: 52: 53:
54: protected function _prepareCollection()
55: {
56: $collection = Mage::getModel('log/visitor_online')
57: ->prepare()
58: ->getCollection();
59:
60: $collection->addCustomerData();
61:
62: $this->setCollection($collection);
63: parent::_prepareCollection();
64:
65: return $this;
66: }
67:
68: 69: 70: 71: 72:
73: protected function _prepareColumns()
74: {
75: $this->addColumn('customer_id', array(
76: 'header' => Mage::helper('customer')->__('ID'),
77: 'width' => '40px',
78: 'align' => 'right',
79: 'type' => 'number',
80: 'default' => Mage::helper('customer')->__('n/a'),
81: 'index' => 'customer_id'
82: ));
83:
84: $this->addColumn('firstname', array(
85: 'header' => Mage::helper('customer')->__('First Name'),
86: 'default' => Mage::helper('customer')->__('Guest'),
87: 'index' => 'customer_firstname'
88: ));
89:
90: $this->addColumn('lastname', array(
91: 'header' => Mage::helper('customer')->__('Last Name'),
92: 'default' => Mage::helper('customer')->__('n/a'),
93: 'index' => 'customer_lastname'
94: ));
95:
96: $this->addColumn('email', array(
97: 'header' => Mage::helper('customer')->__('Email'),
98: 'default' => Mage::helper('customer')->__('n/a'),
99: 'index' => 'customer_email'
100: ));
101:
102: $this->addColumn('ip_address', array(
103: 'header' => Mage::helper('customer')->__('IP Address'),
104: 'default' => Mage::helper('customer')->__('n/a'),
105: 'index' => 'remote_addr',
106: 'renderer' => 'adminhtml/customer_online_grid_renderer_ip',
107: 'filter' => false,
108: 'sort' => false
109: ));
110:
111: $this->addColumn('session_start_time', array(
112: 'header' => Mage::helper('customer')->__('Session Start Time'),
113: 'align' => 'left',
114: 'width' => '200px',
115: 'type' => 'datetime',
116: 'default' => Mage::helper('customer')->__('n/a'),
117: 'index' =>'first_visit_at'
118: ));
119:
120: $this->addColumn('last_activity', array(
121: 'header' => Mage::helper('customer')->__('Last Activity'),
122: 'align' => 'left',
123: 'width' => '200px',
124: 'type' => 'datetime',
125: 'default' => Mage::helper('customer')->__('n/a'),
126: 'index' => 'last_visit_at'
127: ));
128:
129: $typeOptions = array(
130: Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER => Mage::helper('customer')->__('Customer'),
131: Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR => Mage::helper('customer')->__('Visitor'),
132: );
133:
134: $this->addColumn('type', array(
135: 'header' => Mage::helper('customer')->__('Type'),
136: 'index' => 'type',
137: 'type' => 'options',
138: 'options' => $typeOptions,
139:
140: 'index' => 'visitor_type'
141: ));
142:
143: $this->addColumn('last_url', array(
144: 'header' => Mage::helper('customer')->__('Last URL'),
145: 'type' => 'wrapline',
146: 'lineLength' => '60',
147: 'default' => Mage::helper('customer')->__('n/a'),
148: 'renderer' => 'adminhtml/customer_online_grid_renderer_url',
149: 'index' => 'last_url'
150: ));
151:
152: return parent::_prepareColumns();
153: }
154:
155: 156: 157: 158: 159: 160:
161: public function getRowUrl($row)
162: {
163: return (Mage::getSingleton('admin/session')->isAllowed('customer/manage') && $row->getCustomerId())
164: ? $this->getUrl('*/customer/edit', array('id' => $row->getCustomerId())) : '';
165: }
166: }
167: