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