|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright 2016 Sourcefabric z.ú. and contributors. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please see the |
|
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright 2016 Sourcefabric z.ú |
|
14
|
|
|
* @license http://www.superdesk.org/license |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace SWP\Bundle\CoreBundle\Matcher; |
|
18
|
|
|
|
|
19
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleInterface; |
|
20
|
|
|
use SWP\Component\Common\Criteria\Criteria; |
|
21
|
|
|
|
|
22
|
|
|
final class ArticleCriteriaMatcher implements ArticleCriteriaMatcherInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function match(ArticleInterface $article, Criteria $criteria) |
|
28
|
|
|
{ |
|
29
|
2 |
|
if ($criteria->has('route')) { |
|
30
|
1 |
|
foreach ($criteria->get('route') as $value) { |
|
31
|
1 |
|
if ($value !== $article->getRoute()->getId()) { |
|
32
|
1 |
|
return false; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
if ($criteria->has('author') && is_array($criteria->get('author'))) { |
|
38
|
1 |
|
foreach ($criteria->get('author') as $key => $value) { |
|
39
|
1 |
|
if ($value !== $article->getMetadataByKey('byline')) { |
|
40
|
1 |
|
return false; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
if ($criteria->has('publishedBefore')) { |
|
46
|
|
|
$publishedBefore = new \DateTime($criteria->get('publishedBefore')); |
|
47
|
|
|
if ($article->getPublishedAt() > $publishedBefore) { |
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
2 |
|
if ($criteria->has('publishedAfter')) { |
|
53
|
|
|
$publishedAfter = new \DateTime($criteria->get('publishedAfter')); |
|
54
|
|
|
if ($article->getPublishedAt() < $publishedAfter) { |
|
55
|
|
|
return false; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
if ($criteria->has('publishedAt') |
|
60
|
2 |
|
&& (!$criteria->has('publishedBefore') || !$criteria->has('publishedAfter'))) { |
|
61
|
1 |
|
$publishedAt = new \DateTime($criteria->get('publishedAt')); |
|
62
|
1 |
|
if ($publishedAt->format('d-m-Y') !== $article->getPublishedAt()->format('d-m-Y')) { |
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
2 |
|
if ($criteria->has('metadata')) { |
|
68
|
2 |
|
foreach ($criteria->get('metadata') as $key => $value) { |
|
69
|
2 |
|
if ($value !== $article->getMetadataByKey($key)) { |
|
70
|
2 |
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
2 |
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|