ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTermsOfServiceDocumentCriterionAssignmentConstraint.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
6
12{
15
17 protected $document;
18
26 public function __construct(
29 Factory $dataFactory,
31 ) {
32 $this->criterionTypeFactory = $criterionTypeFactory;
33 $this->document = $document;
34
37 return 0 === count($this->filterEqualValues($value));
38 },
39 function ($txt, $value) {
40 return "The passed assignment must be unique for the document!";
41 },
42 $dataFactory,
43 $lng
44 );
45 }
46
51 protected function filterEqualValues(
53 ) : array {
54 $otherValues = $this->document->criteria();
55
56 return array_filter(
57 $otherValues,
58 function (ilTermsOfServiceDocumentCriterionAssignment $otherValue) use ($value) {
59 $idCurrent = $otherValue->getId();
60 $idNew = $value->getId();
61
62 $uniqueIdEquals = $idCurrent === $idNew;
63 if ($uniqueIdEquals) {
64 return false;
65 }
66
67 $valuesEqual = $value->equals($otherValue);
68 if ($valuesEqual) {
69 return true;
70 }
71
72 $valuesHaveSameNature = $this->haveSameNature($value, $otherValue);
73
74 return $valuesHaveSameNature;
75 }
76 );
77 }
78
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:20
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:13
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc