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\Grid\Definition\Factory\Monitoring;
28
29use PrestaShop\PrestaShop\Core\Grid\Action\GridActionCollection;
30use PrestaShop\PrestaShop\Core\Grid\Action\Row\RowActionCollection;
31use PrestaShop\PrestaShop\Core\Grid\Action\Row\RowActionCollectionInterface;
32use PrestaShop\PrestaShop\Core\Grid\Action\Row\Type\Category\DeleteCategoryRowAction;
33use PrestaShop\PrestaShop\Core\Grid\Action\Row\Type\LinkRowAction;
34use PrestaShop\PrestaShop\Core\Grid\Action\Type\SimpleGridAction;
35use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
36use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ActionColumn;
37use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\IdentifierColumn;
38use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ToggleColumn;
39use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
40use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory;
41use PrestaShop\PrestaShop\Core\Grid\Filter\Filter;
42use PrestaShop\PrestaShop\Core\Grid\Filter\FilterCollection;
43use PrestaShopBundle\Form\Admin\Type\SearchAndResetType;
44use PrestaShopBundle\Form\Admin\Type\YesAndNoChoiceType;
45use Symfony\Component\Form\Extension\Core\Type\TextType;
46
47/**
48 * Builds Grid definition for empty categories listing
49 */
50final class EmptyCategoryGridDefinitionFactory extends AbstractGridDefinitionFactory
51{
52    public const GRID_ID = 'empty_category';
53
54    /**
55     * {@inheritdoc}
56     */
57    protected function getId()
58    {
59        return self::GRID_ID;
60    }
61
62    /**
63     * {@inheritdoc}
64     */
65    protected function getName()
66    {
67        return $this->trans('List of empty categories', [], 'Admin.Catalog.Feature');
68    }
69
70    /**
71     * {@inheritdoc}
72     */
73    protected function getColumns()
74    {
75        return (new ColumnCollection())
76            ->add(
77                (new IdentifierColumn('id_category'))
78                    ->setName($this->trans('ID', [], 'Admin.Global'))
79                    ->setOptions([
80                        'identifier_field' => 'id_category',
81                    ])
82            )
83            ->add(
84                (new DataColumn('name'))
85                    ->setName($this->trans('Name', [], 'Admin.Global'))
86                    ->setOptions([
87                        'field' => 'name',
88                    ])
89            )
90            ->add(
91                (new DataColumn('description'))
92                    ->setName($this->trans('Description', [], 'Admin.Global'))
93                    ->setOptions([
94                        'field' => 'description',
95                    ])
96            )
97            ->add(
98                (new ToggleColumn('active'))
99                    ->setName($this->trans('Displayed', [], 'Admin.Global'))
100                    ->setOptions([
101                        'field' => 'active',
102                        'primary_field' => 'id_category',
103                        'route' => 'admin_categories_toggle_status',
104                        'route_param_name' => 'categoryId',
105                    ])
106            )
107            ->add(
108                (new ActionColumn('actions'))
109                    ->setName($this->trans('Actions', [], 'Admin.Global'))
110                    ->setOptions([
111                        'actions' => $this->getRowActions(),
112                    ])
113            );
114    }
115
116    /**
117     * {@inheritdoc}
118     */
119    protected function getFilters()
120    {
121        return (new FilterCollection())
122            ->add(
123                (new Filter('id_category', TextType::class))
124                    ->setAssociatedColumn('id_category')
125                    ->setTypeOptions([
126                        'required' => false,
127                        'attr' => [
128                            'placeholder' => $this->trans('Search ID', [], 'Admin.Actions'),
129                        ],
130                    ])
131            )
132            ->add(
133                (new Filter('name', TextType::class))
134                    ->setAssociatedColumn('name')
135                    ->setTypeOptions([
136                        'required' => false,
137                        'attr' => [
138                            'placeholder' => $this->trans('Search name', [], 'Admin.Actions'),
139                        ],
140                    ])
141            )
142            ->add(
143                (new Filter('description', TextType::class))
144                    ->setAssociatedColumn('description')
145                    ->setTypeOptions([
146                        'required' => false,
147                        'attr' => [
148                            'placeholder' => $this->trans('Search description', [], 'Admin.Actions'),
149                        ],
150                    ])
151            )
152            ->add(
153                (new Filter('active', YesAndNoChoiceType::class))
154                    ->setAssociatedColumn('active')
155            )
156            ->add(
157                (new Filter('actions', SearchAndResetType::class))
158                    ->setAssociatedColumn('actions')
159                    ->setTypeOptions([
160                        'reset_route' => 'admin_common_reset_search_by_filter_id',
161                        'reset_route_params' => [
162                            'filterId' => self::GRID_ID,
163                        ],
164                        'redirect_route' => 'admin_monitorings_index',
165                    ])
166                    ->setAssociatedColumn('actions')
167            );
168    }
169
170    /**
171     * {@inheritdoc}
172     */
173    protected function getGridActions()
174    {
175        return (new GridActionCollection())
176            ->add(
177                (new SimpleGridAction('common_refresh_list'))
178                    ->setName($this->trans('Refresh list', [], 'Admin.Advparameters.Feature'))
179                    ->setIcon('refresh')
180            );
181    }
182
183    /**
184     * @return RowActionCollectionInterface
185     */
186    private function getRowActions()
187    {
188        return (new RowActionCollection())
189            ->add(
190                (new LinkRowAction('view'))
191                    ->setName($this->trans('View', [], 'Admin.Actions'))
192                    ->setIcon('zoom_in')
193                    ->setOptions([
194                        'route' => 'admin_categories_index', //@todo: implement view products of this category
195                        'route_param_name' => 'id_category',
196                        'route_param_field' => 'id_category',
197                    ])
198            )
199            ->add(
200                (new LinkRowAction('edit'))
201                    ->setName($this->trans('Edit', [], 'Admin.Actions'))
202                    ->setIcon('edit')
203                    ->setOptions([
204                        'route' => 'admin_categories_edit',
205                        'route_param_name' => 'categoryId',
206                        'route_param_field' => 'id_category',
207                    ])
208            )
209            ->add(
210                (new DeleteCategoryRowAction('delete'))
211                    ->setName($this->trans('Delete', [], 'Admin.Actions'))
212                    ->setIcon('delete')
213                    ->setOptions([
214                        'category_id_field' => 'id_category',
215                        'category_delete_route' => 'admin_categories_delete',
216                    ])
217            );
218    }
219}
220