1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BEdita, API-first content management framework |
4
|
|
|
* Copyright 2021 ChannelWeb Srl, Chialab Srl |
5
|
|
|
* |
6
|
|
|
* This file is part of BEdita: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Lesser General Public License as published |
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details. |
12
|
|
|
*/ |
13
|
|
|
namespace App\Controller\Model; |
14
|
|
|
|
15
|
|
|
use BEdita\SDK\BEditaClientException; |
16
|
|
|
use Cake\Http\Response; |
17
|
|
|
use Cake\Utility\Hash; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Categories Model Controller: list, add, edit, remove categories |
21
|
|
|
* |
22
|
|
|
* |
23
|
|
|
* @property \App\Controller\Component\CategoriesComponent $Categories |
24
|
|
|
* @property \App\Controller\Component\PropertiesComponent $Properties |
25
|
|
|
*/ |
26
|
|
|
class CategoriesController extends ModelBaseController |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Resource type currently used |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $resourceType = 'categories'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Single resource view exists |
37
|
|
|
* |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
protected $singleView = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritDoc} |
44
|
|
|
*/ |
45
|
|
|
public function initialize(): void |
46
|
|
|
{ |
47
|
|
|
parent::initialize(); |
48
|
|
|
|
49
|
|
|
$this->loadComponent('Categories'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritDoc |
54
|
|
|
*/ |
55
|
|
|
public function index(): ?Response |
56
|
|
|
{ |
57
|
|
|
$this->request->allowMethod(['get']); |
58
|
|
|
|
59
|
|
|
$objectTypes = $this->Schema->objectTypesFeatures()['categorized']; |
60
|
|
|
$objectTypes = array_combine($objectTypes, $objectTypes); |
61
|
|
|
$response = $this->Categories->index(null, $this->request->getQueryParams()); |
62
|
|
|
$resources = $this->Categories->map($response); |
63
|
|
|
$roots = $this->Categories->getAvailableRoots($resources); |
64
|
|
|
$categoriesTree = $this->Categories->tree($resources); |
65
|
|
|
|
66
|
|
|
$this->set(compact('resources', 'roots', 'categoriesTree')); |
67
|
|
|
$this->set('object_types', $objectTypes); |
68
|
|
|
$this->set('meta', (array)$response['meta']); |
69
|
|
|
$this->set('links', (array)$response['links']); |
70
|
|
|
$this->set('schema', $this->Schema->getSchema()); |
71
|
|
|
$this->set('properties', $this->Properties->indexList('categories')); |
72
|
|
|
$this->set('filter', $this->Properties->filterList('categories')); |
73
|
|
|
|
74
|
|
|
return null; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|