* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute' , 'WBUser'); /** * Populate form element's value with current user's data * * * @version 1.0.0 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_CurrentUser 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 * @var array */ protected $config = array( 'group' => array() ); /** * 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 $user->getId(); } 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 $user->getId(); } }