ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
30  $lng = $DIC['lng'];
31 
32  $lng->loadLanguageModule('sahs');
33 
34  return $lng->txt('sahs_mail_context_lp');
35  }
36 
40  public function getDescription()
41  {
42  global $DIC;
43  $lng = $DIC['lng'];
44 
45  $lng->loadLanguageModule('sahs');
46 
47  return $lng->txt('sahs_mail_context_lp_info');
48  }
49 
54  public function getSpecificPlaceholders()
55  {
59  global $DIC;
60  $lng = $DIC['lng'];
61 
62  $lng->loadLanguageModule('trac');
63 
64  // tracking settings
65  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
66  $tracking = new ilObjUserTracking();
67 
68 
69  $placeholders = array();
70 
71 
72  $placeholders['sahs_title'] = array(
73  'placeholder' => 'SCORM_TITLE',
74  'label' => $lng->txt('obj_sahs')
75  );
76 
77  $placeholders['sahs_status'] = array(
78  'placeholder' => 'SCORM_STATUS',
79  'label' => $lng->txt('trac_status')
80  );
81 
82  $placeholders['sahs_mark'] = array(
83  'placeholder' => 'SCORM_MARK',
84  'label' => $lng->txt('trac_mark')
85  );
86 
87  // #17969
88  $lng->loadLanguageModule('content');
89  $placeholders['sahs_score'] = array(
90  'placeholder' => 'SCORM_SCORE',
91  'label' => $lng->txt('cont_score')
92  );
93 
94  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
95  $placeholders['sahs_time_spent'] = array(
96  'placeholder' => 'SCORM_TIME_SPENT',
97  'label' => $lng->txt('trac_spent_seconds')
98  );
99  }
100 
101  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
102  $placeholders['sahs_first_access'] = array(
103  'placeholder' => 'SCORM_FIRST_ACCESS',
104  'label' => $lng->txt('trac_first_access')
105  );
106 
107  $placeholders['sahs_last_access'] = array(
108  'placeholder' => 'SCORM_LAST_ACCESS',
109  'label' => $lng->txt('trac_last_access')
110  );
111  }
112 
113 
114  $placeholders['sahs_link'] = array(
115  'placeholder' => 'SCORM_LINK',
116  'label' => $lng->txt('perma_link')
117  );
118 
119  return $placeholders;
120  }
121 
125  public function resolveSpecificPlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient = null, $html_markup = false)
126  {
130  global $DIC;
131  $ilObjDataCache = $DIC['ilObjDataCache'];
132 
133  if (!in_array($placeholder_id, array('sahs_title', 'sahs_link'))) {
134  return '';
135  }
136 
137  $obj_id = $ilObjDataCache->lookupObjId($context_parameters['ref_id']);
138 
139  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
140  $tracking = new ilObjUserTracking();
141 
142  switch ($placeholder_id) {
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  return '';
153  }
154 
155  include_once './Services/Tracking/classes/class.ilLPStatus.php';
156  include_once './Services/Tracking/classes/class.ilLearningProgressBaseGUI.php';
157  $status = ilLPStatus::_lookupStatus($obj_id, $recipient->getId());
158  if (!$status) {
160  }
161  return ilLearningProgressBaseGUI::_getStatusText($status, $this->getLanguage());
162 
163  case 'sahs_mark':
164  if ($recipient === null) {
165  return '';
166  }
167 
168  include_once './Services/Tracking/classes/class.ilLPMarks.php';
169  $mark = ilLPMarks::_lookupMark($recipient->getId(), $obj_id);
170  return strlen(trim($mark)) ? $mark : '-';
171 
172  case 'sahs_score':
173  if ($recipient === null) {
174  return '';
175  }
176 
177  $scores = array();
178  $obj_id = ilObject::_lookupObjId($context_parameters['ref_id']);
179  include_once 'Modules/ScormAicc/classes/class.ilScormLP.php';
180  $coll = ilScormLP::getInstance($obj_id)->getCollectionInstance();
181  if ($coll->getItems()) {
182  include_once 'Services/Tracking/classes/class.ilTrQuery.php';
183  //changed static call into dynamic one//ukohnle
184  //foreach(ilTrQuery::getSCOsStatusForUser($recipient->getId(), $obj_id, $coll->getItems()) as $item)
185  $SCOStatusForUser = (new ilTrQuery)->getSCOsStatusForUser($recipient->getId(), $obj_id, $coll->getItems());
186  foreach ($SCOStatusForUser as $item) {
187  $scores[] = $item['title'] . ': ' . $item['score'];
188  }
189  }
190  return implode("\n", $scores);
191 
192  case 'sahs_time_spent':
193  if ($recipient === null) {
194  return '';
195  }
196 
197  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) {
198  include_once './Services/Tracking/classes/class.ilLearningProgress.php';
199  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
200  if (isset($progress['spent_seconds'])) {
201  return ilDatePresentation::secondsToString($progress['spent_seconds'], false, $this->getLanguage());
202  }
203  }
204  break;
205 
206  case 'sahs_first_access':
207  if ($recipient === null) {
208  return '';
209  }
210 
211  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
212  include_once './Services/Tracking/classes/class.ilLearningProgress.php';
213  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
214  if (isset($progress['access_time_min'])) {
215  return ilDatePresentation::formatDate(new ilDateTime($progress['access_time_min'], IL_CAL_UNIX));
216  }
217  }
218  break;
219 
220  case 'sahs_last_access':
221  if ($recipient === null) {
222  return '';
223  }
224 
225  if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) {
226  include_once './Services/Tracking/classes/class.ilLearningProgress.php';
227  $progress = ilLearningProgress::_getProgress($recipient->getId(), $obj_id);
228  if (isset($progress['access_time'])) {
229  return ilDatePresentation::formatDate(new ilDateTime($progress['access_time'], IL_CAL_UNIX));
230  }
231  }
232  break;
233  }
234 
235  return '';
236  }
237 }
global $DIC
Definition: saml.php:7
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
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
Tracking query class.
static secondsToString($seconds, $force_with_seconds=false, $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
$lng
static _lookupObjId($a_id)
Date and time handling
Class ilMailTemplateContext.
const LP_STATUS_NOT_ATTEMPTED_NUM
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.