ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTermsOfServiceDocumentCriterionAssignmentConstraint.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
7
13{
16
18 protected $document;
19
27 public function __construct(
30 Factory $dataFactory,
32 ) {
33 $this->criterionTypeFactory = $criterionTypeFactory;
34 $this->document = $document;
35
36 parent::__construct(
38 return 0 === count($this->filterEqualValues($value));
39 },
40 function ($txt, $value) {
41 return "The passed assignment must be unique for the document!";
42 },
43 $dataFactory,
44 $lng
45 );
46 }
47
52 protected function filterEqualValues(
54 ) : array {
55 $otherValues = $this->document->criteria();
56
57 return array_filter(
58 $otherValues,
59 function (\ilTermsOfServiceDocumentCriterionAssignment $otherValue) use ($value) {
60 $idCurrent = $otherValue->getId();
61 $idNew = $value->getId();
62
63 $uniqueIdEquals = $idCurrent === $idNew;
64 if ($uniqueIdEquals) {
65 return false;
66 }
67
68 $valuesEqual = $value->equals($otherValue) ;
69 if ($valuesEqual) {
70 return true;
71 }
72
73 $valuesHaveSameNature = $this->haveSameNature($value, $otherValue);
74
75 return $valuesHaveSameNature;
76 }
77 );
78 }
79
85 protected function haveSameNature(
88 ) : bool {
89 if ($value->getCriterionId() !== $otherValue->getCriterionId()) {
90 return false;
91 }
92
93 $valuesHaveSameNature = $this->criterionTypeFactory->findByTypeIdent($value->getCriterionId())->hasUniqueNature();
94
95 return $valuesHaveSameNature;
96 }
97}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:15
language handling
haveSameNature(\ilTermsOfServiceDocumentCriterionAssignment $value, \ilTermsOfServiceDocumentCriterionAssignment $otherValue)
__construct(\ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, \ilTermsOfServiceDocument $document, Factory $dataFactory, \ilLanguage $lng)
ilTermsOfServiceDocumentCriterionAssignmentConstraint constructor.
Class ilTermsOfServiceDocument.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
$txt
Definition: error.php:11
A constraint encodes some resrtictions on values.
Definition: Constraint.php:15