@@ -80,8 +80,8 @@ public function setData($data)
8080 /**
8181 * Insert an item
8282 * @param array $item
83- * @param string $before_at (Optional) The reference position for insert
84- * @param string $parent (Optional) The parent if the insert is in a submenu
83+ * @param string $before_at (Optional) The reference position for insert. The 'text' attribute
84+ * @param string $parent (Optional) The node parent if the insert is in a submenu. The 'text' attribute
8585 */
8686 public function insert ($ item , $ before_at = '' , $ parent = '' )
8787 {
@@ -104,7 +104,7 @@ public function insert($item, $before_at = '', $parent = '')
104104 $ pos_parent = array_search ($ parent , array_column ($ this ->arrData , 'text ' ));
105105 if ($ pos_parent === FALSE )
106106 {
107- $ this ->arrData [] = $ item ;
107+ $ this ->a8rrData [] = $ item ;
108108 return ;
109109 }
110110 $ pos = array_search ($ before_at , array_column ($ this ->arrData [$ pos_parent ]['children ' ], 'text ' ));
@@ -116,7 +116,48 @@ public function insert($item, $before_at = '', $parent = '')
116116 $ this ->arrData [$ pos_parent ]['children ' ][] = $ item ;
117117 }
118118 }
119-
119+
120+ /**
121+ * Replace an item (find by text attribute)
122+ * @param array $newItem The new item
123+ * @param string $text The text item for search
124+ */
125+ public function replace (array $ newItem , $ text )
126+ {
127+ $ pos = array_search ($ text , array_column ($ this ->arrData , 'text ' ));
128+ if ($ pos ===FALSE )
129+ {
130+ return FALSE ;
131+ }
132+ $ this ->arrData [$ pos ] = $ newItem ;
133+ return TRUE ;
134+ }
135+
136+ /**
137+ * Remove an item (from top level) by text attribute
138+ * @param string $text Text item
139+ */
140+ public function remove ($ text )
141+ {
142+ $ pos = array_search ($ text , array_column ($ this ->arrData , 'text ' ));
143+ if ($ pos ===FALSE )
144+ {
145+ return FALSE ;
146+ }
147+ array_splice ($ this ->arrData , $ pos , 1 );
148+ return TRUE ;
149+ }
150+ /**
151+ * Get an menu item (from top level)
152+ * @param string $text Text menu to find
153+ * @return mixed Array with the item. Else not found, return NULL
154+ */
155+ public function getItem ($ text )
156+ {
157+ $ pos = array_search ($ text , array_column ($ this ->arrData , 'text ' ));
158+ return ($ pos !==FALSE ) ? $ this ->arrData [$ pos ] : NULL ;
159+ }
160+
120161 /**
121162 * The Html menu
122163 * @return string Html menu
0 commit comments