* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute' , 'WBUser'); /** * Populate form element's attribute conditional * * * @version 1.0.0 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_SwitchByGroup extends WBDatasource_FormAttribute { /** * configuration parameter * * - group List of groups, negate with ! in front. Only set user id of user in group or not in groups * - switch named attribute like "disabled". used for value lists * - value switch target value * @var array */ protected $config = array( 'group' => array(), 'switch' => 'disabled', 'value' => 'no' ); /** * get attribute's value * * * * @param mixed $current actual attribute value * @return array */ protected function getAttributeValue($current) { $user = WBUser::getCurrent(); if (empty($this->config['group'])) { return $current; } foreach ($this->config['group'] as $g) { $rel = true; if (0 == strncmp('!', $g, 1)) { $rel = false; $g = substr($g, 1); } if ($user->isInGroup($g) !== $rel) { 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; } }