ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseMailTemplateTutorContext.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
27{
28 public const ID = 'crs_context_tutor_manual';
29
30 protected static array $periodInfoByObjIdCache = [];
31
32 public function getId(): string
33 {
34 return self::ID;
35 }
36
37 public function getTitle(): string
38 {
39 global $DIC;
40
41 $lng = $DIC['lng'];
42
43 $lng->loadLanguageModule('crs');
44
45 return $lng->txt('crs_mail_context_tutor_title');
46 }
47
48 public function getDescription(): string
49 {
50 global $DIC;
51
52 $lng = $DIC['lng'];
53
54 $lng->loadLanguageModule('crs');
55
56 return $lng->txt('crs_mail_context_tutor_info');
57 }
58
62 public function getSpecificPlaceholders(): array
63 {
67 global $DIC;
68
69 $lng = $DIC['lng'];
70
71 $lng->loadLanguageModule('crs');
72 $lng->loadLanguageModule('trac');
73
74 // tracking settings
75 $tracking = new ilObjUserTracking();
76
77 $placeholders = array();
78
79 $placeholders['course_title'] = array(
80 'placeholder' => 'COURSE_TITLE',
81 'label' => $lng->txt('crs_title')
82 );
83
84 $placeholders['course_period_start'] = array(
85 'placeholder' => 'COURSE_PERIOD_START',
86 'label' => $lng->txt('crs_period_start_mail_placeholder')
87 );
88
89 $placeholders['course_period_end'] = array(
90 'placeholder' => 'COURSE_PERIOD_END',
91 'label' => $lng->txt('crs_period_end_mail_placeholder')
92 );
93
94 $placeholders['course_status'] = array(
95 'placeholder' => 'COURSE_STATUS',
96 'label' => $lng->txt('trac_status')
97 );
98
99 $placeholders['course_mark'] = array(
100 'placeholder' => 'COURSE_MARK',
101 'label' => $lng->txt('trac_mark')
102 );
103
104 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
105 $placeholders['course_time_spent'] = array(
106 'placeholder' => 'COURSE_TIME_SPENT',
107 'label' => $lng->txt('trac_spent_seconds')
108 );
109 }
110
111 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
112 $placeholders['course_first_access'] = array(
113 'placeholder' => 'COURSE_FIRST_ACCESS',
114 'label' => $lng->txt('trac_first_access')
115 );
116
117 $placeholders['course_last_access'] = array(
118 'placeholder' => 'COURSE_LAST_ACCESS',
119 'label' => $lng->txt('trac_last_access')
120 );
121 }
122
123 $placeholders['course_link'] = array(
124 'placeholder' => 'COURSE_LINK',
125 'label' => $lng->txt('crs_mail_permanent_link')
126 );
127
128 return $placeholders;
129 }
130
131 private function getCachedPeriodByObjId(int $objId): ?array
132 {
133 if (!array_key_exists($objId, self::$periodInfoByObjIdCache)) {
134 self::$periodInfoByObjIdCache[$objId] = ilObjCourseAccess::lookupPeriodInfo($objId);
135 }
136
137 return self::$periodInfoByObjIdCache[$objId];
138 }
139
143 public function resolveSpecificPlaceholder(
144 string $placeholder_id,
145 array $context_parameters,
146 ?ilObjUser $recipient = null
147 ): string {
151 global $DIC;
152
153 $ilObjDataCache = $DIC['ilObjDataCache'];
154
155 if (!in_array($placeholder_id, array(
156 'course_title',
157 'course_period_start',
158 'course_period_end',
159 'course_link',
160 'course_status',
161 'course_mark',
162 'course_time_spent',
163 'course_first_access',
164 'course_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 'course_title':
178 return $ilObjDataCache->lookupTitle($obj_id);
179
180 case 'course_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 'course_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 'course_link':
207 return ilLink::_getLink($context_parameters['ref_id'], 'crs');
208
209 case 'course_status':
210 if ($recipient === null) {
211 return '';
212 }
213
214 $status = ilLPStatus::_lookupStatus($obj_id, $recipient->getId());
215 if (!$status) {
217 }
219
220 case 'course_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 'course_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 'course_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 'course_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 formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
@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)
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ?ilObjUser $recipient=null)
static lookupPeriodInfo(int $a_obj_id)
User class.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57