* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute'); /** * Populate form element's attribute conditional * * * @version 1.0.1 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_SwitchIfEqual extends WBDatasource_FormAttribute { /** * configuration parameter * * - switch named attribute like "disabled". used for value lists * - value switch target value * - left compare left side * - right compare right side * @var array */ protected $config = array( 'switch' => 'disabled', 'value' => 'no', 'left' => '', 'right' => '', 'equal' => 'yes' ); /** * get attribute's value * * * * @param mixed $current actual attribute value * @return array */ protected function getAttributeValue($current) { $this->config['equal'] = strtolower($this->config['equal']); if ('yes' == $this->config['equal'] && $this->config['left'] != $this->config['right']) { return $current; } if ('no' == $this->config['equal'] && $this->config['left'] == $this->config['right']) { return $current; } // just the disabled switch if (!is_array($current)) { return $this->config['value']; } // value list foreach ($current as &$c) { $c[$this->config['switch']] = $this->config['value']; } return $current; } }