ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public function __construct($object)
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  $vars = $this->getBaseVariablesForPreview();
67  $vars["SCORM_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
68  $vars["SCORM_POINTS"] = number_format(80.7, 1, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand")) . " %";
69  $vars["SCORM_POINTS_MAX"] = number_format(90, 0, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand"));
70 
71  $insert_tags = array();
72  foreach ($vars as $id => $caption) {
73  $insert_tags["[" . $id . "]"] = $caption;
74  }
75 
76  include_once 'Services/Object/classes/class.ilObjectLP.php';
77  $olp = ilObjectLP::getInstance($this->object->getId());
78  $collection = $olp->getCollectionInstance();
79  if ($collection) {
80  $counter=0;
81  foreach ($collection->getPossibleItems() as $item_id => $sahs_item) {
82  if ($collection->isAssignedEntry($item_id)) {
83  $insert_tags['[SCO_T_' . $counter . ']'] = $sahs_item['title'];
84  $insert_tags['[SCO_P_' . $counter . ']'] = number_format(30.3, 1, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand"));
85  $insert_tags['[SCO_PM_' . $counter . ']'] = number_format(90.9, 1, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand"));
86  $insert_tags['[SCO_PP_' . $counter . ']'] = number_format(33.3333, 1, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand")) . " %";
87  $counter++;
88  }
89  }
90  }
91 
92  return $insert_tags;
93  }
94 
104  {
105  $this->lng->loadLanguageModule('certificate');
106 
107  $points = $this->object->getPointsInPercent();
108  $txtPoints = "";
109  if (is_null($points)) {
110  $txtPoints = $this->lng->txt("certificate_points_notavailable");
111  } else {
112  $txtPoints = number_format($points, 1, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand")) . " %";
113  }
114 
115  $max_points = $this->object->getMaxPoints();
116  $txtMaxPoints = '';
117  if (is_null($max_points)) {
118  $txtMaxPoints = $this->lng->txt("certificate_points_notavailable");
119  } else {
120  if ($max_points != floor($max_points)) {
121  $txtMaxPoints = number_format($max_points, 1, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand"));
122  } else {
123  $txtMaxPoints = $max_points;
124  }
125  }
126 
127  $user_data = $params["user_data"];
128  $completion_date = $this->getUserCompletionDate($user_data["usr_id"]);
129 
130  $vars = $this->getBaseVariablesForPresentation($user_data, $params["last_access"], $completion_date);
131  $vars["SCORM_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
132  $vars["SCORM_POINTS"] = $txtPoints;
133  $vars["SCORM_POINTS_MAX"] = $txtMaxPoints;
134 
135  foreach ($vars as $id => $caption) {
136  $insert_tags["[" . $id . "]"] = $caption;
137  }
138 
139  include_once 'Services/Object/classes/class.ilObjectLP.php';
140  $olp = ilObjectLP::getInstance($this->object->getId());
141  $collection = $olp->getCollectionInstance();
142  if ($collection) {
143  $counter=0;
144  foreach ($collection->getPossibleItems() as $item_id => $sahs_item) {
145  if ($collection->isAssignedEntry($item_id)) {
146  $insert_tags['[SCO_T_' . $counter . ']'] = $sahs_item['title'];//." getId=".$this->object->getId()." item_id=".$item_id." user_id=".$ilUser->getId()
147  $a_scores = $collection->getScoresForUserAndCP_Node_Id($item_id, $GLOBALS['DIC']['ilUser']->getId());
148  if ($a_scores["raw"] == null) {
149  $insert_tags['[SCO_P_' . $counter . ']'] = $this->lng->txt("certificate_points_notavailable");
150  } else {
151  $insert_tags['[SCO_P_' . $counter . ']'] = number_format($a_scores["raw"], 1, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand"));
152  }
153  if ($a_scores["max"] == null) {
154  $insert_tags['[SCO_PM_' . $counter . ']'] = $this->lng->txt("certificate_points_notavailable");
155  } else {
156  $insert_tags['[SCO_PM_' . $counter . ']'] = number_format($a_scores["max"], 1, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand"));
157  }
158  if ($a_scores["scaled"] == null) {
159  $insert_tags['[SCO_PP_' . $counter . ']'] = $this->lng->txt("certificate_points_notavailable");
160  } else {
161  $insert_tags['[SCO_PP_' . $counter . ']'] = number_format(($a_scores["scaled"]*100), 1, $this->lng->txt("lang_sep_decimal"), $this->lng->txt("lang_sep_thousand")) . " %";
162  }
163  $counter++;
164  }
165  }
166  }
167 
168  return $insert_tags;
169  }
170 
178  {
179  $vars = $this->getBaseVariablesDescription();
180  $vars["SCORM_TITLE"] = $this->lng->txt("certificate_ph_scormtitle");
181  $vars["SCORM_POINTS"] = $this->lng->txt("certificate_ph_scormpoints");
182  $vars["SCORM_POINTS_MAX"] = $this->lng->txt("certificate_ph_scormmaxpoints");
183 
184  $template = new ilTemplate("tpl.certificate_edit.html", true, true, "Modules/ScormAicc");
185  $template->setCurrentBlock("items");
186  foreach ($vars as $id => $caption) {
187  $template->setVariable("ID", $id);
188  $template->setVariable("TXT", $caption);
189  $template->parseCurrentBlock();
190  }
191 
192  $template->setVariable("PH_INTRODUCTION", $this->lng->txt("certificate_ph_introduction"));
193 
194  include_once 'Services/Object/classes/class.ilObjectLP.php';
195  $olp = ilObjectLP::getInstance($this->object->getId());
196  $collection = $olp->getCollectionInstance();
197  if ($collection) {
198  $items = $collection->getPossibleItems();
199  }
200 
201  if (!$items) {
202  $template->setCurrentBlock('NO_SCO');
203  $template->setVariable('PH_NO_SCO', $this->lng->txt('certificate_ph_no_sco'));
204  $template->parseCurrentBlock();
205  } else {
206  $template->setCurrentBlock('SCOS');
207  $template->setVariable('PH_SCOS', $this->lng->txt('certificate_ph_scos'));
208  $template->parseCurrentBlock();
209  $template->setCurrentBlock('SCO_HEADER');
210  $template->setVariable('PH_TITLE_SCO', $this->lng->txt('certificate_ph_title_sco'));
211  //$template->setVariable('PH_PH',$lng->txt('certificate_ph_ph'));
212  $template->setVariable('PH_SCO_TITLE', $this->lng->txt('certificate_ph_sco_title'));
213  $template->setVariable('PH_SCO_POINTS_RAW', $this->lng->txt('certificate_ph_sco_points_raw'));
214  $template->setVariable('PH_SCO_POINTS_MAX', $this->lng->txt('certificate_ph_sco_points_max'));
215  $template->setVariable('PH_SCO_POINTS_SCALED', $this->lng->txt('certificate_ph_sco_points_scaled'));
216  $template->parseCurrentBlock();
217  }
218 
219  if ($collection) {
220  $counter=0;
221  foreach ($items as $item_id => $sahs_item) {
222  if ($collection->isAssignedEntry($item_id)) {
223  $template->setCurrentBlock("SCO");
224  $template->setVariable('SCO_TITLE', $sahs_item['title']);
225  $template->setVariable('PH_SCO_TITLE', '[SCO_T_' . $counter . ']');
226  $template->setVariable('PH_SCO_POINTS_RAW', '[SCO_P_' . $counter . ']');
227  $template->setVariable('PH_SCO_POINTS_MAX', '[SCO_PM_' . $counter . ']');
228  $template->setVariable('PH_SCO_POINTS_SCALED', '[SCO_PP_' . $counter . ']');
229  $template->parseCurrentBlock();
230  $counter++;
231  }
232  }
233  }
234 
235  return $template->get();
236  }
237 
247  public function addAdditionalFormElements(&$form, $form_fields)
248  {
249  $short_name = new ilTextInputGUI($this->lng->txt("certificate_short_name"), "short_name");
250  $short_name->setRequired(true);
251  require_once "./Services/Utilities/classes/class.ilStr.php";
252  $short_name->setValue(strlen($form_fields["short_name"]) ? $form_fields["short_name"] : ilStr::subStr($this->object->getTitle(), 0, 30));
253  $short_name->setSize(30);
254  if (strlen($form_fields["short_name"])) {
255  $short_name->setInfo(str_replace("[SHORT_TITLE]", $form_fields["short_name"], $this->lng->txt("certificate_short_name_description")));
256  } else {
257  $short_name->setInfo($this->lng->txt("certificate_short_name_description"));
258  }
259  if (count($_POST)) {
260  $short_name->checkInput();
261  }
262  $form->addItem($short_name);
263  }
264 
273  public function addFormFieldsFromPOST(&$form_fields)
274  {
275  $form_fields["certificate_enabled_scorm"] = $_POST["certificate_enabled_scorm"];
276  $form_fields["short_name"] = $_POST["short_name"];
277  }
278 
287  public function addFormFieldsFromObject(&$form_fields)
288  {
289  $scormSetting = new ilSetting("scorm");
290  $form_fields["certificate_enabled_scorm"] = $scormSetting->get("certificate_" . $this->object->getId());
291  $form_fields["short_name"] = $scormSetting->get("certificate_short_name_" . $this->object->getId());
292  }
293 
301  public function saveFormFields(&$form_fields)
302  {
303  $scormSetting = new ilSetting("scorm");
304  $scormSetting->set("certificate_" . $this->object->getId(), $form_fields["certificate_enabled_scorm"]);
305  $scormSetting->set("certificate_short_name_" . $this->object->getId(), $form_fields["short_name"]);
306  }
307 
314  public function getAdapterType()
315  {
316  return "scorm";
317  }
318 
325  public function getCertificateID()
326  {
327  return $this->object->getId();
328  }
329 
336  public function getCertificateFilename($params = array())
337  {
338  $basename = parent::getCertificateFilename($params);
339 
340  $user_data = $params["user_data"];
341  if (!is_array($user_data)) {
342  global $ilSetting;
343  $scormSetting = new ilSetting("scorm");
344  $short_title = $scormSetting->get("certificate_short_name_" . $this->object->getId());
345  return strftime("%y%m%d", time()) . "_" . $this->lng->txt("certificate_var_user_lastname") . "_" . $short_title . "_" . $basename;
346  } else {
347  return strftime("%y%m%d", time()) . "_" . $user_data["lastname"] . "_" . $params["short_title"] . "_.$basename";
348  }
349  }
350 
356  public function deleteCertificate()
357  {
358  $scormSetting = new ilSetting("scorm");
359  $scormSetting->delete("certificate_" . $this->object->getId());
360  }
361 
368  public function getUserIdForParams($a_params)
369  {
370  return $a_params["user_data"]["usr_id"];
371  }
372 }
$params
Definition: disable.php:11
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
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.
$template
addFormFieldsFromPOST(&$form_fields)
Allows to add additional form values to the array of form values evaluating a HTTP POST action...
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
addAdditionalFormElements(&$form, $form_fields)
Allows to add additional form fields to the certificate editor form This method will be called when t...
if(!array_key_exists('StateId', $_REQUEST)) $id
__construct($object)
ilSCORMCertificateAdapter contructor
static subStr($a_str, $a_start, $a_length=null)
Definition: class.ilStr.php:15
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.
$counter
if(isset($_POST['submit'])) $form
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...
Create styles array
The data for the language used.
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.
Create new PHPExcel object
obj_idprivate
global $ilSetting
Definition: privfeed.php:17
Adapter class to provide certificate data for the certificate generator.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
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 getInstance($a_obj_id)
$_POST["username"]
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...