1: <?php
 2: 
 3:  4:  5:  6: 
 7: 
 8: namespace Nette\Forms\Controls;
 9: 
10: use Nette;
11: 
12: 
13: 14: 15: 
16: class MultiSelectBox extends MultiChoiceControl
17: {
18:     
19:     private $options = array();
20: 
21: 
22:     23: 24: 25: 
26:     public function setItems(array $items, $useKeys = TRUE)
27:     {
28:         if (!$useKeys) {
29:             $res = array();
30:             foreach ($items as $key => $value) {
31:                 unset($items[$key]);
32:                 if (is_array($value)) {
33:                     foreach ($value as $val) {
34:                         $res[$key][(string) $val] = $val;
35:                     }
36:                 } else {
37:                     $res[(string) $value] = $value;
38:                 }
39:             }
40:             $items = $res;
41:         }
42:         $this->options = $items;
43:         return parent::setItems(Nette\Utils\Arrays::flatten($items, TRUE));
44:     }
45: 
46: 
47:     48: 49: 50: 
51:     public function getControl()
52:     {
53:         $items = array();
54:         foreach ($this->options as $key => $value) {
55:             $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value);
56:         }
57: 
58:         return Nette\Forms\Helpers::createSelectBox(
59:             $items,
60:             array(
61:                 'selected?' => $this->value,
62:                 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL,
63:             )
64:         )->addAttributes(parent::getControl()->attrs)->multiple(TRUE);
65:     }
66: 
67: }
68: