Skip to content

Instantly share code, notes, and snippets.

@v6ak
Created August 3, 2010 16:18
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 v6ak/506664 to your computer and use it in GitHub Desktop.
Save v6ak/506664 to your computer and use it in GitHub Desktop.
<?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