* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute' , 'WBUser'); /** * Populate form element's value in conditional to user group * * * @version 1.0.0 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_ValueByGroup 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 * - value array or string * @var array */ protected $config = array( 'group' => array(), 'value' => null ); /** * 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 $this->config['value']; } 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; } } return $this->config['value']; } }