ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  if (!in_array($placeholder_id, ['sahs_title', 'sahs_link'])) {
140  return '';
141  }
142 
143  $obj_id = $ilObjDataCache->lookupObjId((int) $context_parameters['ref_id']);
144  $tracking = new ilObjUserTracking();
145 
146  switch ($placeholder_id) {
147  case 'scorm_title':
148  return $ilObjDataCache->lookupTitle($obj_id);
149 
150  case 'scorm_link':
151  return ilLink::_getLink((int) $context_parameters['ref_id'], 'sahs');
152 
153  case 'scorm_status':
154  if ($recipient === null) {
155  return '';
156  }
157  $status = ilLPStatus::_lookupStatus($obj_id, $recipient->getId());
158  if (!$status) {
160  }
161 
162  $this->getLanguage()->loadLanguageModule('trac');
163 
164  return ilLearningProgressBaseGUI::_getStatusText($status, $this->getLanguage());
165 
166  case 'scorm_mark':
167  if ($recipient === null) {
168  return '';
169  }
170  $mark = ilLPMarks::_lookupMark($recipient->getId(), $obj_id);
171  return trim($mark) !== '' ? $mark : '-';
172 
173  case 'scorm_score':
174  if ($recipient === null) {
175  return '';
176  }
177 
178  $scores = [];
179  $obj_id = ilObject::_lookupObjId((int) $context_parameters['ref_id']);
180  $coll = ilScormLP::getInstance($obj_id)->getCollectionInstance();
181  if ($coll !== null && $coll->getItems()) {
182  //changed static call into dynamic one//ukohnle
183  //foreach(ilTrQuery::getSCOsStatusForUser($recipient->getId(), $obj_id, $coll->getItems()) as $item)
184  $SCOStatusForUser = ilTrQuery::getSCOsStatusForUser(
185  $recipient->getId(),
186  $obj_id,
187  $coll->getItems()
188  );
189  foreach ($SCOStatusForUser as $item) {
190  $scores[] = $item['title'] . ': ' . $item['score'];
191  }
192  }
193  return implode("\n", $scores);
194 
195  case 'scorm_time_spent':
196  if ($recipient === null) {
197  return '';
198  }
199 
200  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
201  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
202  if (isset($progress['spent_seconds'])) {
204  $progress['spent_seconds'],
205  false,
206  $this->getLanguage()
207  );
208  }
209  }
210  break;
211 
212  case 'scorm_first_access':
213  if ($recipient === null) {
214  return '';
215  }
216 
217  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
218  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
219  if (isset($progress['access_time_min'])) {
220  $current_language = ilDatePresentation::getLanguage();
222  $used_relative_dates = ilDatePresentation::useRelativeDates();
225  $progress['access_time_min'],
227  ));
228  ilDatePresentation::setLanguage($current_language);
229  ilDatePresentation::setUseRelativeDates($used_relative_dates);
230 
231  return $datetime;
232  }
233  }
234  break;
235 
236  case 'scorm_last_access':
237  if ($recipient === null) {
238  return '';
239  }
240 
241  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
242  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
243  if (isset($progress['access_time'])) {
244  $current_language = ilDatePresentation::getLanguage();
246  $used_relative_dates = ilDatePresentation::useRelativeDates();
248  $datetime = ilDatePresentation::formatDate(new ilDateTime($progress['access_time'], IL_CAL_UNIX));
249  ilDatePresentation::setLanguage($current_language);
250  ilDatePresentation::setUseRelativeDates($used_relative_dates);
251 
252  return $datetime;
253  }
254  }
255  break;
256  }
257 
258  return '';
259  }
260 }
static array static setUseRelativeDates(bool $a_status)
set use relative dates
static _getProgress(int $a_user_id, int $a_obj_id)
$datetime
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
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)
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ?ilObjUser $recipient=null)
global $lng
Definition: privfeed.php:31
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static getInstance(int $obj_id)