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