|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Limitation\LanguageLimitation; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation; |
|
12
|
|
|
use eZ\Publish\Core\Limitation\LanguageLimitationType; |
|
13
|
|
|
use eZ\Publish\SPI\Limitation\Target; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @internal for internal use by LanguageLimitation |
|
17
|
|
|
*/ |
|
18
|
|
|
final class VersionTranslationUpdateEvaluator implements VersionTargetEvaluator |
|
19
|
|
|
{ |
|
20
|
|
|
public function accept(Target\Version $targetVersion): bool |
|
21
|
|
|
{ |
|
22
|
|
|
return |
|
23
|
|
|
!empty($targetVersion->forUpdateLanguageCodesList) |
|
24
|
|
|
|| null !== $targetVersion->forUpdateInitialLanguageCode; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function evaluate(Target\Version $targetVersion, Limitation $limitationValue): ?bool |
|
28
|
|
|
{ |
|
29
|
|
|
$accessVote = LanguageLimitationType::ACCESS_ABSTAIN; |
|
30
|
|
|
|
|
31
|
|
|
if (!empty($targetVersion->forUpdateLanguageCodesList)) { |
|
32
|
|
|
$diff = array_diff( |
|
33
|
|
|
$targetVersion->forUpdateLanguageCodesList, |
|
34
|
|
|
$limitationValue->limitationValues |
|
35
|
|
|
); |
|
36
|
|
|
$accessVote = empty($diff) |
|
37
|
|
|
? LanguageLimitationType::ACCESS_GRANTED |
|
38
|
|
|
: LanguageLimitationType::ACCESS_DENIED; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if ( |
|
42
|
|
|
$accessVote !== LanguageLimitationType::ACCESS_DENIED |
|
43
|
|
|
&& null !== $targetVersion->forUpdateInitialLanguageCode |
|
44
|
|
|
) { |
|
45
|
|
|
$accessVote = in_array( |
|
46
|
|
|
$targetVersion->forUpdateInitialLanguageCode, |
|
47
|
|
|
$limitationValue->limitationValues |
|
48
|
|
|
) |
|
49
|
|
|
? LanguageLimitationType::ACCESS_GRANTED |
|
50
|
|
|
: LanguageLimitationType::ACCESS_DENIED; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $accessVote; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|