Skip to content

Instantly share code, notes, and snippets.

@v6ak
Created Aug 3, 2010
Embed
What would you like to do?
<?php
/**
* Representation of enumerated grid column.
*
* @author Vít Šesták 'v6ak'
* @copyright Copyright (c) 2010 Vít Šesták
* @license New BSD License
* @package Nette\Extras\DataGrid
*/
class EnumColumn extends DataGridColumn{
/** @var array array(value=>label) */
private $values;
/**
* Enum column constructor
* @param string textual caption of this column
* @param array array(enumValue=>label)
*/
public function __construct($caption, $values){
parent::__construct($caption);
$this->values = $values;
}
public function formatContent($value, $data = NULL){
return htmlspecialchars($this->values[$value]);
}
public function applyFilter($value){
if (!$this->hasFilter()){
return;
};
$column = $this->getName();
$this->getDataGrid(true)->dataSource->where('%and', array(array("[$column] = %s", $value)));
}
/**
* Adds selectbox filter using $values from constructor.
* @return IDataGridColumnFilter
*/
public function addDefaultSelectboxFilter(){
return $this->addSelectboxFilter($this->values);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment