1<?php
2/**
3 * Class helper_plugin_bureaucracyau_fieldmultiselect
4 *
5 * Creates a multiselect box
6 */
7class helper_plugin_bureaucracyau_fieldmultiselect extends helper_plugin_bureaucracyau_fieldselect {
8
9    /**
10     * Arguments:
11     *  - cmd
12     *  - label
13     *  - option1|option2|etc
14     *  - ^ (optional)
15     *
16     * @param array $args The tokenized definition, only split at spaces
17     */
18    public function initialize($args) {
19        $this->init($args);
20        $this->opt['args'] = array_map('trim', explode('|',array_shift($args)));
21        $this->standardArgs($args);
22        if (isset($this->opt['value'])) {
23            $this->opt['value'] = array_map('trim', explode(',', $this->opt['value']));
24        } else {
25            $this->opt['value'] = array();
26        }
27    }
28
29    /**
30     * Render the field as XHTML
31     *
32     * Outputs the represented field using the passed Doku_Form object.
33     * Additional parameters (CSS class & HTML name) are passed in $params.
34     *
35     * @params array     $params Additional HTML specific parameters
36     * @params Doku_Form $form   The target Doku_Form object
37     * @params int       $formid unique identifier of the form which contains this field
38     */
39    public function renderfield($params, Doku_Form $form, $formid) {
40        $this->_handlePreload();
41        if(!$form->_infieldset){
42            $form->startFieldset('');
43        }
44        if ($this->error) {
45            $params['class'] = 'bureaucracyau_error';
46        }
47        $params = array_merge($this->opt, $params);
48        $form->addElement(call_user_func_array('form_makeListboxField',
49                                               $this->_parse_tpl(
50                                                   array(
51                                                       '@@NAME@@[]',
52                                                       $params['args'],
53                                                       $this->opt['value'],
54                                                       '@@DISPLAY@@',
55                                                       '@@ID@@',
56                                                       '@@CLASS@@',
57                                                       array('multiple' => 'multiple')
58                                                   ),
59                                                   $params
60                                               )));
61    }
62}