ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilScormMailTemplateLPContext.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  public const ID = 'sahs_context_lp';
30 
31  public function getId(): string
32  {
33  return self::ID;
34  }
35 
36  public function getTitle(): string
37  {
38  global $DIC;
39  $lng = $DIC->language();
40 
41  $lng->loadLanguageModule('sahs');
42 
43  return $lng->txt('sahs_mail_context_lp');
44  }
45 
46  public function getDescription(): string
47  {
48  global $DIC;
49  $lng = $DIC->language();
50 
51  $lng->loadLanguageModule('sahs');
52 
53  return $lng->txt('sahs_mail_context_lp_info');
54  }
55 
60  public function getSpecificPlaceholders(): array
61  {
65  global $DIC;
66  $lng = $DIC->language();
67 
68  $lng->loadLanguageModule('trac');
69  $tracking = new ilObjUserTracking();
70 
71 
72  $placeholders = [];
73 
74 
75  $placeholders['scorm_title'] = [
76  'placeholder' => 'SCORM_TITLE',
77  'label' => $lng->txt('obj_sahs')
78  ];
79 
80  $placeholders['scorm_status'] = [
81  'placeholder' => 'SCORM_STATUS',
82  'label' => $lng->txt('trac_status')
83  ];
84 
85  $placeholders['scorm_mark'] = [
86  'placeholder' => 'SCORM_MARK',
87  'label' => $lng->txt('trac_mark')
88  ];
89 
90  // #17969
91  $lng->loadLanguageModule('content');
92  $placeholders['scorm_score'] = [
93  'placeholder' => 'SCORM_SCORE',
94  'label' => $lng->txt('cont_score')
95  ];
96 
97  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
98  $placeholders['scorm_time_spent'] = [
99  'placeholder' => 'SCORM_TIME_SPENT',
100  'label' => $lng->txt('trac_spent_seconds')
101  ];
102  }
103 
104  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
105  $placeholders['scorm_first_access'] = [
106  'placeholder' => 'SCORM_FIRST_ACCESS',
107  'label' => $lng->txt('trac_first_access')
108  ];
109 
110  $placeholders['scorm_last_access'] = [
111  'placeholder' => 'SCORM_LAST_ACCESS',
112  'label' => $lng->txt('trac_last_access')
113  ];
114  }
115 
116 
117  $placeholders['scorm_link'] = [
118  'placeholder' => 'SCORM_LINK',
119  'label' => $lng->txt('perma_link')
120  ];
121 
122  return $placeholders;
123  }
124 
128  public function resolveSpecificPlaceholder(
129  string $placeholder_id,
130  array $context_parameters,
131  ?ilObjUser $recipient = null
132  ): string {
136  global $DIC;
137  $ilObjDataCache = $DIC['ilObjDataCache'];
138 
139  $obj_id = $ilObjDataCache->lookupObjId((int) $context_parameters['ref_id']);
140  $tracking = new ilObjUserTracking();
141 
142  switch ($placeholder_id) {
143  case 'scorm_title':
144  return $ilObjDataCache->lookupTitle($obj_id);
145 
146  case 'scorm_link':
147  return ilLink::_getLink((int) $context_parameters['ref_id'], 'sahs');
148 
149  case 'scorm_status':
150  if ($recipient === null) {
151  return '';
152  }
153  $status = ilLPStatus::_lookupStatus($obj_id, $recipient->getId());
154  if (!$status) {
156  }
157 
158  $this->getLanguage()->loadLanguageModule('trac');
159 
160  return ilLearningProgressBaseGUI::_getStatusText($status, $this->getLanguage());
161 
162  case 'scorm_mark':
163  if ($recipient === null) {
164  return '';
165  }
166  $mark = ilLPMarks::_lookupMark($recipient->getId(), $obj_id);
167  return trim($mark) !== '' ? $mark : '-';
168 
169  case 'scorm_score':
170  if ($recipient === null) {
171  return '';
172  }
173 
174  $scores = [];
175  $obj_id = ilObject::_lookupObjId((int) $context_parameters['ref_id']);
176  $coll = ilScormLP::getInstance($obj_id)->getCollectionInstance();
177  if ($coll !== null && $coll->getItems()) {
178  //changed static call into dynamic one//ukohnle
179  //foreach(ilTrQuery::getSCOsStatusForUser($recipient->getId(), $obj_id, $coll->getItems()) as $item)
180  $SCOStatusForUser = ilTrQuery::getSCOsStatusForUser(
181  $recipient->getId(),
182  $obj_id,
183  $coll->getItems()
184  );
185  foreach ($SCOStatusForUser as $item) {
186  $scores[] = $item['title'] . ': ' . $item['score'];
187  }
188  }
189  return implode("\n", $scores);
190 
191  case 'scorm_time_spent':
192  if ($recipient === null) {
193  return '';
194  }
195 
196  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
197  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
198  if (isset($progress['spent_seconds'])) {
200  $progress['spent_seconds'],
201  false,
202  $this->getLanguage()
203  );
204  }
205  }
206  break;
207 
208  case 'scorm_first_access':
209  if ($recipient === null) {
210  return '';
211  }
212 
213  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
214  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
215  if (isset($progress['access_time_min'])) {
216  $current_language = ilDatePresentation::getLanguage();
218  $used_relative_dates = ilDatePresentation::useRelativeDates();
221  $progress['access_time_min'],
223  ));
224  ilDatePresentation::setLanguage($current_language);
225  ilDatePresentation::setUseRelativeDates($used_relative_dates);
226 
227  return $datetime;
228  }
229  }
230  break;
231 
232  case 'scorm_last_access':
233  if ($recipient === null) {
234  return '';
235  }
236 
237  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
238  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
239  if (isset($progress['access_time'])) {
240  $current_language = ilDatePresentation::getLanguage();
242  $used_relative_dates = ilDatePresentation::useRelativeDates();
244  $datetime = ilDatePresentation::formatDate(new ilDateTime($progress['access_time'], IL_CAL_UNIX));
245  ilDatePresentation::setLanguage($current_language);
246  ilDatePresentation::setUseRelativeDates($used_relative_dates);
247 
248  return $datetime;
249  }
250  }
251  break;
252  }
253 
254  return '';
255  }
256 }
static _getProgress(int $a_user_id, int $a_obj_id)
$datetime
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static getSCOsStatusForUser(int $a_user_id, int $a_parent_obj_id, array $a_sco_ids)
const IL_CAL_UNIX
static setLanguage(ilLanguage $a_lng)
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ilObjUser $recipient=null)
$lng
Class ilMailTemplateContext.
static _getStatusText(int $a_status, ?ilLanguage $a_lng=null)
Get status alt text.
static _lookupStatus(int $a_obj_id, int $a_user_id, bool $a_create=true)
Lookup status.
const LP_STATUS_NOT_ATTEMPTED_NUM
static _lookupMark(int $a_usr_id, int $a_obj_id)
static setUseRelativeDates(bool $a_status)
set use relative dates
static getInstance(int $obj_id)