ILIAS  release_8 Revision v8.24
class.ilScormMailTemplateLPContext.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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['sahs_title'] = [
76 'placeholder' => 'SCORM_TITLE',
77 'label' => $lng->txt('obj_sahs')
78 ];
79
80 $placeholders['sahs_status'] = [
81 'placeholder' => 'SCORM_STATUS',
82 'label' => $lng->txt('trac_status')
83 ];
84
85 $placeholders['sahs_mark'] = [
86 'placeholder' => 'SCORM_MARK',
87 'label' => $lng->txt('trac_mark')
88 ];
89
90 // #17969
91 $lng->loadLanguageModule('content');
92 $placeholders['sahs_score'] = [
93 'placeholder' => 'SCORM_SCORE',
94 'label' => $lng->txt('cont_score')
95 ];
96
97 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
98 $placeholders['sahs_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['sahs_first_access'] = [
106 'placeholder' => 'SCORM_FIRST_ACCESS',
107 'label' => $lng->txt('trac_first_access')
108 ];
109
110 $placeholders['sahs_last_access'] = [
111 'placeholder' => 'SCORM_LAST_ACCESS',
112 'label' => $lng->txt('trac_last_access')
113 ];
114 }
115
116
117 $placeholders['sahs_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 bool $html_markup = false
133 ): string {
137 global $DIC;
138 $ilObjDataCache = $DIC['ilObjDataCache'];
139
140 if (!in_array($placeholder_id, ['sahs_title', 'sahs_link'])) {
141 return '';
142 }
143
144 $obj_id = $ilObjDataCache->lookupObjId((int) $context_parameters['ref_id']);
145 $tracking = new ilObjUserTracking();
146
147 switch ($placeholder_id) {
148 case 'sahs_title':
149 return $ilObjDataCache->lookupTitle($obj_id);
150
151 case 'sahs_link':
152 return ilLink::_getLink((int) $context_parameters['ref_id'], 'sahs');
153
154 case 'sahs_status':
155 if ($recipient === null) {
156 return '';
157 }
158 $status = ilLPStatus::_lookupStatus($obj_id, $recipient->getId());
159 if (!$status) {
161 }
163
164 case 'sahs_mark':
165 if ($recipient === null) {
166 return '';
167 }
168 $mark = ilLPMarks::_lookupMark($recipient->getId(), $obj_id);
169 return strlen(trim($mark)) ? $mark : '-';
170
171 case 'sahs_score':
172 if ($recipient === null) {
173 return '';
174 }
175
176 $scores = [];
177 $obj_id = ilObject::_lookupObjId((int) $context_parameters['ref_id']);
178 $coll = ilScormLP::getInstance($obj_id)->getCollectionInstance();
179 if ($coll !== null && $coll->getItems()) {
180 //changed static call into dynamic one//ukohnle
181 //foreach(ilTrQuery::getSCOsStatusForUser($recipient->getId(), $obj_id, $coll->getItems()) as $item)
182 $SCOStatusForUser = ilTrQuery::getSCOsStatusForUser(
183 $recipient->getId(),
184 $obj_id,
185 $coll->getItems()
186 );
187 foreach ($SCOStatusForUser as $item) {
188 $scores[] = $item['title'] . ': ' . $item['score'];
189 }
190 }
191 return implode("\n", $scores);
192
193 case 'sahs_time_spent':
194 if ($recipient === null) {
195 return '';
196 }
197
198 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
199 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
200 if (isset($progress['spent_seconds'])) {
202 $progress['spent_seconds'],
203 false,
204 $this->getLanguage()
205 );
206 }
207 }
208 break;
209
210 case 'sahs_first_access':
211 if ($recipient === null) {
212 return '';
213 }
214
215 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
216 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
217 if (isset($progress['access_time_min'])) {
219 $progress['access_time_min'],
221 ));
222 }
223 }
224 break;
225
226 case 'sahs_last_access':
227 if ($recipient === null) {
228 return '';
229 }
230
231 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
232 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
233 if (isset($progress['access_time'])) {
234 return ilDatePresentation::formatDate(new ilDateTime($progress['access_time'], IL_CAL_UNIX));
235 }
236 }
237 break;
238 }
239
240 return '';
241 }
242}
const IL_CAL_UNIX
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
static _lookupMark(int $a_usr_id, int $a_obj_id)
const LP_STATUS_NOT_ATTEMPTED_NUM
static _lookupStatus(int $a_obj_id, int $a_user_id, bool $a_create=true)
Lookup status.
static _getStatusText(int $a_status, ?ilLanguage $a_lng=null)
Get status alt text.
static _getProgress(int $a_user_id, int $a_obj_id)
Class ilMailTemplateContext.
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ilObjUser $recipient=null, bool $html_markup=false)
User class.
static getInstance(int $obj_id)
static _lookupObjId(int $ref_id)
static getSCOsStatusForUser(int $a_user_id, int $a_parent_obj_id, array $a_sco_ids)
global $DIC
Definition: feed.php:28
$lng