ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilScormMailTemplateLPContext.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Mail/classes/class.ilMailTemplateContext.php';
5
13{
14 const ID = 'sahs_context_lp';
15
19 public function getId() : string
20 {
21 return self::ID;
22 }
23
27 public function getTitle() : string
28 {
29 global $DIC;
30 $lng = $DIC['lng'];
31
32 $lng->loadLanguageModule('sahs');
33
34 return $lng->txt('sahs_mail_context_lp');
35 }
36
40 public function getDescription() : string
41 {
42 global $DIC;
43 $lng = $DIC['lng'];
44
45 $lng->loadLanguageModule('sahs');
46
47 return $lng->txt('sahs_mail_context_lp_info');
48 }
49
54 public function getSpecificPlaceholders() : array
55 {
59 global $DIC;
60 $lng = $DIC['lng'];
61
62 $lng->loadLanguageModule('trac');
63
64 // tracking settings
65 include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
66 $tracking = new ilObjUserTracking();
67
68
69 $placeholders = array();
70
71
72 $placeholders['sahs_title'] = array(
73 'placeholder' => 'SCORM_TITLE',
74 'label' => $lng->txt('obj_sahs')
75 );
76
77 $placeholders['sahs_status'] = array(
78 'placeholder' => 'SCORM_STATUS',
79 'label' => $lng->txt('trac_status')
80 );
81
82 $placeholders['sahs_mark'] = array(
83 'placeholder' => 'SCORM_MARK',
84 'label' => $lng->txt('trac_mark')
85 );
86
87 // #17969
88 $lng->loadLanguageModule('content');
89 $placeholders['sahs_score'] = array(
90 'placeholder' => 'SCORM_SCORE',
91 'label' => $lng->txt('cont_score')
92 );
93
94 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
95 $placeholders['sahs_time_spent'] = array(
96 'placeholder' => 'SCORM_TIME_SPENT',
97 'label' => $lng->txt('trac_spent_seconds')
98 );
99 }
100
101 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
102 $placeholders['sahs_first_access'] = array(
103 'placeholder' => 'SCORM_FIRST_ACCESS',
104 'label' => $lng->txt('trac_first_access')
105 );
106
107 $placeholders['sahs_last_access'] = array(
108 'placeholder' => 'SCORM_LAST_ACCESS',
109 'label' => $lng->txt('trac_last_access')
110 );
111 }
112
113
114 $placeholders['sahs_link'] = array(
115 'placeholder' => 'SCORM_LINK',
116 'label' => $lng->txt('perma_link')
117 );
118
119 return $placeholders;
120 }
121
125 public function resolveSpecificPlaceholder(
126 string $placeholder_id,
127 array $context_parameters,
128 ilObjUser $recipient = null,
129 bool $html_markup = false
130 ) : string {
134 global $DIC;
135 $ilObjDataCache = $DIC['ilObjDataCache'];
136
137 if (!in_array($placeholder_id, array('sahs_title', 'sahs_link'))) {
138 return '';
139 }
140
141 $obj_id = $ilObjDataCache->lookupObjId($context_parameters['ref_id']);
142
143 include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
144 $tracking = new ilObjUserTracking();
145
146 switch ($placeholder_id) {
147 case 'sahs_title':
148 return $ilObjDataCache->lookupTitle($obj_id);
149
150 case 'sahs_link':
151 require_once './Services/Link/classes/class.ilLink.php';
152 return ilLink::_getLink($context_parameters['ref_id'], 'sahs');
153
154 case 'sahs_status':
155 if ($recipient === null) {
156 return '';
157 }
158
159 include_once './Services/Tracking/classes/class.ilLPStatus.php';
160 include_once './Services/Tracking/classes/class.ilLearningProgressBaseGUI.php';
161 $status = ilLPStatus::_lookupStatus($obj_id, $recipient->getId());
162 if (!$status) {
164 }
166
167 case 'sahs_mark':
168 if ($recipient === null) {
169 return '';
170 }
171
172 include_once './Services/Tracking/classes/class.ilLPMarks.php';
173 $mark = ilLPMarks::_lookupMark($recipient->getId(), $obj_id);
174 return strlen(trim($mark)) ? $mark : '-';
175
176 case 'sahs_score':
177 if ($recipient === null) {
178 return '';
179 }
180
181 $scores = array();
182 $obj_id = ilObject::_lookupObjId($context_parameters['ref_id']);
183 include_once 'Modules/ScormAicc/classes/class.ilScormLP.php';
184 $coll = ilScormLP::getInstance($obj_id)->getCollectionInstance();
185 if ($coll->getItems()) {
186 include_once 'Services/Tracking/classes/class.ilTrQuery.php';
187 //changed static call into dynamic one//ukohnle
188 //foreach(ilTrQuery::getSCOsStatusForUser($recipient->getId(), $obj_id, $coll->getItems()) as $item)
189 $SCOStatusForUser = (new ilTrQuery)->getSCOsStatusForUser(
190 $recipient->getId(),
191 $obj_id,
192 $coll->getItems()
193 );
194 foreach ($SCOStatusForUser as $item) {
195 $scores[] = $item['title'] . ': ' . $item['score'];
196 }
197 }
198 return implode("\n", $scores);
199
200 case 'sahs_time_spent':
201 if ($recipient === null) {
202 return '';
203 }
204
205 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
206 include_once './Services/Tracking/classes/class.ilLearningProgress.php';
207 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
208 if (isset($progress['spent_seconds'])) {
210 $progress['spent_seconds'],
211 false,
212 $this->getLanguage()
213 );
214 }
215 }
216 break;
217
218 case 'sahs_first_access':
219 if ($recipient === null) {
220 return '';
221 }
222
223 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
224 include_once './Services/Tracking/classes/class.ilLearningProgress.php';
225 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
226 if (isset($progress['access_time_min'])) {
228 $progress['access_time_min'],
230 ));
231 }
232 }
233 break;
234
235 case 'sahs_last_access':
236 if ($recipient === null) {
237 return '';
238 }
239
240 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
241 include_once './Services/Tracking/classes/class.ilLearningProgress.php';
242 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
243 if (isset($progress['access_time'])) {
244 return ilDatePresentation::formatDate(new ilDateTime($progress['access_time'], IL_CAL_UNIX));
245 }
246 }
247 break;
248 }
249
250 return '';
251 }
252}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static secondsToString($seconds, $force_with_seconds=false, $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
static _lookupMark($a_usr_id, $a_obj_id)
static _lookupStatus($a_obj_id, $a_user_id, $a_create=true)
Lookup status.
const LP_STATUS_NOT_ATTEMPTED_NUM
static _getStatusText($a_status, $a_lng=null)
Get status alt text.
static _getProgress($a_user_id, $a_obj_id)
Class ilMailTemplateContext.
getSpecificPlaceholders()
Return an array of placeholders.
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ilObjUser $recipient=null, bool $html_markup=false)
static getInstance($a_obj_id)
static _lookupObjId($a_id)
Tracking query class.
global $DIC
Definition: goto.php:24
$lng