Пример #1
0
 private static function getNavItems()
 {
     if (self::$_navItems === null) {
         $items = Nav::find()->select(['sort_index', 'id', 'parent_nav_id', 'is_deleted'])->where(['is_deleted' => 0])->orderBy(['sort_index' => SORT_ASC])->asArray()->all();
         return self::$_navItems = ArrayHelper::index($items, null, 'parent_nav_id');
     }
     return self::$_navItems;
 }
Пример #2
0
 public function actionDelete($navId)
 {
     $model = Nav::find()->where(['id' => $navId])->one();
     if ($model) {
         Yii::$app->menu->flushCache();
         // check for internal redirects
         $redirectResult = false;
         $redirects = NavItemRedirect::find()->where(['value' => $navId])->asArray()->all();
         foreach ($redirects as $redirect) {
             $navItem = NavItem::find()->where(['nav_item_type' => 3, 'nav_item_type_id' => $redirect['id']])->one();
             $redirectResult = empty(Nav::find()->where(['id' => $navItem->nav_id, 'is_deleted' => 0])->one()) ? $redirectResult : true;
         }
         if ($redirectResult) {
             Yii::$app->response->statusCode = 417;
             return;
         }
         $model->is_deleted = 1;
         foreach (NavItem::find()->where(['nav_id' => $navId])->all() as $navItem) {
             $navItem->setAttribute('alias', date('Y-m-d-H-i') . '-' . $navItem->alias);
             $navItem->update(false);
         }
         return $model->update(false);
     }
 }