ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
93  $placeholders['sahs_time_spent'] = array(
94  'placeholder' => 'SCORM_TIME_SPENT',
95  'label' => $lng->txt('trac_spent_seconds')
96  );
97  }
98 
99  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS))
100  {
101  $placeholders['sahs_first_access'] = array(
102  'placeholder' => 'SCORM_FIRST_ACCESS',
103  'label' => $lng->txt('trac_first_access')
104  );
105 
106  $placeholders['sahs_last_access'] = array(
107  'placeholder' => 'SCORM_LAST_ACCESS',
108  'label' => $lng->txt('trac_last_access')
109  );
110  }
111 
112 
113  $placeholders['sahs_link'] = array(
114  'placeholder' => 'SCORM_LINK',
115  'label' => $lng->txt('perma_link')
116  );
117 
118  return $placeholders;
119  }
120 
124  public function resolveSpecificPlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient = null, $html_markup = false)
125  {
129  global $ilObjDataCache;
130 
131  if(!in_array($placeholder_id, array('sahs_title', 'sahs_link')))
132  {
133  return '';
134  }
135 
136  $obj_id = $ilObjDataCache->lookupObjId($context_parameters['ref_id']);
137 
138  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
139  $tracking = new ilObjUserTracking();
140 
141  switch($placeholder_id)
142  {
143  case 'sahs_title':
144  return $ilObjDataCache->lookupTitle($obj_id);
145 
146  case 'sahs_link':
147  require_once './Services/Link/classes/class.ilLink.php';
148  return ilLink::_getLink($context_parameters['ref_id'], 'sahs');
149 
150  case 'sahs_status':
151  if($recipient === null)
152  {
153  return '';
154  }
155 
156  include_once './Services/Tracking/classes/class.ilLPStatus.php';
157  include_once './Services/Tracking/classes/class.ilLearningProgressBaseGUI.php';
158  $status = ilLPStatus::_lookupStatus($obj_id, $recipient->getId());
159  if(!$status)
160  {
162  }
163  return ilLearningProgressBaseGUI::_getStatusText($status, $this->getLanguage());
164 
165  case 'sahs_mark':
166  if($recipient === null)
167  {
168  return '';
169  }
170 
171  include_once './Services/Tracking/classes/class.ilLPMarks.php';
172  $mark = ilLPMarks::_lookupMark($recipient->getId(), $obj_id);
173  return strlen(trim($mark)) ? $mark : '-';
174 
175  case 'sahs_score':
176  if($recipient === null)
177  {
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  {
187  include_once 'Services/Tracking/classes/class.ilTrQuery.php';
188  //changed static call into dynamic one//ukohnle
189  //foreach(ilTrQuery::getSCOsStatusForUser($recipient->getId(), $obj_id, $coll->getItems()) as $item)
190  $SCOStatusForUser = (new ilTrQuery)->getSCOsStatusForUser($recipient->getId(), $obj_id, $coll->getItems());
191  foreach($SCOStatusForUser as $item)
192  {
193  $scores[] = $item['title'].': '.$item['score'];
194  }
195  }
196  return implode("\n", $scores);
197 
198  case 'sahs_time_spent':
199  if($recipient === null)
200  {
201  return '';
202  }
203 
204  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS))
205  {
206  include_once './Services/Tracking/classes/class.ilLearningProgress.php';
207  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
208  if(isset($progress['spent_seconds']))
209  {
210  return ilDatePresentation::secondsToString($progress['spent_seconds'], false, $this->getLanguage());
211  }
212  }
213  break;
214 
215  case 'sahs_first_access':
216  if($recipient === null)
217  {
218  return '';
219  }
220 
221  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS))
222  {
223  include_once './Services/Tracking/classes/class.ilLearningProgress.php';
224  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
225  if(isset($progress['access_time_min']))
226  {
227  return ilDatePresentation::formatDate(new ilDateTime($progress['access_time_min'], IL_CAL_UNIX));
228  }
229  }
230  break;
231 
232  case 'sahs_last_access':
233  if($recipient === null)
234  {
235  return '';
236  }
237 
238  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS))
239  {
240  include_once './Services/Tracking/classes/class.ilLearningProgress.php';
241  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
242  if(isset($progress['access_time']))
243  {
244  return ilDatePresentation::formatDate(new ilDateTime($progress['access_time'], IL_CAL_UNIX));
245  }
246  }
247  break;
248  }
249 
250  return '';
251  }
252 }
253 ?>
static _getStatusText($a_status, $a_lng=null)
Get status alt text.
resolveSpecificPlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient=null, $html_markup=false)
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)
static formatDate(ilDateTime $date)
Format a date public.
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.