ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCourseMailTemplateTutorContext.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
11{
12 const ID = 'crs_context_tutor_manual';
13
15 protected static $periodInfoByObjIdCache = [];
16
20 public function getId() : string
21 {
22 return self::ID;
23 }
24
28 public function getTitle() : string
29 {
30 global $DIC;
31
32 $lng = $DIC['lng'];
33
34 $lng->loadLanguageModule('crs');
35
36 return $lng->txt('crs_mail_context_tutor_title');
37 }
38
42 public function getDescription() : string
43 {
44 global $DIC;
45
46 $lng = $DIC['lng'];
47
48 $lng->loadLanguageModule('crs');
49
50 return $lng->txt('crs_mail_context_tutor_info');
51 }
52
57 public function getSpecificPlaceholders() : array
58 {
62 global $DIC;
63
64 $lng = $DIC['lng'];
65
66 $lng->loadLanguageModule('crs');
67 $lng->loadLanguageModule('trac');
68
69 // tracking settings
70 include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
71 $tracking = new ilObjUserTracking();
72
73
74 $placeholders = array();
75
76
77 $placeholders['crs_title'] = array(
78 'placeholder' => 'COURSE_TITLE',
79 'label' => $lng->txt('crs_title')
80 );
81
82 $placeholders['crs_period_start'] = array(
83 'placeholder' => 'COURSE_PERIOD_START',
84 'label' => $lng->txt('crs_period_start_mail_placeholder')
85 );
86
87 $placeholders['crs_period_end'] = array(
88 'placeholder' => 'COURSE_PERIOD_END',
89 'label' => $lng->txt('crs_period_end_mail_placeholder')
90 );
91
92 $placeholders['crs_status'] = array(
93 'placeholder' => 'COURSE_STATUS',
94 'label' => $lng->txt('trac_status')
95 );
96
97 $placeholders['crs_mark'] = array(
98 'placeholder' => 'COURSE_MARK',
99 'label' => $lng->txt('trac_mark')
100 );
101
102 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
103 $placeholders['crs_time_spent'] = array(
104 'placeholder' => 'COURSE_TIME_SPENT',
105 'label' => $lng->txt('trac_spent_seconds')
106 );
107 }
108
109 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
110 $placeholders['crs_first_access'] = array(
111 'placeholder' => 'COURSE_FIRST_ACCESS',
112 'label' => $lng->txt('trac_first_access')
113 );
114
115 $placeholders['crs_last_access'] = array(
116 'placeholder' => 'COURSE_LAST_ACCESS',
117 'label' => $lng->txt('trac_last_access')
118 );
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
134 private function getCachedPeriodByObjId(int $objId)
135 {
136 if (!array_key_exists($objId, self::$periodInfoByObjIdCache)) {
137 self::$periodInfoByObjIdCache[$objId] = ilObjCourseAccess::lookupPeriodInfo($objId);
138 }
139
140 return self::$periodInfoByObjIdCache[$objId];
141 }
142
146 public function resolveSpecificPlaceholder(
147 string $placeholder_id,
148 array $context_parameters,
149 ilObjUser $recipient = null,
150 bool $html_markup = false
151 ) : string {
155 global $DIC;
156
157 $ilObjDataCache = $DIC['ilObjDataCache'];
158
159 if (!in_array($placeholder_id, array(
160 'crs_title',
161 'crs_period_start',
162 'crs_period_end',
163 'crs_link',
164 'crs_status',
165 'crs_mark',
166 'crs_time_spent',
167 'crs_first_access',
168 'crs_last_access'
169 ))) {
170 return '';
171 }
172
173 $obj_id = $ilObjDataCache->lookupObjId($context_parameters['ref_id']);
174
175 $tracking = new ilObjUserTracking();
176
177 $this->getLanguage()->loadLanguageModule('trac');
178 $this->getLanguage()->loadLanguageModule('crs');
179
180 switch ($placeholder_id) {
181 case 'crs_title':
182 return $ilObjDataCache->lookupTitle($obj_id);
183
184 case 'crs_period_start':
185 $periodInfo = $this->getCachedPeriodByObjId((int) $ilObjDataCache->lookupObjId($context_parameters['ref_id']));
186 if ($periodInfo) {
187 $useRelativeDates = ilDatePresentation::useRelativeDates();
189 $formattedDate = ilDatePresentation::formatDate($periodInfo['crs_start']);
191
192 return $formattedDate;
193 }
194
195 return '';
196
197 case 'crs_period_end':
198 $periodInfo = $this->getCachedPeriodByObjId((int) $ilObjDataCache->lookupObjId($context_parameters['ref_id']));
199 if ($periodInfo) {
200 $useRelativeDates = ilDatePresentation::useRelativeDates();
202 $formattedDate = ilDatePresentation::formatDate($periodInfo['crs_end']);
204
205 return $formattedDate;
206 }
207
208 return '';
209
210 case 'crs_link':
211 return ilLink::_getLink($context_parameters['ref_id'], 'crs');
212
213 case 'crs_status':
214 if ($recipient === null) {
215 return '';
216 }
217
218 $status = ilLPStatus::_lookupStatus($obj_id, $recipient->getId());
219 if (!$status) {
221 }
223
224 case 'crs_mark':
225 if ($recipient === null) {
226 return '';
227 }
228
229 $mark = ilLPMarks::_lookupMark($recipient->getId(), $obj_id);
230 return (is_string($mark) && strlen(trim($mark))) ? $mark : '-';
231
232 case 'crs_time_spent':
233 if ($recipient === null) {
234 return '';
235 }
236
237 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
238 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
239 if (isset($progress['spent_seconds'])) {
241 $progress['spent_seconds'],
242 false,
243 $this->getLanguage()
244 );
245 }
246 }
247 break;
248
249 case 'crs_first_access':
250 if ($recipient === null) {
251 return '';
252 }
253
254 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
255 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
256 if (isset($progress['access_time_min'])) {
258 $progress['access_time_min'],
260 ));
261 }
262 }
263 break;
264
265 case 'crs_last_access':
266 if ($recipient === null) {
267 return '';
268 }
269
270 if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
271 $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
272 if (isset($progress['access_time'])) {
273 return ilDatePresentation::formatDate(new ilDateTime($progress['access_time'], IL_CAL_UNIX));
274 }
275 }
276 break;
277 }
278
279 return '';
280 }
281}
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.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
@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 lookupPeriodInfo($a_obj_id)
Lookup course period info.
global $DIC
Definition: goto.php:24
$lng
$objId
Definition: xapitoken.php:39