ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTermsOfServiceDocumentCriterionAssignmentConstraint Class Reference

Class ilTermsOfServiceDocumentCriterionAssignmentConstraint. More...

+ Inheritance diagram for ilTermsOfServiceDocumentCriterionAssignmentConstraint:
+ Collaboration diagram for ilTermsOfServiceDocumentCriterionAssignmentConstraint:

Public Member Functions

 __construct (\ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, \ilTermsOfServiceDocument $document, Factory $dataFactory, \ilLanguage $lng)
 ilTermsOfServiceDocumentCriterionAssignmentConstraint constructor. More...
 
- Public Member Functions inherited from ILIAS\Validation\Constraints\Custom
 __construct (callable $is_ok, $error, Data\Factory $data_factory, \ilLanguage $lng)
 If $error is a callable it needs to take two parameters: More...
 
 check ($value)
 Checks the provided value.Should not throw if accepts($value).
Exceptions

UnexpectedValueException if value does not comply with encoded constraint.

Parameters
mixed$value
Returns
null
More...
 
 accepts ($value)
 Tells if the provided value complies.
Parameters
mixed$value
Returns
bool
More...
 
 problemWith ($value)
 Tells what the problem with the provided value is.Should return null if accepts($value).
Parameters
mixed$value
Returns
string|null
More...
 
 restrict (Result $result)
 Restricts a Result.Must do nothing with the result if $result->isError(). Must replace the result with an error according to problemWith() if !accepts($result->value()).
Parameters
Result$result
Returns
Result
More...
 
 withProblemBuilder (callable $builder)
 Get a constraint like this one with a builder for a custom error message.problemWith() must return an error message according to the new builder for the new constraint.The builder needs to be callable that takes two parameters:
Parameters
callable$builder
Returns
Constraint
More...
 
 getErrorMessage ($value)
 Get the problem message. More...
 
 check ($value)
 Checks the provided value. More...
 
 accepts ($value)
 Tells if the provided value complies. More...
 
 problemWith ($value)
 Tells what the problem with the provided value is. More...
 
 restrict (Result $result)
 Restricts a Result. More...
 
 withProblemBuilder (callable $builder)
 Get a constraint like this one with a builder for a custom error message. More...
 

Protected Member Functions

 filterEqualValues (\ilTermsOfServiceDocumentCriterionAssignment $value)
 
 haveSameNature (\ilTermsOfServiceDocumentCriterionAssignment $value, \ilTermsOfServiceDocumentCriterionAssignment $otherValue)
 
- Protected Member Functions inherited from ILIAS\Validation\Constraints\Custom
 getLngClosure ()
 Get the closure to be passed to the error-function that does i18n and sprintf. More...
 

Protected Attributes

 $criterionTypeFactory
 
 $document
 
- Protected Attributes inherited from ILIAS\Validation\Constraints\Custom
 $data_factory
 
 $lng
 
 $is_ok
 
 $error
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilTermsOfServiceDocumentCriterionAssignmentConstraint::__construct ( \ilTermsOfServiceCriterionTypeFactoryInterface  $criterionTypeFactory,
\ilTermsOfServiceDocument  $document,
Factory  $dataFactory,
\ilLanguage  $lng 
)

ilTermsOfServiceDocumentCriterionAssignmentConstraint constructor.

Parameters
\ilTermsOfServiceCriterionTypeFactoryInterface$criterionTypeFactory
\ilTermsOfServiceDocument$document
Factory$dataFactory
\ilLanguage$lng

Definition at line 27 of file class.ilTermsOfServiceDocumentCriterionAssignmentConstraint.php.

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 }
$txt
Definition: error.php:11

References $criterionTypeFactory, $document, ILIAS\Validation\Constraints\Custom\$lng, $txt, and filterEqualValues().

+ Here is the call graph for this function:

Member Function Documentation

◆ filterEqualValues()

ilTermsOfServiceDocumentCriterionAssignmentConstraint::filterEqualValues ( \ilTermsOfServiceDocumentCriterionAssignment  $value)
protected
Parameters
\ilTermsOfServiceDocumentCriterionAssignment$value
Returns
\ilTermsOfServiceDocumentCriterionAssignment[]

Definition at line 52 of file class.ilTermsOfServiceDocumentCriterionAssignmentConstraint.php.

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 }
haveSameNature(\ilTermsOfServiceDocumentCriterionAssignment $value, \ilTermsOfServiceDocumentCriterionAssignment $otherValue)

References ilTermsOfServiceDocumentCriterionAssignment\equals(), and haveSameNature().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ haveSameNature()

ilTermsOfServiceDocumentCriterionAssignmentConstraint::haveSameNature ( \ilTermsOfServiceDocumentCriterionAssignment  $value,
\ilTermsOfServiceDocumentCriterionAssignment  $otherValue 
)
protected
Parameters
\ilTermsOfServiceDocumentCriterionAssignment$value
\ilTermsOfServiceDocumentCriterionAssignment$otherValue
Returns
bool

Definition at line 85 of file class.ilTermsOfServiceDocumentCriterionAssignmentConstraint.php.

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 }

Referenced by filterEqualValues().

+ Here is the caller graph for this function:

Field Documentation

◆ $criterionTypeFactory

ilTermsOfServiceDocumentCriterionAssignmentConstraint::$criterionTypeFactory
protected

◆ $document

ilTermsOfServiceDocumentCriterionAssignmentConstraint::$document
protected

The documentation for this class was generated from the following file: