ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilAssQuestionLifecycle.php
Go to the documentation of this file.
1<?php
2
22
29{
30 public const DRAFT = 'draft';
31 public const REVIEW = 'review';
32 public const REJECTED = 'rejected';
33 public const FINAL = 'final';
34 public const SHARABLE = 'sharable';
35 public const OUTDATED = 'outdated';
36
37 private string $identifier;
38
40 {
41 $this->validateIdentifier($identifier);
42 $this->setIdentifier($identifier);
43 }
44
45 public function getIdentifier(): string
46 {
47 return $this->identifier;
48 }
49
50 private function setIdentifier(string $identifier): void
51 {
52 $this->identifier = $identifier;
53 }
54
58 public function getValidIdentifiers(): array
59 {
61 }
62
63 public function getMappedLomLifecycle(): string
64 {
65 switch ($this->getIdentifier()) {
66 case self::OUTDATED:
68
69 case self::SHARABLE:
70 case self::FINAL:
72
73 case self::REJECTED:
74 case self::REVIEW:
75 case self::DRAFT:
76 default:
78 }
79 }
80
81 public function getTranslation(ilLanguage $lng): string
82 {
83 return $this->getTranslationByIdentifier($lng, $this->getIdentifier());
84 }
85
86 private function getTranslationByIdentifier(ilLanguage $lng, string $identifier): string
87 {
88 switch ($identifier) {
89 case self::DRAFT:
90 return $lng->txt('qst_lifecycle_draft');
91
92 case self::REVIEW:
93 return $lng->txt('qst_lifecycle_review');
94
95 case self::REJECTED:
96 return $lng->txt('qst_lifecycle_rejected');
97
98 case self::FINAL:
99 return $lng->txt('qst_lifecycle_final');
100
101 case self::SHARABLE:
102 return $lng->txt('qst_lifecycle_sharable');
103
104 case self::OUTDATED:
105 return $lng->txt('qst_lifecycle_outdated');
106
107 default:
108 return '';
109 }
110 }
111
116 public function getSelectOptions(ilLanguage $lng): array
117 {
118 $selectOptions = [];
119
120 foreach ($this->getValidIdentifiers() as $identifier) {
121 $selectOptions[$identifier] = $this->getTranslationByIdentifier($lng, $identifier);
122 }
123
124 return $selectOptions;
125 }
126
131 private function validateIdentifier($identifier): void
132 {
133 if (!in_array($identifier, $this->getValidIdentifiers(), true)) {
135 'Invalid ilias lifecycle given: ' . $identifier
136 );
137 }
138 }
139
140 #[\Override]
141 public function toNormalized(
142 Transformations $transformations,
143 array $context = []
144 ): array|float|bool|int|string|null
145 {
146 return [
147 'identifier' => $this->getIdentifier(),
148 ];
149 }
150
151 #[\Override]
152 public function fromNormalized(
153 array $normalized,
154 Transformations $transformations
155 ): self
156 {
157 return new self($normalized['identifier']);
158 }
159}
Provides a set of transformations for normalizing and denormalizing values.
__construct($identifier=self::DRAFT)
fromNormalized(array $normalized, Transformations $transformations)
Restore the object from its normalized representation.
toNormalized(Transformations $transformations, array $context=[])
Convert the internal state of the implementing object into a language-neutral array structure.
getTranslationByIdentifier(ilLanguage $lng, string $identifier)
language handling
global $lng
Definition: privfeed.php:26