Skip to content

Instantly share code, notes, and snippets.

@bennoislost
Created May 30, 2013 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennoislost/484b8c36e80977809c1b to your computer and use it in GitHub Desktop.
Save bennoislost/484b8c36e80977809c1b to your computer and use it in GitHub Desktop.
app/code/local/Untitled/Swatchrequest/Block/Adminhtml/Swatchrequest/Grid.php
<?php
/**
* Un.titled
*
* @package Untitled_Swatchrequest
* @copyright Un.titled Copyright (c) 2013 (http://un.titled.co.uk)
*/
class Untitled_Swatchrequest_Block_Adminhtml_Swatchrequest_Grid
extends Mage_Adminhtml_Block_Widget_Grid
{
/**
* Class Group path for Resource Collection
*/
const RESOURCE_COLLECTION = 'untitled_swatchrequest/swatchrequest_collection';
/**
* Prepare base grid
*/
protected function _construct()
{
parent::_construct();
$this->setId('untitled_swatchrequest_swatchrequest');
$this->setDefaultSort('created_at');
/**
* @TODO: Why??
*/
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
}
/**
* Grid URL for AJAX request
*
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current' => true));
}
/**
* Assign Swatchrequest collection to grid block
*
* @return this
*/
protected function _prepareCollection()
{
/**
* @var Untitled_Swatchrequest_Model_Resource_Swatchrequest_Collection
*/
$collection = Mage::getResourceModel(self::RESOURCE_COLLECTION);
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* Required to filter collection
*
* @TODO: really?
* @param $column
* @return $this
*/
protected function _addColumnFilterToCollection($column)
{
return parent::_addColumnFilterToCollection($column);
}
/**
* From Collection define columns and Export types
*
* @return $this
*/
protected function _prepareColumns()
{
$this->addColumn('id', array(
'header' => $this->__('ID'),
'index' => 'entity_id',
'sortable' => true,
'width' => '60px'
));
$this->addColumn('email', array(
'header' => $this->__('Customer Email'),
'index' => 'email',
));
$this->addColumn('created_at', array(
'header' => $this->__('Created'),
'type' =>'datetime',
'index' => 'created_at'
));
$this->addColumn('name', array(
'header' => $this->__('Customer Name'),
'index' => 'name',
));
$this->addColumn('product_name', array(
'header' => $this->__('Product Name'),
'index' => 'product_name',
));
$this->addColumn('address', array(
'header' => $this->__('Address Name'),
'index' => 'address',
));
$this->addColumn('status', array(
'header' => $this->__('Status'),
'width' => '120',
'align' => 'left',
'index' => 'delivered_status',
'type' => 'options',
'options' => array(
0 => $this->__('Not Delivered'),
1 => $this->__('Delivered')
),
'frame_callback' => array(
$this, 'decorateStatus'
)
));
$this->addExportType('*/*/exportCsv', $this->__('CSV'));
$this->addExportType('*/*/exportXml', $this->__('XML'));
return parent::_prepareColumns();
}
/**
* @return Mage_Adminhtml_Block_Widget_Grid
*/
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('swatchrequests');
// delete en mass
$this->getMassactionBlock()->addItem('delete', array(
'label' => $this->__('Delete'),
'url' => $this->getUrl('*/*/deleteMass'),
'confirm' => $this->__('Are you sure?')
));
// update delivered status en mass
$this->getMassactionBlock()->addItem('status', array(
'label' => $this->__('Delivery Status'),
'url' => $this->getUrl('*/*/updateMass'),
'additional' => array(
'visibility' => array(
'name' => 'delivered_status',
'type' => 'select',
'class' => 'required-entry',
'label' => $this->__('Status'),
'values' => array(
array(
'label' => 'Not Delivered',
'value' => 0
),
array(
'label' => 'Delivered',
'value' => 1
)
)
)
)
));
return parent::_prepareMassaction();
}
/**
* Get editable URL
*
* @param $row Row in collection
* @return string
*/
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array(
'id' => $row->getId()
));
}
/**
* Decorate Delivery Status column with a Badge
*
* @param $value Value for $row
* @param $row Row in collection
* @param $column
* @param $isExport
* @return string
*/
public function decorateStatus($value, $row, $column, $isExport)
{
$cell = '<span class="grid-severity-critical"><span>' . $value . '</span></span>';
if($row->getDeliveredStatus() == 1) {
$cell = '<span class="grid-severity-notice"><span>' . $value . '</span></span>';
}
return $cell;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment