/** * Deletes all menu items assigned to the App * * * @param integer $appId * @throws \Exception */ public function deleteAppMenuItems($appId) { /** @var MenuItem[] $menusList */ // 1 - we get all the menus connected to the App $menusList = MenuItem::find()->joinWith('appConnections', FALSE)->where(['app_id' => $appId])->all(); foreach ($menusList as $menuItem) { $menuItem->delete(); } AppConnections::deleteAll(['app_id' => $appId, 'type' => MenuItem::className()]); }
/** * Deletes a menu item and all it's children * * @param $name */ public function delete_menu_item($name) { $menu_item = MenuItem::find()->where(['name' => $name])->asArray()->one(); if (!is_null($menu_item)) { $children = MenuItem::find()->where(['parent_id' => $menu_item['id']])->asArray()->all(); foreach ($children as $child) { $this->delete_menu_item($child['name']); } MenuItem::deleteAll(['id' => $menu_item['id']]); } }