ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORMCertificateAdapter.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Services/Certificate/classes/class.ilCertificateAdapter.php";
25 
34 {
35  protected $object;
36 
42  function __construct(&$object)
43  {
44  $this->object =& $object;
45  }
46 
52  public function getCertificatePath()
53  {
54  return CLIENT_WEB_DIR . "/certificates/scorm/" . $this->object->getId() . "/";
55  }
56 
64  {
65  global $lng;
66 
67  $vars = $this->getBaseVariablesForPreview();
68  $vars["SCORM_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
69  $vars["SCORM_POINTS"] = number_format(80.7, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand")) . " %";
70  $vars["SCORM_POINTS_MAX"] = number_format(90, 0, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
71 
72  $insert_tags = array();
73  foreach($vars as $id => $caption)
74  {
75  $insert_tags["[".$id."]"] = $caption;
76  }
77 
78  include_once 'Services/Tracking/classes/class.ilLPCollections.php';
79  $lp_collections = new ilLPCollections($this->object->getId());
80 
81  $counter=0;
82  foreach(ilLPCollections::_getPossibleSAHSItems($this->object->getId()) as $item_id => $sahs_item)
83  {
84  if($lp_collections->isAssigned($item_id)) {
85  $insert_tags['[SCO_T_'.$counter.']'] = $sahs_item['title'];
86  $insert_tags['[SCO_P_'.$counter.']'] = number_format(30.3, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
87  $insert_tags['[SCO_PM_'.$counter.']'] = number_format(90.9, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
88  $insert_tags['[SCO_PP_'.$counter.']'] = number_format(33.3333, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand")) . " %";
89  $counter++;
90  }
91  }
92 
93  return $insert_tags;
94  }
95 
104  public function getCertificateVariablesForPresentation($params = array())
105  {
106  global $lng,$ilUser;
107 
108  $lng->loadLanguageModule('certificate');
109 
110  $points = $this->object->getPointsInPercent();
111  $txtPoints = "";
112  if (is_null($points))
113  {
114  $txtPoints = $lng->txt("certificate_points_notavailable");
115  }
116  else
117  {
118  $txtPoints = number_format($points, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand")) . " %";
119  }
120 
121  $max_points = $this->object->getMaxPoints();
122  $txtMaxPoints = '';
123  if (is_null($max_points))
124  {
125  $txtMaxPoints = $lng->txt("certificate_points_notavailable");
126  }
127  else
128  {
129  if($max_points != floor($max_points))
130  {
131  $txtMaxPoints = number_format($max_points, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
132  }
133  else
134  {
135  $txtMaxPoints = $max_points;
136  }
137  }
138 
139  $user_data = $params["user_data"];
140  $completion_date = $this->getUserCompletionDate($user_data["usr_id"]);
141 
142  $vars = $this->getBaseVariablesForPresentation($user_data, $params["last_access"], $completion_date);
143  $vars["SCORM_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
144  $vars["SCORM_POINTS"] = $txtPoints;
145  $vars["SCORM_POINTS_MAX"] = $txtMaxPoints;
146 
147  foreach($vars as $id => $caption)
148  {
149  $insert_tags["[".$id."]"] = $caption;
150  }
151 
152  include_once 'Services/Tracking/classes/class.ilLPCollections.php';
153  $lp_collections = new ilLPCollections($this->object->getId());
154 
155  $counter=0;
156  foreach(ilLPCollections::_getPossibleSAHSItems($this->object->getId()) as $item_id => $sahs_item)
157  {
158  if($lp_collections->isAssigned($item_id)) {
159  $insert_tags['[SCO_T_'.$counter.']'] = $sahs_item['title'];//." getId=".$this->object->getId()." item_id=".$item_id." user_id=".$ilUser->getId()
160  $a_scores = ilLPCollections::_getScoresForUserAndCP_Node_Id($this->object->getId(), $item_id, $ilUser->getId());
161  if ($a_scores["raw"] == null) $insert_tags['[SCO_P_'.$counter.']'] = $lng->txt("certificate_points_notavailable");
162  else $insert_tags['[SCO_P_'.$counter.']'] = number_format($a_scores["raw"], 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
163  if ($a_scores["max"] == null) $insert_tags['[SCO_PM_'.$counter.']'] = $lng->txt("certificate_points_notavailable");
164  else $insert_tags['[SCO_PM_'.$counter.']'] = number_format($a_scores["max"], 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
165  if ($a_scores["scaled"] == null) $insert_tags['[SCO_PP_'.$counter.']'] = $lng->txt("certificate_points_notavailable");
166  else $insert_tags['[SCO_PP_'.$counter.']'] = number_format(($a_scores["scaled"]*100), 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand")) . " %";
167  $counter++;
168  }
169  }
170 
171  return $insert_tags;
172  }
173 
181  {
182  global $lng;
183 
184  $vars = $this->getBaseVariablesDescription();
185  $vars["SCORM_TITLE"] = $lng->txt("certificate_ph_scormtitle");
186  $vars["SCORM_POINTS"] = $lng->txt("certificate_ph_scormpoints");
187  $vars["SCORM_POINTS_MAX"] = $lng->txt("certificate_ph_scormmaxpoints");
188 
189  $template = new ilTemplate("tpl.certificate_edit.html", TRUE, TRUE, "Modules/ScormAicc");
190  $template->setCurrentBlock("items");
191  foreach($vars as $id => $caption)
192  {
193  $template->setVariable("ID", $id);
194  $template->setVariable("TXT", $caption);
195  $template->parseCurrentBlock();
196  }
197 
198  $template->setVariable("PH_INTRODUCTION", $lng->txt("certificate_ph_introduction"));
199 
200  include_once 'Services/Tracking/classes/class.ilLPCollections.php';
201  $lp_collections = new ilLPCollections($this->object->getId());
202 
203  if(!$items = ilLPCollections::_getPossibleSAHSItems($this->object->getId())) {
204  $template->setCurrentBlock('NO_SCO');
205  $template->setVariable('PH_NO_SCO',$lng->txt('certificate_ph_no_sco'));
206  $template->parseCurrentBlock();
207  }
208  else {
209  $template->setCurrentBlock('SCOS');
210  $template->setVariable('PH_SCOS',$lng->txt('certificate_ph_scos'));
211  $template->parseCurrentBlock();
212  $template->setCurrentBlock('SCO_HEADER');
213  $template->setVariable('PH_TITLE_SCO',$lng->txt('certificate_ph_title_sco'));
214  //$template->setVariable('PH_PH',$lng->txt('certificate_ph_ph'));
215  $template->setVariable('PH_SCO_TITLE',$lng->txt('certificate_ph_sco_title'));
216  $template->setVariable('PH_SCO_POINTS_RAW',$lng->txt('certificate_ph_sco_points_raw'));
217  $template->setVariable('PH_SCO_POINTS_MAX',$lng->txt('certificate_ph_sco_points_max'));
218  $template->setVariable('PH_SCO_POINTS_SCALED',$lng->txt('certificate_ph_sco_points_scaled'));
219  $template->parseCurrentBlock();
220  }
221 
222  $counter=0;
223  foreach(ilLPCollections::_getPossibleSAHSItems($this->object->getId()) as $item_id => $sahs_item)
224  {
225  if($lp_collections->isAssigned($item_id)) {
226  $template->setCurrentBlock("SCO");
227  $template->setVariable('SCO_TITLE',$sahs_item['title']);
228  $template->setVariable('PH_SCO_TITLE','[SCO_T_'.$counter.']');
229  $template->setVariable('PH_SCO_POINTS_RAW','[SCO_P_'.$counter.']');
230  $template->setVariable('PH_SCO_POINTS_MAX','[SCO_PM_'.$counter.']');
231  $template->setVariable('PH_SCO_POINTS_SCALED','[SCO_PP_'.$counter.']');
232  $template->parseCurrentBlock();
233  $counter++;
234  }
235  }
236 
237  return $template->get();
238  }
239 
249  public function addAdditionalFormElements(&$form, $form_fields)
250  {
251  global $lng;
252  $short_name = new ilTextInputGUI($lng->txt("certificate_short_name"), "short_name");
253  $short_name->setRequired(TRUE);
254  require_once "./Services/Utilities/classes/class.ilStr.php";
255  $short_name->setValue(strlen($form_fields["short_name"]) ? $form_fields["short_name"] : ilStr::subStr($this->object->getTitle(), 0, 30));
256  $short_name->setSize(30);
257  if (strlen($form_fields["short_name"])) {
258  $short_name->setInfo(str_replace("[SHORT_TITLE]", $form_fields["short_name"], $lng->txt("certificate_short_name_description")));
259  } else {
260  $short_name->setInfo($lng->txt("certificate_short_name_description"));
261  }
262  if (count($_POST)) $short_name->checkInput();
263  $form->addItem($short_name);
264 
265  $visibility = new ilCheckboxInputGUI($lng->txt("certificate_enabled_scorm"), "certificate_enabled_scorm");
266  $visibility->setInfo($lng->txt("certificate_enabled_scorm_introduction"));
267  $visibility->setValue(1);
268  if ($form_fields["certificate_enabled_scorm"])
269  {
270  $visibility->setChecked(TRUE);
271  }
272  if (count($_POST)) $visibility->checkInput();
273  $form->addItem($visibility);
274  }
275 
284  public function addFormFieldsFromPOST(&$form_fields)
285  {
286  $form_fields["certificate_enabled_scorm"] = $_POST["certificate_enabled_scorm"];
287  $form_fields["short_name"] = $_POST["short_name"];
288  }
289 
298  public function addFormFieldsFromObject(&$form_fields)
299  {
300  global $ilSetting;
301  $scormSetting = new ilSetting("scorm");
302  $form_fields["certificate_enabled_scorm"] = $scormSetting->get("certificate_" . $this->object->getId());
303  $form_fields["short_name"] = $scormSetting->get("certificate_short_name_" . $this->object->getId());
304  }
305 
313  public function saveFormFields(&$form_fields)
314  {
315  global $ilSetting;
316  $scormSetting = new ilSetting("scorm");
317  $scormSetting->set("certificate_" . $this->object->getId(), $form_fields["certificate_enabled_scorm"]);
318  $scormSetting->set("certificate_short_name_" . $this->object->getId(), $form_fields["short_name"]);
319  }
320 
327  public function getAdapterType()
328  {
329  return "scorm";
330  }
331 
338  public function getCertificateID()
339  {
340  return $this->object->getId();
341  }
342 
349  public function getCertificateFilename($params = array())
350  {
351  global $lng;
352 
353  $basename = parent::getCertificateFilename($params);
354 
355  $user_data = $params["user_data"];
356  if (!is_array($user_data))
357  {
358  global $ilSetting;
359  $scormSetting = new ilSetting("scorm");
360  $short_title = $scormSetting->get("certificate_short_name_" . $this->object->getId());
361  return strftime("%y%m%d", time()) . "_" . $lng->txt("certificate_var_user_lastname") . "_" . $short_title . "_" . $basename;
362  }
363  else
364  {
365  return strftime("%y%m%d", time()) . "_" . $user_data["lastname"] . "_" . $params["short_title"] . "_.$basename";
366  }
367  }
368 
374  public function deleteCertificate()
375  {
376  global $ilSetting;
377  $scormSetting = new ilSetting("scorm");
378  $scormSetting->delete("certificate_" . $this->object->getId());
379  }
380 
387  function getUserIdForParams($a_params)
388  {
389  return $a_params["user_data"]["usr_id"];
390  }
391 
392 }
393 
394 ?>