ILIAS  release_8 Revision v8.24
class.ilCourseMailTemplateTutorContext.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
26{
27 public const ID = 'crs_context_tutor_manual';
28
29 protected static array $periodInfoByObjIdCache = [];
30
31 public function getId(): string
32 {
33 return self::ID;
34 }
35
36 public function getTitle(): string
37 {
38 global $DIC;
39
40 $lng = $DIC['lng'];
41
42 $lng->loadLanguageModule('crs');
43
44 return $lng->txt('crs_mail_context_tutor_title');
45 }
46
47 public function getDescription(): string
48 {
49 global $DIC;
50
51 $lng = $DIC['lng'];
52
53 $lng->loadLanguageModule('crs');
54
55 return $lng->txt('crs_mail_context_tutor_info');
56 }
57
61 public function getSpecificPlaceholders(): array
62 {
66 global $DIC;
67
68 $lng = $DIC['lng'];
69
70 $lng->loadLanguageModule('crs');
71 $lng->loadLanguageModule('trac');
72
73 // tracking settings
74 $tracking = new ilObjUserTracking();
75
76 $placeholders = array();
77
78 $placeholders['crs_title'] = array(
79 'placeholder' => 'COURSE_TITLE',
80 'label' => $lng->txt('crs_title')
81 );
82
83 $placeholders['crs_period_start'] = array(
84 'placeholder' => 'COURSE_PERIOD_START',
85 'label' => $lng->txt('crs_period_start_mail_placeholder')
86 );
87
88 $placeholders['crs_period_end'] = array(
89 'placeholder' => 'COURSE_PERIOD_END',
90 'label' => $lng->txt('crs_period_end_mail_placeholder')
91 );
92
93 $placeholders['crs_status'] = array(
94 'placeholder' => 'COURSE_STATUS',
95 'label' => $lng->txt('trac_status')
96 );
97
98 $placeholders['crs_mark'] = array(
99 'placeholder' => 'COURSE_MARK',
100 'label' => $lng->txt('trac_mark')
101 );
102
103 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
104 $placeholders['crs_time_spent'] = array(
105 'placeholder' => 'COURSE_TIME_SPENT',
106 'label' => $lng->txt('trac_spent_seconds')
107 );
108 }
109
110 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
111 $placeholders['crs_first_access'] = array(
112 'placeholder' => 'COURSE_FIRST_ACCESS',
113 'label' => $lng->txt('trac_first_access')
114 );
115
116 $placeholders['crs_last_access'] = array(
117 'placeholder' => 'COURSE_LAST_ACCESS',
118 'label' => $lng->txt('trac_last_access')
119 );
120 }
121
122 $placeholders['crs_link'] = array(
123 'placeholder' => 'COURSE_LINK',
124 'label' => $lng->txt('crs_mail_permanent_link')
125 );
126
127 return $placeholders;
128 }
129
130 private function getCachedPeriodByObjId(int $objId): ?array
131 {
132 if (!array_key_exists($objId, self::$periodInfoByObjIdCache)) {
133 self::$periodInfoByObjIdCache[$objId] = ilObjCourseAccess::lookupPeriodInfo($objId);
134 }
135
136 return self::$periodInfoByObjIdCache[$objId];
137 }
138
142 public function resolveSpecificPlaceholder(
143 string $placeholder_id,
144 array $context_parameters,
145 ilObjUser $recipient = null,
146 bool $html_markup = false
147 ): string {
151 global $DIC;
152
153 $ilObjDataCache = $DIC['ilObjDataCache'];
154
155 if (!in_array($placeholder_id, array(
156 'crs_title',
157 'crs_period_start',
158 'crs_period_end',
159 'crs_link',
160 'crs_status',
161 'crs_mark',
162 'crs_time_spent',
163 'crs_first_access',
164 'crs_last_access'
165 ))) {
166 return '';
167 }
168
169 $obj_id = $ilObjDataCache->lookupObjId((int) $context_parameters['ref_id']);
170
171 $tracking = new ilObjUserTracking();
172
173 $this->getLanguage()->loadLanguageModule('trac');
174 $this->getLanguage()->loadLanguageModule('crs');
175
176 switch ($placeholder_id) {
177 case 'crs_title':
178 return $ilObjDataCache->lookupTitle($obj_id);
179
180 case 'crs_period_start':
181 $periodInfo = $this->getCachedPeriodByObjId((int) $ilObjDataCache->lookupObjId((int) $context_parameters['ref_id']));
182 if ($periodInfo) {
183 $useRelativeDates = ilDatePresentation::useRelativeDates();
185 $formattedDate = ilDatePresentation::formatDate($periodInfo['crs_start']);
187
188 return $formattedDate;
189 }
190
191 return '';
192
193 case 'crs_period_end':
194 $periodInfo = $this->getCachedPeriodByObjId($ilObjDataCache->lookupObjId((int) $context_parameters['ref_id']));
195 if ($periodInfo) {
196 $useRelativeDates = ilDatePresentation::useRelativeDates();
198 $formattedDate = ilDatePresentation::formatDate($periodInfo['crs_end']);
200
201 return $formattedDate;
202 }
203
204 return '';
205
206 case 'crs_link':
207 return ilLink::_getLink($context_parameters['ref_id'], 'crs');
208
209 case 'crs_status':
210 if ($recipient === null) {
211 return '';
212 }
213
214 $status = ilLPStatus::_lookupStatus($obj_id, $recipient->getId());
215 if (!$status) {
217 }
219
220 case 'crs_mark':
221 if ($recipient === null) {
222 return '';
223 }
224
225 $mark = ilLPMarks::_lookupMark($recipient->getId(), $obj_id);
226 return (is_string($mark) && strlen(trim($mark))) ? $mark : '-';
227
228 case 'crs_time_spent':
229 if ($recipient === null) {
230 return '';
231 }
232
233 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
234 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
235 if (isset($progress['spent_seconds'])) {
237 $progress['spent_seconds'],
238 false,
239 $this->getLanguage()
240 );
241 }
242 }
243 break;
244
245 case 'crs_first_access':
246 if ($recipient === null) {
247 return '';
248 }
249
250 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
251 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
252 if (isset($progress['access_time_min'])) {
254 $progress['access_time_min'],
256 ));
257 }
258 }
259 break;
260
261 case 'crs_last_access':
262 if ($recipient === null) {
263 return '';
264 }
265
266 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
267 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
268 if (isset($progress['access_time'])) {
269 return ilDatePresentation::formatDate(new ilDateTime($progress['access_time'], IL_CAL_UNIX));
270 }
271 }
272 break;
273 }
274
275 return '';
276 }
277}
const IL_CAL_UNIX
static setUseRelativeDates(bool $a_status)
set use relative dates
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)
static lookupPeriodInfo(int $a_obj_id)
User class.
global $DIC
Definition: feed.php:28
$lng
$objId
Definition: xapitoken.php:57