1<?php
2/**
3 * Copyright since 2007 PrestaShop SA and Contributors
4 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5 *
6 * NOTICE OF LICENSE
7 *
8 * This source file is subject to the Open Software License (OSL 3.0)
9 * that is bundled with this package in the file LICENSE.md.
10 * It is also available through the world-wide-web at this URL:
11 * https://opensource.org/licenses/OSL-3.0
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@prestashop.com so we can send you a copy immediately.
15 *
16 * DISCLAIMER
17 *
18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
19 * versions in the future. If you wish to customize PrestaShop for your
20 * needs please refer to https://devdocs.prestashop.com/ for more information.
21 *
22 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
23 * @copyright Since 2007 PrestaShop SA and Contributors
24 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
25 */
26
27namespace PrestaShop\PrestaShop\Core\Form\ChoiceProvider;
28
29use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface;
30
31/**
32 * Class TabChoiceProvider provides Tab choices with name values.
33 *
34 * This class is used for choosing Default page when creating employee
35 */
36final class TabChoiceProvider implements FormChoiceProviderInterface
37{
38    /**
39     * @var array
40     */
41    private $tabs;
42
43    /**
44     * @param array $tabs
45     */
46    public function __construct(array $tabs)
47    {
48        $this->tabs = $tabs;
49    }
50
51    /**
52     * {@inheritdoc}
53     */
54    public function getChoices()
55    {
56        $choices = [];
57
58        foreach ($this->tabs as $tab) {
59            if (!empty($tab['children'])) {
60                $choices[$tab['name']] = [];
61
62                foreach ($tab['children'] as $childTab) {
63                    if ($childTab['name']) {
64                        $choices[$tab['name']][$childTab['name']] = $childTab['id_tab'];
65                    }
66                }
67            } else {
68                $choices[$tab['name']] = $tab['id_tab'];
69            }
70        }
71
72        return $choices;
73    }
74}
75