@@ -82,10 +82,12 @@ public function render()
8282 $ args ['value ' ] = '' ;
8383 $ args ['text ' ] = '' ;
8484 } else {
85- foreach ($ args ['items ' ] as $ item ) {
86- if ($ item ['value ' ] == $ args ['value ' ]) {
87- $ args ['text ' ] = $ item ['text ' ];
88- }
85+ $ selectedItem = self ::getSelectedItem ($ args ['items ' ], $ args ['value ' ]);
86+ if ($ selectedItem ) {
87+ $ args ['text ' ] = $ selectedItem ['text ' ];
88+ } else {
89+ $ args ['value ' ] = '' ;
90+ $ args ['text ' ] = '' ;
8991 }
9092 }
9193
@@ -98,4 +100,57 @@ public function render()
98100
99101 return View::make ('board::components/UIObjects/DesignSelect/designSelect ' , $ args )->render ();
100102 }
103+
104+ private static function getSelectedItem ($ items , $ selectedValue )
105+ {
106+ foreach ($ items as $ item ) {
107+ if ($ item ['value ' ] == $ selectedValue ) {
108+ return [
109+ 'value ' => $ item ['value ' ],
110+ 'text ' => $ item ['text ' ]
111+ ];
112+ }
113+
114+ if (self ::hasChildren ($ item )) {
115+ $ selectedItem = self ::getSelectedItem (self ::getChildren ($ item ), $ selectedValue );
116+ if ($ selectedItem ) {
117+ return $ selectedItem ;
118+ }
119+ }
120+ }
121+
122+ return false ;
123+ }
124+
125+ /**
126+ * @param array $item
127+ * @return boolean
128+ */
129+ public static function hasChildren ($ item )
130+ {
131+ return array_has ($ item , 'children ' );
132+ }
133+
134+ /**
135+ * @param array $item
136+ * @return array
137+ */
138+ public static function getChildren ($ item )
139+ {
140+ if (array_has ($ item , 'children ' )) {
141+ return array_get ($ item , 'children ' );
142+ }
143+
144+ return [];
145+ }
146+
147+ public static function renderList ($ items , $ value = null )
148+ {
149+ $ args = [
150+ 'items ' => $ items ,
151+ 'selectedItemValue ' => $ value
152+ ];
153+
154+ return View::make ('board::components/UIObjects/DesignSelect/designSelectItem ' , $ args )->render ();
155+ }
101156}
0 commit comments