1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the facet builder DateRange parser class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\REST\Common\Input\BaseParser; |
12
|
|
|
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher; |
13
|
|
|
use eZ\Publish\Core\REST\Common\Exceptions; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder\DateRangeFacetBuilder; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Parser for DateRange facet builder. |
18
|
|
|
*/ |
19
|
|
|
class DateRangeParser extends BaseParser |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Parses input structure to a FacetBuilder object. |
23
|
|
|
* |
24
|
|
|
* @param array $data |
25
|
|
|
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher |
26
|
|
|
* |
27
|
|
|
* @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser |
28
|
|
|
* |
29
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder\DateRangeFacetBuilder |
30
|
|
|
*/ |
31
|
|
|
public function parse(array $data, ParsingDispatcher $parsingDispatcher) |
32
|
|
|
{ |
33
|
|
|
throw new Exceptions\Parser('<DateRange> is not supported yet'); |
34
|
|
|
/* @todo: DateRangeFacetBuilder is an abstract class and has no descendants (?) |
35
|
|
|
|
36
|
|
|
if (!array_key_exists('DateRange', $data)) { |
37
|
|
|
throw new Exceptions\Parser('Invalid <DateRange> format'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$selectType = [ |
41
|
|
|
'CREATED' => DateRangeFacetBuilder::CREATED, |
42
|
|
|
'MODIFIED' => DateRangeFacetBuilder::MODIFIED, |
43
|
|
|
'PUBLISHED' => DateRangeFacetBuilder::PUBLISHED, |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
if (isset($data['DateRange']['select'])) { |
47
|
|
|
$type = $data['DateRange']['select']; |
48
|
|
|
|
49
|
|
|
if (!isset($selectType[$type])) { |
50
|
|
|
throw new Exceptions\Parser('<DateRange> unknown type (supported: '.implode (', ', array_keys($selectType)).')'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$data['type'] = DateRangeFacetBuilder::$type; |
54
|
|
|
|
55
|
|
|
unset($data['DateRange']['select']); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return new DateRangeFacetBuilder($data['DateRange']); |
59
|
|
|
*/ |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|