ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules 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/Object/classes/class.ilObjectLP.php';
79  $olp = ilObjectLP::getInstance($this->object->getId());
80  $collection = $olp->getCollectionInstance();
81  if($collection)
82  {
83  $counter=0;
84  foreach($collection->getPossibleItems() as $item_id => $sahs_item)
85  {
86  if($collection->isAssignedEntry($item_id)) {
87  $insert_tags['[SCO_T_'.$counter.']'] = $sahs_item['title'];
88  $insert_tags['[SCO_P_'.$counter.']'] = number_format(30.3, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
89  $insert_tags['[SCO_PM_'.$counter.']'] = number_format(90.9, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
90  $insert_tags['[SCO_PP_'.$counter.']'] = number_format(33.3333, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand")) . " %";
91  $counter++;
92  }
93  }
94  }
95 
96  return $insert_tags;
97  }
98 
107  public function getCertificateVariablesForPresentation($params = array())
108  {
109  global $lng,$ilUser;
110 
111  $lng->loadLanguageModule('certificate');
112 
113  $points = $this->object->getPointsInPercent();
114  $txtPoints = "";
115  if (is_null($points))
116  {
117  $txtPoints = $lng->txt("certificate_points_notavailable");
118  }
119  else
120  {
121  $txtPoints = number_format($points, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand")) . " %";
122  }
123 
124  $max_points = $this->object->getMaxPoints();
125  $txtMaxPoints = '';
126  if (is_null($max_points))
127  {
128  $txtMaxPoints = $lng->txt("certificate_points_notavailable");
129  }
130  else
131  {
132  if($max_points != floor($max_points))
133  {
134  $txtMaxPoints = number_format($max_points, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
135  }
136  else
137  {
138  $txtMaxPoints = $max_points;
139  }
140  }
141 
142  $user_data = $params["user_data"];
143  $completion_date = $this->getUserCompletionDate($user_data["usr_id"]);
144 
145  $vars = $this->getBaseVariablesForPresentation($user_data, $params["last_access"], $completion_date);
146  $vars["SCORM_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
147  $vars["SCORM_POINTS"] = $txtPoints;
148  $vars["SCORM_POINTS_MAX"] = $txtMaxPoints;
149 
150  foreach($vars as $id => $caption)
151  {
152  $insert_tags["[".$id."]"] = $caption;
153  }
154 
155  include_once 'Services/Object/classes/class.ilObjectLP.php';
156  $olp = ilObjectLP::getInstance($this->object->getId());
157  $collection = $olp->getCollectionInstance();
158  if($collection)
159  {
160  $counter=0;
161  foreach($collection->getPossibleItems() as $item_id => $sahs_item)
162  {
163  if($collection->isAssignedEntry($item_id)) {
164  $insert_tags['[SCO_T_'.$counter.']'] = $sahs_item['title'];//." getId=".$this->object->getId()." item_id=".$item_id." user_id=".$ilUser->getId()
165  $a_scores = $collection->getScoresForUserAndCP_Node_Id($item_id, $ilUser->getId());
166  if ($a_scores["raw"] == null) $insert_tags['[SCO_P_'.$counter.']'] = $lng->txt("certificate_points_notavailable");
167  else $insert_tags['[SCO_P_'.$counter.']'] = number_format($a_scores["raw"], 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
168  if ($a_scores["max"] == null) $insert_tags['[SCO_PM_'.$counter.']'] = $lng->txt("certificate_points_notavailable");
169  else $insert_tags['[SCO_PM_'.$counter.']'] = number_format($a_scores["max"], 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand"));
170  if ($a_scores["scaled"] == null) $insert_tags['[SCO_PP_'.$counter.']'] = $lng->txt("certificate_points_notavailable");
171  else $insert_tags['[SCO_PP_'.$counter.']'] = number_format(($a_scores["scaled"]*100), 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand")) . " %";
172  $counter++;
173  }
174  }
175  }
176 
177  return $insert_tags;
178  }
179 
187  {
188  global $lng;
189 
190  $vars = $this->getBaseVariablesDescription();
191  $vars["SCORM_TITLE"] = $lng->txt("certificate_ph_scormtitle");
192  $vars["SCORM_POINTS"] = $lng->txt("certificate_ph_scormpoints");
193  $vars["SCORM_POINTS_MAX"] = $lng->txt("certificate_ph_scormmaxpoints");
194 
195  $template = new ilTemplate("tpl.certificate_edit.html", TRUE, TRUE, "Modules/ScormAicc");
196  $template->setCurrentBlock("items");
197  foreach($vars as $id => $caption)
198  {
199  $template->setVariable("ID", $id);
200  $template->setVariable("TXT", $caption);
201  $template->parseCurrentBlock();
202  }
203 
204  $template->setVariable("PH_INTRODUCTION", $lng->txt("certificate_ph_introduction"));
205 
206  include_once 'Services/Object/classes/class.ilObjectLP.php';
207  $olp = ilObjectLP::getInstance($this->object->getId());
208  $collection = $olp->getCollectionInstance();
209  if($collection)
210  {
211  $items = $collection->getPossibleItems();
212  }
213 
214  if(!$items) {
215  $template->setCurrentBlock('NO_SCO');
216  $template->setVariable('PH_NO_SCO',$lng->txt('certificate_ph_no_sco'));
217  $template->parseCurrentBlock();
218  }
219  else {
220  $template->setCurrentBlock('SCOS');
221  $template->setVariable('PH_SCOS',$lng->txt('certificate_ph_scos'));
222  $template->parseCurrentBlock();
223  $template->setCurrentBlock('SCO_HEADER');
224  $template->setVariable('PH_TITLE_SCO',$lng->txt('certificate_ph_title_sco'));
225  //$template->setVariable('PH_PH',$lng->txt('certificate_ph_ph'));
226  $template->setVariable('PH_SCO_TITLE',$lng->txt('certificate_ph_sco_title'));
227  $template->setVariable('PH_SCO_POINTS_RAW',$lng->txt('certificate_ph_sco_points_raw'));
228  $template->setVariable('PH_SCO_POINTS_MAX',$lng->txt('certificate_ph_sco_points_max'));
229  $template->setVariable('PH_SCO_POINTS_SCALED',$lng->txt('certificate_ph_sco_points_scaled'));
230  $template->parseCurrentBlock();
231  }
232 
233  if($collection)
234  {
235  $counter=0;
236  foreach($items as $item_id => $sahs_item)
237  {
238  if($collection->isAssignedEntry($item_id)) {
239  $template->setCurrentBlock("SCO");
240  $template->setVariable('SCO_TITLE',$sahs_item['title']);
241  $template->setVariable('PH_SCO_TITLE','[SCO_T_'.$counter.']');
242  $template->setVariable('PH_SCO_POINTS_RAW','[SCO_P_'.$counter.']');
243  $template->setVariable('PH_SCO_POINTS_MAX','[SCO_PM_'.$counter.']');
244  $template->setVariable('PH_SCO_POINTS_SCALED','[SCO_PP_'.$counter.']');
245  $template->parseCurrentBlock();
246  $counter++;
247  }
248  }
249  }
250 
251  return $template->get();
252  }
253 
263  public function addAdditionalFormElements(&$form, $form_fields)
264  {
265  global $lng;
266  $short_name = new ilTextInputGUI($lng->txt("certificate_short_name"), "short_name");
267  $short_name->setRequired(TRUE);
268  require_once "./Services/Utilities/classes/class.ilStr.php";
269  $short_name->setValue(strlen($form_fields["short_name"]) ? $form_fields["short_name"] : ilStr::subStr($this->object->getTitle(), 0, 30));
270  $short_name->setSize(30);
271  if (strlen($form_fields["short_name"])) {
272  $short_name->setInfo(str_replace("[SHORT_TITLE]", $form_fields["short_name"], $lng->txt("certificate_short_name_description")));
273  } else {
274  $short_name->setInfo($lng->txt("certificate_short_name_description"));
275  }
276  if (count($_POST)) $short_name->checkInput();
277  $form->addItem($short_name);
278 
279  $visibility = new ilCheckboxInputGUI($lng->txt("certificate_enabled_scorm"), "certificate_enabled_scorm");
280  $visibility->setInfo($lng->txt("certificate_enabled_scorm_introduction"));
281  $visibility->setValue(1);
282  if ($form_fields["certificate_enabled_scorm"])
283  {
284  $visibility->setChecked(TRUE);
285  }
286  if (count($_POST)) $visibility->checkInput();
287  $form->addItem($visibility);
288  }
289 
298  public function addFormFieldsFromPOST(&$form_fields)
299  {
300  $form_fields["certificate_enabled_scorm"] = $_POST["certificate_enabled_scorm"];
301  $form_fields["short_name"] = $_POST["short_name"];
302  }
303 
312  public function addFormFieldsFromObject(&$form_fields)
313  {
314  global $ilSetting;
315  $scormSetting = new ilSetting("scorm");
316  $form_fields["certificate_enabled_scorm"] = $scormSetting->get("certificate_" . $this->object->getId());
317  $form_fields["short_name"] = $scormSetting->get("certificate_short_name_" . $this->object->getId());
318  }
319 
327  public function saveFormFields(&$form_fields)
328  {
329  global $ilSetting;
330  $scormSetting = new ilSetting("scorm");
331  $scormSetting->set("certificate_" . $this->object->getId(), $form_fields["certificate_enabled_scorm"]);
332  $scormSetting->set("certificate_short_name_" . $this->object->getId(), $form_fields["short_name"]);
333  }
334 
341  public function getAdapterType()
342  {
343  return "scorm";
344  }
345 
352  public function getCertificateID()
353  {
354  return $this->object->getId();
355  }
356 
363  public function getCertificateFilename($params = array())
364  {
365  global $lng;
366 
367  $basename = parent::getCertificateFilename($params);
368 
369  $user_data = $params["user_data"];
370  if (!is_array($user_data))
371  {
372  global $ilSetting;
373  $scormSetting = new ilSetting("scorm");
374  $short_title = $scormSetting->get("certificate_short_name_" . $this->object->getId());
375  return strftime("%y%m%d", time()) . "_" . $lng->txt("certificate_var_user_lastname") . "_" . $short_title . "_" . $basename;
376  }
377  else
378  {
379  return strftime("%y%m%d", time()) . "_" . $user_data["lastname"] . "_" . $params["short_title"] . "_.$basename";
380  }
381  }
382 
388  public function deleteCertificate()
389  {
390  global $ilSetting;
391  $scormSetting = new ilSetting("scorm");
392  $scormSetting->delete("certificate_" . $this->object->getId());
393  }
394 
401  function getUserIdForParams($a_params)
402  {
403  return $a_params["user_data"]["usr_id"];
404  }
405 
406 }
407 
408 ?>
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
ILIAS Setting Class.
getCertificateVariablesForPreview()
Returns an array containing all variables and values which can be exchanged in the certificate...
getUserCompletionDate($a_user_id, $a_object_id=null)
Get completion for user.
$_POST['username']
Definition: cron.php:12
addFormFieldsFromPOST(&$form_fields)
Allows to add additional form values to the array of form values evaluating a HTTP POST action...
addAdditionalFormElements(&$form, $form_fields)
Allows to add additional form fields to the certificate editor form This method will be called when t...
This class represents a checkbox property in a property form.
deleteCertificate()
Is called when the certificate is deleted Add some adapter specific code if more work has to be done ...
getCertificateVariablesDescription()
Returns a description of the available certificate parameters.
setInfo($a_info)
Set Information Text.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
getBaseVariablesDescription($a_enable_last_access=true, $a_enable_completion_date=true)
Get variable descriptions.
getCertificateVariablesForPresentation($params=array())
Returns an array containing all variables and values which can be exchanged in the certificate The va...
__construct(&$object)
ilSCORMCertificateAdapter contructor
getCertificatePath()
Returns the certificate path (with a trailing path separator)
getCertificateID()
Returns a certificate ID This value will be used to generate unique file names for the certificates...
addFormFieldsFromObject(&$form_fields)
Allows to add additional form values to the array of form values evaluating the associated adapter cl...
getUserIdForParams($a_params)
Get user id for params.
global $ilUser
Definition: imgupload.php:15
global $ilSetting
Definition: privfeed.php:40
global $lng
Definition: privfeed.php:40
Adapter class to provide certificate data for the certificate generator.
getBaseVariablesForPreview($a_enable_last_access=true, $a_enable_completion_date=true)
Get variable dummys.
saveFormFields(&$form_fields)
Allows to save additional adapter form fields This method will be called when the certificate editor ...
getBaseVariablesForPresentation($a_user_data, $a_last_access=null, $a_completion_date=false)
Get variable values.
static subStr($a_str, $a_start, $a_length=NULL)
Definition: class.ilStr.php:15
static getInstance($a_obj_id)
getAdapterType()
Returns the adapter type This value will be used to generate file names for the certificates.
setRequired($a_required)
Set Required.
getCertificateFilename($params=array())
Set the name of the certificate file This method will be called when the certificate will be generate...