ILIAS  eassessment Revision 61809
 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  private $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  include_once "./classes/class.ilFormat.php";
67  $insert_tags = array(
68  "[USER_FULLNAME]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_fullname")),
69  "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_firstname")),
70  "[USER_LASTNAME]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_lastname")),
71  "[USER_TITLE]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_title")),
72  "[USER_SALUTATION]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_salutation")),
73  "[USER_BIRTHDAY]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_birthday")),
74  "[USER_INSTITUTION]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_institution")),
75  "[USER_DEPARTMENT]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_department")),
76  "[USER_STREET]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_street")),
77  "[USER_CITY]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_city")),
78  "[USER_ZIPCODE]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_zipcode")),
79  "[USER_COUNTRY]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_country")),
80  "[USER_LASTACCESS]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()-(24*60*60*5)), "datetime", TRUE, FALSE),
81  "[SCORM_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
82  "[SCORM_POINTS]" => number_format(80.7, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand")) . " %",
83  "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date", FALSE, FALSE),
84  "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE, FALSE)
85  );
86  return $insert_tags;
87  }
88 
97  public function getCertificateVariablesForPresentation($params = array())
98  {
99  global $lng;
100 
101  $lng->loadLanguageModule('certificate');
102  $user_data = $params["user_data"];
103  $points = $this->object->getPointsInPercent();
104  $txtPoints = "";
105  if (is_null($points))
106  {
107  $txtPoints = $lng->txt("certificate_points_notavailable");
108  }
109  else
110  {
111  $txtPoints = number_format($points, 1, $lng->txt("lang_sep_decimal"), $lng->txt("lang_sep_thousand")) . " %";
112  }
113  $salutation = "";
114  if (strlen($user_data["gender"]))
115  {
116  $salutation = $lng->txt("salutation_" . $user_data["gender"]);
117  }
118  $y = ""; $m = ""; $d = "";
119  if (preg_match("/(\\d{4})-(\\d{2})-(\\d{2})/", $user_data["birthday"], $matches))
120  {
121  $y = $matches[1];
122  $m = $matches[2];
123  $d = $matches[3];
124  }
125  include_once "./classes/class.ilFormat.php";
126  $insert_tags = array(
127  "[USER_FULLNAME]" => ilUtil::prepareFormOutput(trim($user_data["title"] . " " . $user_data["firstname"] . " " . $user_data["lastname"])),
128  "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($user_data["firstname"]),
129  "[USER_LASTNAME]" => ilUtil::prepareFormOutput($user_data["lastname"]),
130  "[USER_TITLE]" => ilUtil::prepareFormOutput($user_data["title"]),
131  "[USER_SALUTATION]" => ilUtil::prepareFormOutput($salutation),
132  "[USER_BIRTHDAY]" => ilUtil::prepareFormOutput((strlen($y.$m.$d)) ? str_replace("m", $m, str_replace("d", $d, str_replace("Y", $y, $lng->txt("lang_dateformat")))) : $lng->txt("not_available")),
133  "[USER_INSTITUTION]" => ilUtil::prepareFormOutput($user_data["institution"]),
134  "[USER_DEPARTMENT]" => ilUtil::prepareFormOutput($user_data["department"]),
135  "[USER_STREET]" => ilUtil::prepareFormOutput($user_data["street"]),
136  "[USER_CITY]" => ilUtil::prepareFormOutput($user_data["city"]),
137  "[USER_ZIPCODE]" => ilUtil::prepareFormOutput($user_data["zipcode"]),
138  "[USER_COUNTRY]" => ilUtil::prepareFormOutput($user_data["country"]),
139  "[USER_LASTACCESS]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime($params["last_access"]), "datetime", FALSE, FALSE),
140  "[SCORM_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
141  "[SCORM_POINTS]" => $txtPoints,
142  "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date", FALSE, FALSE),
143  "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE, FALSE)
144  );
145  return $insert_tags;
146  }
147 
155  {
156  global $lng;
157 
158  $template = new ilTemplate("tpl.certificate_edit.html", TRUE, TRUE, "Modules/ScormAicc");
159  $template->setVariable("PH_INTRODUCTION", $lng->txt("certificate_ph_introduction"));
160  $template->setVariable("PH_USER_FULLNAME", $lng->txt("certificate_ph_fullname"));
161  $template->setVariable("PH_USER_FIRSTNAME", $lng->txt("certificate_ph_firstname"));
162  $template->setVariable("PH_USER_LASTNAME", $lng->txt("certificate_ph_lastname"));
163  $template->setVariable("PH_RESULT_PASSED", $lng->txt("certificate_ph_passed"));
164  $template->setVariable("PH_RESULT_POINTS", $lng->txt("certificate_ph_resultpoints"));
165  $template->setVariable("PH_RESULT_PERCENT", $lng->txt("certificate_ph_resultpercent"));
166  $template->setVariable("PH_USER_TITLE", $lng->txt("certificate_ph_title"));
167  $template->setVariable("PH_USER_BIRTHDAY", $lng->txt("certificate_ph_birthday"));
168  $template->setVariable("PH_USER_SALUTATION", $lng->txt("certificate_ph_salutation"));
169  $template->setVariable("PH_USER_STREET", $lng->txt("certificate_ph_street"));
170  $template->setVariable("PH_USER_INSTITUTION", $lng->txt("certificate_ph_institution"));
171  $template->setVariable("PH_USER_DEPARTMENT", $lng->txt("certificate_ph_department"));
172  $template->setVariable("PH_USER_CITY", $lng->txt("certificate_ph_city"));
173  $template->setVariable("PH_USER_ZIPCODE", $lng->txt("certificate_ph_zipcode"));
174  $template->setVariable("PH_USER_COUNTRY", $lng->txt("certificate_ph_country"));
175  $template->setVariable("PH_USER_LASTACCESS", $lng->txt("certificate_ph_lastaccess"));
176  $template->setVariable("PH_SCORM_TITLE", $lng->txt("certificate_ph_scormtitle"));
177  $template->setVariable("PH_SCORM_POINTS", $lng->txt("certificate_ph_scormpoints"));
178  $template->setVariable("PH_DATE", $lng->txt("certificate_ph_date"));
179  $template->setVariable("PH_DATETIME", $lng->txt("certificate_ph_datetime"));
180  return $template->get();
181  }
182 
192  public function addAdditionalFormElements(&$form, $form_fields)
193  {
194  global $lng;
195  $short_name = new ilTextInputGUI($lng->txt("certificate_short_name"), "short_name");
196  $short_name->setRequired(TRUE);
197  require_once "./Services/Utilities/classes/class.ilStr.php";
198  $short_name->setValue(strlen($form_fields["short_name"]) ? $form_fields["short_name"] : ilStr::subStr($this->object->getTitle(), 0, 30));
199  $short_name->setSize(30);
200  if (strlen($form_fields["short_name"])) {
201  $short_name->setInfo(str_replace("[SHORT_TITLE]", $form_fields["short_name"], $lng->txt("certificate_short_name_description")));
202  } else {
203  $short_name->setInfo($lng->txt("certificate_short_name_description"));
204  }
205  if (count($_POST)) $short_name->checkInput();
206  $form->addItem($short_name);
207 
208  $visibility = new ilCheckboxInputGUI($lng->txt("certificate_enabled_scorm"), "certificate_enabled_scorm");
209  $visibility->setInfo($lng->txt("certificate_enabled_scorm_introduction"));
210  $visibility->setValue(1);
211  if ($form_fields["certificate_enabled_scorm"])
212  {
213  $visibility->setChecked(TRUE);
214  }
215  if (count($_POST)) $visibility->checkInput();
216  $form->addItem($visibility);
217  }
218 
227  public function addFormFieldsFromPOST(&$form_fields)
228  {
229  $form_fields["certificate_enabled_scorm"] = $_POST["certificate_enabled_scorm"];
230  $form_fields["short_name"] = $_POST["short_name"];
231  }
232 
241  public function addFormFieldsFromObject(&$form_fields)
242  {
243  global $ilSetting;
244  $scormSetting = new ilSetting("scorm");
245  $form_fields["certificate_enabled_scorm"] = $scormSetting->get("certificate_" . $this->object->getId());
246  $form_fields["short_name"] = $scormSetting->get("certificate_short_name_" . $this->object->getId());
247  }
248 
256  public function saveFormFields(&$form_fields)
257  {
258  global $ilSetting;
259  $scormSetting = new ilSetting("scorm");
260  $scormSetting->set("certificate_" . $this->object->getId(), $form_fields["certificate_enabled_scorm"]);
261  $scormSetting->set("certificate_short_name_" . $this->object->getId(), $form_fields["short_name"]);
262  }
263 
270  public function getAdapterType()
271  {
272  return "scorm";
273  }
274 
281  public function getCertificateID()
282  {
283  return $this->object->getId();
284  }
285 
292  public function getCertificateFilename($params = array())
293  {
294  global $lng;
295 
296  $user_data = $params["user_data"];
297  if (!is_array($user_data))
298  {
299  global $ilSetting;
300  $scormSetting = new ilSetting("scorm");
301  $short_title = $scormSetting->get("certificate_short_name_" . $this->object->getId());
302  return strftime("%y%m%d", time()) . "_" . $lng->txt("certificate_var_user_lastname") . "_" . $short_title . "_Zertifikat.pdf";
303  }
304  else
305  {
306  return strftime("%y%m%d", time()) . "_" . $user_data["lastname"] . "_" . $params["short_title"] . "_Zertifikat.pdf";
307  }
308  }
309 
315  public function deleteCertificate()
316  {
317  global $ilSetting;
318  $scormSetting = new ilSetting("scorm");
319  $scormSetting->delete("certificate_" . $this->object->getId());
320  }
321 }
322 
323 ?>