PageRenderTime 103ms CodeModel.GetById 60ms app.highlight 7ms RepoModel.GetById 34ms app.codeStats 0ms

/magento/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php

https://bitbucket.org/jit_bec/shopifine
PHP | 166 lines | 97 code | 16 blank | 53 comment | 1 complexity | 3f19e5385ef5cb69f43e15aeef74173f 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) 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/**
 28 * Adminhtml customer grid block
 29 *
 30 * @category   Mage
 31 * @package    Mage_Adminhtml
 32 * @author     Magento Core Team <core@magentocommerce.com>
 33 */
 34class Mage_Adminhtml_Block_Customer_Online_Grid extends Mage_Adminhtml_Block_Widget_Grid
 35{
 36    /**
 37     * Initialize Grid block
 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     * Prepare collection for grid
 51     *
 52     * @return Mage_Adminhtml_Block_Customer_Online_Grid
 53     */
 54    protected function _prepareCollection()
 55    {
 56        $collection = Mage::getModel('log/visitor_online')
 57            ->prepare()
 58            ->getCollection();
 59        /* @var $collection Mage_Log_Model_Mysql4_Visitor_Online_Collection */
 60        $collection->addCustomerData();
 61
 62        $this->setCollection($collection);
 63        parent::_prepareCollection();
 64
 65        return $this;
 66    }
 67
 68    /**
 69     * Prepare columns
 70     *
 71     * @return Mage_Adminhtml_Block_Customer_Online_Grid
 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//            'renderer'  => 'adminhtml/customer_online_grid_renderer_type',
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     * Retrieve Row URL
157     *
158     * @param Mage_Core_Model_Abstract
159     * @return string
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}