**/ class twIf_Widget_Filter { const EMPTY_VALUE = 'twIfFilterUnset'; private $Filters = array (); private $Class = null; private $UUID = ''; // {{{ __construct /** * Create a new filter-widget * * @param string $Class Create filter-widget for this class * * @access friendly * @return void **/ function __construct ($Class, $UUID = '') { if (!class_exists ($Class)) { trigger_error (twIf_i18n::getText ('Class %s does not exist, filter-widget will not work', $Class)); $Class = null; } $this->Class = $Class; $this->UUID = $UUID; } // }}} // {{{ addFilter /** * Append a filter to this widget * * @param string $Caption Caption for this filter * @param string $Field Destination-filed for this filter * @param enum $Type Control-Type of this filter * @param mixed $Default (optional) * @param mixed $Data (optional) TODO! Document/use this ;) * * @access public * @return **/ public function addFilter ($Caption, $Field, $Type, $Default = null, $Data = null) { $Name = 'twIfFilter' . sha1 ($this->UUID . $Field); $this->Filters [$Field] = array ( $Control = twIf_Widget_Control::generateControl ($Type, $Name, $Default), $Caption, $Field, $Type, $Default, $Data, ); if (is_array ($Data)) { $Items = array (self::EMPTY_VALUE => twIf_i18n::getText ('Show all')); foreach ($Data as $k=>$v) $Items [$k] = $v; $Control->setItems ($Items); } } // }}} // {{{ setFilter /** * Set the value for a filter-field * * @param string $Field * @param mixed $Value * * @access public * @return bool **/ public function setFilter ($Field, $Value) { if (!isset ($this->Filters [$Field])) return false; $this->Filters [$Field][0]->setValue ($Value); if ($this->Filters [$Field][0]->hasPostValue ()) $this->Filters [$Field][0]->ignorePostValue (); return true; } // }}} // {{{ generateFilter /** * Generate HTML-Code from this filter-definition * * @access public * @return string **/ public function generateFilter () { // Check if there are any filters defined or return directly if (count ($this->Filters) == 0) return ""; // Start the filter-code $buf = "