Skip to content

Commit

Permalink
Grid range filter - optimize SQL query when from === to (#1637)
Browse files Browse the repository at this point in the history
* Grid + Range filter - add doc, hints, optimize SQL query when from === to

* Doc-block cleanup
  • Loading branch information
Sekiphp authored Jul 13, 2021
1 parent 0fb1845 commit 061dbe0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
16 changes: 9 additions & 7 deletions app/code/core/Mage/Adminhtml/Block/Widget/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function getCollection()
* Add column to grid
*
* @param string $columnId
* @param array || Varien_Object $column
* @param array $column
* @return Mage_Adminhtml_Block_Widget_Grid
*/
public function addColumn($columnId, $column)
Expand All @@ -313,9 +313,6 @@ public function addColumn($columnId, $column)
->setData($column)
->setGrid($this);
}
/*elseif ($column instanceof Varien_Object) {
$this->_columns[$columnId] = $column;
}*/
else {
throw new Exception(Mage::helper('adminhtml')->__('Wrong column format.'));
}
Expand Down Expand Up @@ -426,7 +423,7 @@ public function getColumnCount()
* Retrieve grid column by column id
*
* @param string $columnId
* @return Varien_Object || false
* @return Mage_Adminhtml_Block_Widget_Grid_Column|false
*/
public function getColumn($columnId)
{
Expand All @@ -439,13 +436,18 @@ public function getColumn($columnId)
/**
* Retrieve all grid columns
*
* @return array
* @return Mage_Adminhtml_Block_Widget_Grid_Column[]
*/
public function getColumns()
{
return $this->_columns;
}

/**
* @param array $data
*
* @return $this
*/
protected function _setFilterValues($data)
{
foreach ($this->getColumns() as $columnId => $column) {
Expand Down Expand Up @@ -1286,7 +1288,7 @@ public function getAbsoluteGridUrl($params = array())
* @param mixed $default
* @return mixed
*/
public function getParam($paramName, $default=null)
public function getParam($paramName, $default = null)
{
$session = Mage::getSingleton('adminhtml/session');
$sessionParamName = $this->getId().$paramName;
Expand Down
3 changes: 3 additions & 0 deletions app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ protected function _getFilterByType()
return $filterClass;
}

/**
* @return Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Abstract|false
*/
public function getFilter()
{
if (!$this->_filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ public function getValue($index=null)
}
return null;
}


public function getCondition()
{
$value = $this->getValue();

if (isset($value['from']) && isset($value['to']) && $value['from'] === $value['to']) {
return ['eq' => $value['from']];
}

return $value;
}

Expand Down

0 comments on commit 061dbe0

Please sign in to comment.