diff --git a/lib/zin/func.php b/lib/zin/func.php index adbb97f388..ac0bec36be 100644 --- a/lib/zin/func.php +++ b/lib/zin/func.php @@ -1823,3 +1823,11 @@ function contactList(): contactList { return createWg('contactList', func_get_args()); } + +/** + * Users widget. + */ +function users(): users +{ + return createWg('users', func_get_args()); +} diff --git a/lib/zin/wg/users/v1.php b/lib/zin/wg/users/v1.php new file mode 100644 index 0000000000..9bd54f5ad1 --- /dev/null +++ b/lib/zin/wg/users/v1.php @@ -0,0 +1,49 @@ + + * @package zin + * @link http://www.zentao.net + */ +namespace zin; + +class users extends wg +{ + protected static array $defineProps = array( + 'name?: string="users[]"', // 控件名称。 + 'value?: string', // 控件默认值。 + 'items?: array', // picker 列表项或表项获取方法。 + 'menu?: array', // picker 附加的菜单选项。 + 'multiple?: boolean|number=false', // picker 是否允许选择多个值,如果指定为数字,则限制多选的数目,默认 `false`。 + 'contactList?: boolean=true' // 是否显示联系人列表。 + ); + + protected static array $defaultProps = array( + 'multiple' => true + ); + + protected function created() + { + $items = $this->prop('items'); + if(!$items) + { + global $app; + $users = $app->control->loadModel('user')->getPairs('noclosed|nodeleted'); + $items = array_map(function($account, $name){return array('text' => $name, 'value' => $account);}, array_keys($users), $users); + $this->setProp('items', $items); + } + } + + protected function build(): wg|array + { + return inputGroup + ( + picker(set($this->getDefinedProps())), + $this->prop('contactList') ? contactList() : null + ); + } +}