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

Class ilTermsOfServiceAcceptanceHistoryCriteriaBag. More...

+ Inheritance diagram for ilTermsOfServiceAcceptanceHistoryCriteriaBag:
+ Collaboration diagram for ilTermsOfServiceAcceptanceHistoryCriteriaBag:

Public Member Functions

 __construct ($data=[])
 ilTermsOfServiceAcceptanceHistoryCriteriaBag constructor. More...
 
 toJson ()
 
 fromJson (string $json)
 
Parameters
string$json
More...
 
 jsonSerialize ()
 

Private Member Functions

 ensureValidArrayTypes (array $data)
 
 ensureValidInternalTypes (array $data)
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilTermsOfServiceAcceptanceHistoryCriteriaBag::__construct (   $data = [])

ilTermsOfServiceAcceptanceHistoryCriteriaBag constructor.

Parameters
string|

Definition at line 15 of file class.ilTermsOfServiceAcceptanceHistoryCriteriaBag.php.

References $data, ensureValidArrayTypes(), fromJson(), ilTermsOfServiceEvaluableCriterion\getCriterionId(), and ilTermsOfServiceEvaluableCriterion\getCriterionValue().

16  {
17  if (is_array($data)) {
19 
20  parent::__construct(array_values(array_map(function (\ilTermsOfServiceEvaluableCriterion $criterionAssignment) {
21  return [
22  'id' => $criterionAssignment->getCriterionId(),
23  'value' => $criterionAssignment->getCriterionValue()
24  ];
25  }, $data)));
26  } else {
27  parent::__construct([]);
28 
29  if (is_string($data)) {
30  $this->fromJson($data);
31  }
32  }
33  }
Interface ilTermsOfServiceEvaluableCriterion.
$data
Definition: bench.php:6
+ Here is the call graph for this function:

Member Function Documentation

◆ ensureValidArrayTypes()

ilTermsOfServiceAcceptanceHistoryCriteriaBag::ensureValidArrayTypes ( array  $data)
private
Parameters
array$data
Exceptions

Definition at line 39 of file class.ilTermsOfServiceAcceptanceHistoryCriteriaBag.php.

Referenced by __construct().

40  {
41  array_walk($data, function ($value) {
42  if (!($value instanceof \ilTermsOfServiceEvaluableCriterion)) {
43  throw new \ilTermsOfServiceUnexpectedCriteriaBagContentException(sprintf(
44  "Unexpected element found, given %s, expected instanceof '%s'",
45  var_export($value, 1),
46  \ilTermsOfServiceEvaluableCriterion::class
47  ));
48  }
49  });
50  }
Interface ilTermsOfServiceEvaluableCriterion.
$data
Definition: bench.php:6
+ Here is the caller graph for this function:

◆ ensureValidInternalTypes()

ilTermsOfServiceAcceptanceHistoryCriteriaBag::ensureValidInternalTypes ( array  $data)
private
Parameters
array$data

Definition at line 55 of file class.ilTermsOfServiceAcceptanceHistoryCriteriaBag.php.

Referenced by fromJson().

56  {
57  array_walk($data, function ($value) {
58  if (!is_array($value)) {
59  throw new \ilTermsOfServiceUnexpectedCriteriaBagContentException(sprintf(
60  "Unexpected element found, given %s, expected array",
61  var_export($value, 1)
62  ));
63  }
64 
65  if (count($value) !== 2 || !array_key_exists('id', $value) || !array_key_exists('value', $value)) {
66  throw new \ilTermsOfServiceUnexpectedCriteriaBagContentException(sprintf(
67  "Unexpected element found, given %s, expected array with keys 'id' and 'value'",
68  var_export($value, 1)
69  ));
70  }
71  });
72  }
$data
Definition: bench.php:6
+ Here is the caller graph for this function:

◆ fromJson()

ilTermsOfServiceAcceptanceHistoryCriteriaBag::fromJson ( string  $json)

Parameters
string$json

Exceptions

Implements ilTermsOfServiceJsonDeserialization.

Definition at line 88 of file class.ilTermsOfServiceAcceptanceHistoryCriteriaBag.php.

References $data, and ensureValidInternalTypes().

Referenced by __construct().

89  {
90  $data = json_decode($json, true);
91 
92  if (!is_array($data)) {
93  throw new \ilTermsOfServiceUnexpectedCriteriaBagContentException(sprintf(
94  "Unexpected element found, given %s, expected array",
95  var_export($data, 1)
96  ));
97  }
98 
100 
101  $this->exchangeArray($data);
102  }
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jsonSerialize()

ilTermsOfServiceAcceptanceHistoryCriteriaBag::jsonSerialize ( )

Definition at line 107 of file class.ilTermsOfServiceAcceptanceHistoryCriteriaBag.php.

108  {
109  return $this->getArrayCopy();
110  }

◆ toJson()

ilTermsOfServiceAcceptanceHistoryCriteriaBag::toJson ( )

Implements ilTermsOfServiceJsonSerialization.

Definition at line 77 of file class.ilTermsOfServiceAcceptanceHistoryCriteriaBag.php.

77  : string
78  {
79  $json = json_encode($this);
80 
81  return $json;
82  }

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