ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCertificateAdapter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
12 abstract class ilCertificateAdapter
13 {
17  protected $lng;
18 
22  public function __construct()
23  {
24  global $DIC;
25 
26  $this->lng = $DIC['lng'];
27  $this->lng->loadLanguageModule('certificate');
28  }
29 
35  abstract public function getCertificatePath();
36 
43  abstract public function getCertificateVariablesForPreview();
44 
53  abstract public function getCertificateVariablesForPresentation($params = array());
54 
61  abstract public function getCertificateVariablesDescription();
62 
69  abstract public function getAdapterType();
70 
77  abstract public function getCertificateID();
78 
88  public function addAdditionalFormElements(&$form, $form_fields)
89  {
90  }
91 
95  public function hasAdditionalFormElements()
96  {
97  return false;
98  }
99 
108  public function addFormFieldsFromPOST(&$form_fields)
109  {
110  }
111 
120  public function addFormFieldsFromObject(&$form_fields)
121  {
122  }
123 
131  public function saveFormFields(&$form_fields)
132  {
133  }
134 
140  public function deleteCertificate()
141  {
142  }
143 
150  public function getCertificateFilename($params = array())
151  {
152  $this->lng->loadLanguageModule("certificate");
153 
154  return $this->lng->txt("certificate_file_basename") . ".pdf";
155  }
156 
164  protected function getBaseVariablesDescription($a_enable_last_access = true, $a_enable_completion_date = true)
165  {
166  $vars = array(
167  "USER_LOGIN" => $this->lng->txt("certificate_ph_login"),
168  "USER_FULLNAME" => $this->lng->txt("certificate_ph_fullname"),
169  "USER_FIRSTNAME" => $this->lng->txt("certificate_ph_firstname"),
170  "USER_LASTNAME" => $this->lng->txt("certificate_ph_lastname"),
171  "USER_TITLE" => $this->lng->txt("certificate_ph_title"),
172  "USER_SALUTATION" => $this->lng->txt("certificate_ph_salutation"),
173  "USER_BIRTHDAY" => $this->lng->txt("certificate_ph_birthday"),
174  "USER_INSTITUTION" => $this->lng->txt("certificate_ph_institution"),
175  "USER_DEPARTMENT" => $this->lng->txt("certificate_ph_department"),
176  "USER_STREET" => $this->lng->txt("certificate_ph_street"),
177  "USER_CITY" => $this->lng->txt("certificate_ph_city"),
178  "USER_ZIPCODE" => $this->lng->txt("certificate_ph_zipcode"),
179  "USER_COUNTRY" => $this->lng->txt("certificate_ph_country"),
180  "USER_MATRICULATION" => $this->lng->txt("certificate_ph_matriculation")
181  );
182 
183  if ($a_enable_last_access) {
184  $vars["USER_LASTACCESS"] = $this->lng->txt("certificate_ph_lastaccess");
185  }
186 
187  $vars["DATE"] = $this->lng->txt("certificate_ph_date");
188  $vars["DATETIME"] = $this->lng->txt("certificate_ph_datetime");
189 
190  if ($a_enable_completion_date) {
191  $vars["DATE_COMPLETED"] = $this->lng->txt("certificate_ph_date_completed");
192  $vars["DATETIME_COMPLETED"] = $this->lng->txt("certificate_ph_datetime_completed");
193  }
194 
195  return $vars;
196  }
197 
205  protected function getBaseVariablesForPreview($a_enable_last_access = true, $a_enable_completion_date = true)
206  {
209 
210  $vars = array(
211  "USER_LOGIN" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_login")),
212  "USER_FULLNAME" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_fullname")),
213  "USER_FIRSTNAME" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_firstname")),
214  "USER_LASTNAME" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_lastname")),
215  "USER_TITLE" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_title")),
216  "USER_SALUTATION" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_salutation")),
217  "USER_BIRTHDAY" => ilDatePresentation::formatDate(new ilDate($this->lng->txt("certificate_var_user_birthday"), IL_CAL_DATE)),
218  "USER_INSTITUTION" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_institution")),
219  "USER_DEPARTMENT" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_department")),
220  "USER_STREET" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_street")),
221  "USER_CITY" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_city")),
222  "USER_ZIPCODE" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_zipcode")),
223  "USER_COUNTRY" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_country")),
224  "USER_MATRICULATION" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_matriculation"))
225  );
226 
227  if ($a_enable_last_access) {
228  $vars["USER_LASTACCESS"] = ilDatePresentation::formatDate(new ilDateTime(time() - (24 * 60 * 60 * 5), IL_CAL_UNIX));
229  };
230 
231  $vars["DATE"] = ilDatePresentation::formatDate(new ilDate(time(), IL_CAL_UNIX));
232  $vars["DATETIME"] = ilDatePresentation::formatDate(new ilDateTime(time(), IL_CAL_UNIX));
233 
234  if ($a_enable_completion_date) {
235  $vars["DATE_COMPLETED"] = ilDatePresentation::formatDate(new ilDate(time() - (24 * 60 * 60 * 5), IL_CAL_UNIX));
236  $vars["DATETIME_COMPLETED"] = ilDatePresentation::formatDate(new ilDateTime(time() - (24 * 60 * 60 * 5), IL_CAL_UNIX));
237  }
238 
240 
241  return $vars;
242  }
243 
244 
253  protected function getBaseVariablesForPresentation($a_user_data, $a_last_access = null, $a_completion_date = false)
254  {
257 
258  $salutation = '';
259  $gender = $a_user_data['gender'];
260  if (is_string($gender) && strlen(trim($gender)) > 0 && strtolower($gender) !== 'n') {
261  $salutation = $this->lng->txt("salutation_" . $gender);
262  }
263 
264  $birthday = "";
265  if ($a_user_data["birthday"]) {
266  $birthday = ilDatePresentation::formatDate(new ilDate($a_user_data["birthday"], IL_CAL_DATE));
267  }
268 
269  $country = $a_user_data["sel_country"];
270  if ($country) {
271  $this->lng->loadLanguageModule("meta");
272  $country = $this->lng->txt("meta_c_" . $country);
273  } else {
274  $country = $a_user_data["country"];
275  }
276 
277  $vars = array(
278  "USER_LOGIN" => ilUtil::prepareFormOutput(trim($a_user_data["login"])),
279  "USER_FULLNAME" => ilUtil::prepareFormOutput(trim($a_user_data["title"] . " " . $a_user_data["firstname"] . " " . $a_user_data["lastname"])),
280  "USER_FIRSTNAME" => ilUtil::prepareFormOutput($a_user_data["firstname"]),
281  "USER_LASTNAME" => ilUtil::prepareFormOutput($a_user_data["lastname"]),
282  "USER_TITLE" => ilUtil::prepareFormOutput($a_user_data["title"]),
283  "USER_SALUTATION" => ilUtil::prepareFormOutput($salutation),
284  "USER_BIRTHDAY" => ilUtil::prepareFormOutput($birthday),
285  "USER_INSTITUTION" => ilUtil::prepareFormOutput($a_user_data["institution"]),
286  "USER_DEPARTMENT" => ilUtil::prepareFormOutput($a_user_data["department"]),
287  "USER_STREET" => ilUtil::prepareFormOutput($a_user_data["street"]),
288  "USER_CITY" => ilUtil::prepareFormOutput($a_user_data["city"]),
289  "USER_ZIPCODE" => ilUtil::prepareFormOutput($a_user_data["zipcode"]),
290  "USER_COUNTRY" => ilUtil::prepareFormOutput($country),
291  "USER_MATRICULATION" => ilUtil::prepareFormOutput($a_user_data["matriculation"])
292  );
293 
294  if ($a_last_access) {
295  $vars["USER_LASTACCESS"] = ilDatePresentation::formatDate(new ilDateTime($a_last_access, IL_CAL_DATETIME));
296  }
297 
298  $vars["DATE"] = ilDatePresentation::formatDate(new ilDate(time(), IL_CAL_UNIX));
299  $vars["DATETIME"] = ilDatePresentation::formatDate(new ilDateTime(time(), IL_CAL_UNIX));
300 
301 
302  if ($a_completion_date) {
303  $vars["DATE_COMPLETED"] = ilDatePresentation::formatDate(new ilDate($a_completion_date, IL_CAL_DATETIME));
304 
305  $dateTime = new ilDateTime($a_completion_date, IL_CAL_DATETIME);
306  $vars["DATETIME_COMPLETED"] = ilDatePresentation::formatDate($dateTime);
307  $vars["DATETIME_COMPLETED_UNIX"] = $dateTime->get(IL_CAL_UNIX);
308  }
309 
311 
312  return $vars;
313  }
314 
322  protected function getUserCompletionDate($a_user_id, $a_object_id = null)
323  {
324  if (!$a_object_id) {
325  $a_object_id = $this->object->getId();
326  }
327  include_once "Services/Tracking/classes/class.ilLPStatus.php";
328  return ilLPStatus::_lookupStatusChanged($a_object_id, $a_user_id);
329  }
330 
337  public function getUserIdForParams($a_params)
338  {
339  return $a_params["user_id"];
340  }
341 }
addFormFieldsFromPOST(&$form_fields)
Allows to add additional form values to the array of form values evaluating a HTTP POST action...
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getUserCompletionDate($a_user_id, $a_object_id=null)
Get completion for user.
const IL_CAL_DATETIME
addFormFieldsFromObject(&$form_fields)
Allows to add additional form values to the array of form values evaluating the associated adapter cl...
global $DIC
Definition: saml.php:7
addAdditionalFormElements(&$form, $form_fields)
Allows to add additional form fields to the certificate editor form This method will be called when t...
getCertificateVariablesForPreview()
Returns an array containing all variables and values which can be exchanged in the certificate...
__construct()
ilCertificateAdapter constructor.
getCertificateID()
Returns a certificate ID This value will be used to generate unique file names for the certificates...
getCertificateVariablesDescription()
Returns a description of the available certificate parameters.
deleteCertificate()
Is called when the certificate is deleted Add some adapter specific code if more work has to be done ...
static setUseRelativeDates($a_status)
set use relative dates
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static useRelativeDates()
check if relative dates are used
Class for single dates.
if(isset($_POST['submit'])) $form
getCertificateFilename($params=array())
Set the name of the certificate file This method will be called when the certificate will be generate...
saveFormFields(&$form_fields)
Allows to save additional adapter form fields This method will be called when the certificate editor ...
getBaseVariablesDescription($a_enable_last_access=true, $a_enable_completion_date=true)
Get variable descriptions.
Date and time handling
static _lookupStatusChanged($a_obj_id, $a_user_id)
Lookup status changed.
const IL_CAL_DATE
getUserIdForParams($a_params)
Get user id for params.
Adapter class to provide certificate data for the certificate generator.
getCertificateVariablesForPresentation($params=array())
Returns an array containing all variables and values which can be exchanged in the certificate The va...
getBaseVariablesForPreview($a_enable_last_access=true, $a_enable_completion_date=true)
Get variable dummys.
getBaseVariablesForPresentation($a_user_data, $a_last_access=null, $a_completion_date=false)
Get variable values.
getAdapterType()
Returns the adapter type This value will be used to generate file names for the certificates.
getCertificatePath()
Returns the certificate path (with a trailing path separator)