ILIAS  release_8 Revision v8.24
class.ilTermsOfServiceDocumentCriterionAssignmentConstraint.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
29{
32
33 public function __construct(
36 Factory $dataFactory,
38 ) {
39 $this->criterionTypeFactory = $criterionTypeFactory;
40 $this->document = $document;
41
43 function (ilTermsOfServiceDocumentCriterionAssignment $value): bool {
44 return 0 === count($this->filterEqualValues($value));
45 },
46 static function ($txt, $value): string {
47 return 'The passed assignment must be unique for the document!';
48 },
49 $dataFactory,
50 $lng
51 );
52 }
53
58 protected function filterEqualValues(
60 ): array {
61 $otherValues = $this->document->criteria();
62
63 return array_filter(
64 $otherValues,
65 function (ilTermsOfServiceDocumentCriterionAssignment $otherValue) use ($value): bool {
66 $idCurrent = $otherValue->getId();
67 $idNew = $value->getId();
68
69 $uniqueIdEquals = $idCurrent === $idNew;
70 if ($uniqueIdEquals) {
71 return false;
72 }
73
74 $valuesEqual = $value->equals($otherValue);
75 if ($valuesEqual) {
76 return true;
77 }
78
79 return $this->haveSameNature($value, $otherValue);
80 }
81 );
82 }
83
90 protected function haveSameNature(
93 ): bool {
94 if ($value->getCriterionId() !== $otherValue->getCriterionId()) {
95 return false;
96 }
97
98 $valuesHaveSameNature = $this->criterionTypeFactory->findByTypeIdent($value->getCriterionId())->hasUniqueNature();
99
100 return $valuesHaveSameNature;
101 }
102}
Builds data types.
Definition: Factory.php:21
language handling
haveSameNature(ilTermsOfServiceDocumentCriterionAssignment $value, ilTermsOfServiceDocumentCriterionAssignment $otherValue)
__construct(ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, ilTermsOfServiceDocument $document, Factory $dataFactory, ilLanguage $lng)
Class ilTermsOfServiceDocument.
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
$txt
Definition: error.php:13
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc