ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTermsOfServiceAcceptanceHistoryCriteriaBag.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
9{
15 public function __construct($data = [])
16 {
17 if (is_array($data)) {
19
20 parent::__construct(array_values(array_map(function (
21 ilTermsOfServiceEvaluableCriterion $criterionAssignment
22 ) {
23 return [
24 'id' => $criterionAssignment->getCriterionId(),
25 'value' => $criterionAssignment->getCriterionValue()
26 ];
27 }, $data)));
28 } else {
30
31 if (is_string($data)) {
32 $this->fromJson($data);
33 }
34 }
35 }
36
40 private function ensureValidArrayTypes(array $data) : void
41 {
42 array_walk($data, function ($value) {
43 if (!($value instanceof ilTermsOfServiceEvaluableCriterion)) {
45 "Unexpected element found, given %s, expected instanceof '%s'",
46 var_export($value, true),
47 ilTermsOfServiceEvaluableCriterion::class
48 ));
49 }
50 });
51 }
52
56 private function ensureValidInternalTypes(array $data) : void
57 {
58 array_walk($data, function ($value) {
59 if (!is_array($value)) {
61 "Unexpected element found, given %s, expected array",
62 var_export($value, true)
63 ));
64 }
65
66 if (count($value) !== 2 || !array_key_exists('id', $value) || !array_key_exists('value', $value)) {
68 "Unexpected element found, given %s, expected array with keys 'id' and 'value'",
69 var_export($value, true)
70 ));
71 }
72 });
73 }
74
78 public function toJson() : string
79 {
80 $json = json_encode($this);
81
82 return $json;
83 }
84
89 public function fromJson(string $json) : void
90 {
91 $data = json_decode($json, true);
92
93 if (!is_array($data)) {
95 "Unexpected element found, given %s, expected array",
96 var_export($data, true)
97 ));
98 }
99
101
102 $this->exchangeArray($data);
103 }
104
108 public function jsonSerialize()
109 {
110 return $this->getArrayCopy();
111 }
112}
An exception for terminatinating execution or to throw for unit testing.
__construct($data=[])
ilTermsOfServiceAcceptanceHistoryCriteriaBag constructor.
Interface ilTermsOfServiceEvaluableCriterion.
Interface ilTermsOfServiceJsonSerializable.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$data
Definition: storeScorm.php:23