ILIAS  trunk Revision v11.0_alpha-1851-ga8564da6fed
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCmiXapiVerbList.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 {
32  public const COMPLETED = 'http://adlnet.gov/expapi/verbs/completed';
33  public const PASSED = 'http://adlnet.gov/expapi/verbs/passed';
34  public const FAILED = 'http://adlnet.gov/expapi/verbs/failed';
35  public const SATISFIED = 'http://adlnet.gov/expapi/verbs/satisfied';
36  public const PROGRESSED = 'http://adlnet.gov/expapi/verbs/progressed';
37  public const EXPERIENCED = 'http://adlnet.gov/expapi/verbs/experienced';
38 
39  protected array $verbs = [
40  'http://adlnet.gov/expapi/verbs/abandoned',
41  'http://adlnet.gov/expapi/verbs/answered',
42  'http://adlnet.gov/expapi/verbs/asked',
43  'http://adlnet.gov/expapi/verbs/attempted',
44  'http://adlnet.gov/expapi/verbs/attended',
45  'http://adlnet.gov/expapi/verbs/commented',
46  'http://adlnet.gov/expapi/verbs/completed',
47  'http://adlnet.gov/expapi/verbs/exited',
48  'http://adlnet.gov/expapi/verbs/experienced',
49  'http://adlnet.gov/expapi/verbs/failed',
50  'http://adlnet.gov/expapi/verbs/imported',
51  'http://adlnet.gov/expapi/verbs/initialized',
52  'http://adlnet.gov/expapi/verbs/interacted',
53  'http://adlnet.gov/expapi/verbs/launched',
54  'http://adlnet.gov/expapi/verbs/mastered',
55  'http://adlnet.gov/expapi/verbs/passed',
56  'http://adlnet.gov/expapi/verbs/preferred',
57  'http://adlnet.gov/expapi/verbs/progressed',
58  'http://adlnet.gov/expapi/verbs/registered',
59  'http://adlnet.gov/expapi/verbs/responded',
60  'http://adlnet.gov/expapi/verbs/resumed',
61  'http://adlnet.gov/expapi/verbs/satisfied',
62  'http://adlnet.gov/expapi/verbs/scored',
63  'http://adlnet.gov/expapi/verbs/shared',
64  'http://adlnet.gov/expapi/verbs/suspended',
65  'http://adlnet.gov/expapi/verbs/terminated',
66  'http://adlnet.gov/expapi/verbs/voided'
67  ];
68 
69  public function isValidVerb(string $verb): bool
70  {
71  return true;//not necessary for dynamic verbs: in_array($verb, $this->verbs);
72  }
73 
74  public function getVerbUri(string $verb): string
75  {
76  return 'http://adlnet.gov/expapi/verbs/' . $verb;
77  }
78 
79  public function getDynamicSelectOptions(?array $verbs): array
80  {
81  global $DIC; /* @var \ILIAS\DI\Container $DIC */
82 
83  $options = array(
84  '' => $DIC->language()->txt('cmix_all_verbs')
85  );
86 
87  if (is_array($verbs)) {
88  foreach ($verbs as $verb) {
89  $verb = $verb['_id'];
90  $options[urlencode($verb)] = self::getVerbTranslation(
91  $DIC->language(),
92  $verb
93  );
94  }
95  }
96 
97  return $options;
98  }
99 
103  public function getSelectOptions(): array
104  {
105  global $DIC; /* @var \ILIAS\DI\Container $DIC */
106 
107  $options = array(
108  '' => $DIC->language()->txt('cmix_all_verbs')
109  );
110 
111  foreach ($this->verbs as $verb) {
112  $options[urlencode($verb)] = self::getVerbTranslation(
113  $DIC->language(),
114  $verb
115  );
116  }
117 
118  return $options;
119  }
120 
121  public static function getVerbTranslation(ilLanguage $lng, string $verb): string
122  {
123  $verbMatch = preg_match('/\/([^\/]+)$/', $verb, $matches);
124  $shortVerb = $matches[1];
125  $langVar = preg_replace('/http(s)?:\/\//', '', $verb);
126  $langVar = str_replace('.', '', $langVar);
127  $langVar = str_replace('/', '_', $langVar);
128  $langVar = 'cmix_' . $langVar;
129  $translatedVerb = $lng->txt($langVar);
130  // check no translation found?
131  if (strpos($translatedVerb, '-cmix_') === 0) {
132  return $shortVerb;
133  } else {
134  return $translatedVerb;
135  }
136  }
137 
138  public static function getInstance(): \ilCmiXapiVerbList
139  {
140  return new self();
141  }
142 }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
global $DIC
Definition: shib_login.php:22
static getVerbTranslation(ilLanguage $lng, string $verb)
global $lng
Definition: privfeed.php:31
getDynamicSelectOptions(?array $verbs)