Welcome to mirror list, hosted at ThFree Co, Russian Federation.

XHtmlSelect.php « xhtml « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7a6c72a7c09d009e6e0954207982e858891b4c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

/**
 * PHPPgAdmin6
 */

namespace PHPPgAdmin\XHtml;

/**
 * Class to render select elements.
 */
class XHtmlSelect extends XHtmlElement
{
    public $_data;

    public function __construct($name, $multiple = false, $size = null)
    {
        parent::__construct();

        $this->set_attribute('name', $name);

        if ($multiple) {
            $this->set_attribute('multiple', 'multiple');
        }

        if ($size) {
            $this->set_attribute('size', $size);
        }
    }

    public function set_data(&$data, $delim = ','): void
    {
        switch (\gettype($data)) {
            case 'string':
                $this->_data = \explode($delim, $data);

                break;
            case 'array':
                $this->_data = $data;

                break;

            default:
                break;
        }
    }

    public function fetch()
    {
        if (isset($this->_data) && $this->_data) {
            foreach ($this->_data as $value) {
                $this->add(new XHtmlOption($value));
            }
        }

        return parent::fetch();
    }
}