forked from ezsystems/ezpublish-kernel
/
Field.php
77 lines (70 loc) · 2.45 KB
/
Field.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* File containing the eZ\Publish\API\Repository\Values\Content\Query\Criterion\Field class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CustomFieldInterface;
/**
* The Field Criterion class.
*
* Provides content filtering based on Fields contents & values.
*/
class Field extends Criterion implements CustomFieldInterface
{
/**
* Custom field definitions to query instead of default field.
*
* @var array
*/
protected $customFields = array();
public function getSpecifications()
{
return array(
new Specifications(Operator::IN, Specifications::FORMAT_ARRAY),
new Specifications(Operator::EQ, Specifications::FORMAT_SINGLE),
new Specifications(Operator::GT, Specifications::FORMAT_SINGLE),
new Specifications(Operator::GTE, Specifications::FORMAT_SINGLE),
new Specifications(Operator::LT, Specifications::FORMAT_SINGLE),
new Specifications(Operator::LTE, Specifications::FORMAT_SINGLE),
new Specifications(Operator::LIKE, Specifications::FORMAT_SINGLE),
new Specifications(Operator::BETWEEN, Specifications::FORMAT_ARRAY, null, 2),
new Specifications(Operator::CONTAINS, Specifications::FORMAT_SINGLE),
);
}
/**
* Set a custom field to query.
*
* Set a custom field to query for a defined field in a defined type.
*
* @param string $type
* @param string $field
* @param string $customField
*/
public function setCustomField($type, $field, $customField)
{
$this->customFields[$type][$field] = $customField;
}
/**
* Return custom field.
*
* If no custom field is set, return null
*
* @param string $type
* @param string $field
*
* @return mixed
*/
public function getCustomField($type, $field)
{
if (!isset($this->customFields[$type]) ||
!isset($this->customFields[$type][$field])) {
return null;
}
return $this->customFields[$type][$field];
}
}