forked from netgen/TagsBundle
/
TagId.php
53 lines (48 loc) · 1.71 KB
/
TagId.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
<?php
namespace Netgen\TagsBundle\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;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;
/**
* A criterion that matches content based on tag ID that is located in one of the fields.
*
* Supported operators:
* - IN: matches against a list of tag IDs (with OR operator)
* - EQ: matches against one tag ID
*/
class TagId extends Criterion implements CriterionInterface
{
/**
* Creates a new TagId criterion.
*
* @param int|int[] $value One or more tag IDs that must be matched
* @param string $target Field definition identifier to use
*
* @throws \InvalidArgumentException if a non numeric id is given
* @throws \InvalidArgumentException if the value type doesn't match the operator
*/
public function __construct($value, $target = null)
{
parent::__construct($target, null, $value);
}
public function getSpecifications()
{
return array(
new Specifications(
Operator::IN,
Specifications::FORMAT_ARRAY,
Specifications::TYPE_INTEGER | Specifications::TYPE_STRING
),
new Specifications(
Operator::EQ,
Specifications::FORMAT_SINGLE,
Specifications::TYPE_INTEGER | Specifications::TYPE_STRING
),
);
}
public static function createFromQueryBuilder($target, $operator, $value)
{
return new self($value);
}
}