From 660cf60ab4b90fe1d69758450c1039ac63174998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 23 Jun 2019 08:57:22 +0200 Subject: [PATCH] RepositoryBase.updateLang(): unfold subcategories --- src/RepositoryBase.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/RepositoryBase.php b/src/RepositoryBase.php index df0736bf..90cda59e 100644 --- a/src/RepositoryBase.php +++ b/src/RepositoryBase.php @@ -34,9 +34,34 @@ class RepositoryBase { return $data; } + function unfoldCategories (&$data, &$categories=null) { + if ($categories === null) { + $categories = &$data['categories']; + } + + foreach ($categories as $id => $_category) { + $category = &$categories[$id]; + + if (is_array($category) && $category['type'] === 'index') { + foreach ($category['subCategories'] as $subIndex => $_subCategory) { + $subCategory = &$category['subCategories'][$subIndex]; + + $data['categories'][$subCategory['id']] = $subCategory; + $this->unfoldCategories($data, $subCategory); + + $category['subCategories'][$subIndex] = array( + 'id' => $subCategory['id'] + ); + } + } + } + } + function updateLang (&$data, $options) { $lang = array_key_exists('lang', $options) ? $options['lang'] : 'en'; + $this->unfoldCategories($data); + if (!is_array($data['lang'])) { $data['lang'] = array(); } @@ -52,7 +77,7 @@ class RepositoryBase { ); } } - elseif (array_key_exists('name', $category)) { + elseif (is_array($category) && array_key_exists('name', $category)) { if (array_key_exists($lang, $category['name'])) { $name = $category['name'][$lang]; } @@ -67,6 +92,7 @@ class RepositoryBase { $data['categories'][$id]['name'] = array($lang => $name); } + } }