ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestCertificateAdapter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Services/Certificate/classes/class.ilCertificateAdapter.php";
5 
14 {
15  protected $object;
16 
22  function __construct(&$object)
23  {
24  $this->object =& $object;
25  parent::__construct();
26  }
27 
33  public function getCertificatePath()
34  {
35  return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/";
36  }
37 
45  {
46  global $lng;
47 
48  $vars = $this->getBaseVariablesForPreview(false);
49  $vars["RESULT_PASSED"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_passed"));
50  $vars["RESULT_POINTS"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_points"));
51  $vars["RESULT_PERCENT"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_percent"));
52  $vars["MAX_POINTS"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_max_points"));
53  $vars["RESULT_MARK_SHORT"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_mark_short"));
54  $vars["RESULT_MARK_LONG"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_mark_long"));
55  $vars["TEST_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
56 
57  $insert_tags = array();
58  foreach($vars as $id => $caption)
59  {
60  $insert_tags["[".$id."]"] = $caption;
61  }
62 
63  return $insert_tags;
64  }
65 
75  {
76  global $lng;
77 
78  $active_id = $params["active_id"];
79  $pass = $params["pass"];
80  $userfilter = array_key_exists("userfilter", $params) ? $params["userfilter"] : "";
81  $passedonly = array_key_exists("passedonly", $params) ? $params["passedonly"] : FALSE;
82  if (strlen($pass))
83  {
84  $result_array =& $this->object->getTestResult($active_id, $pass);
85  }
86  else
87  {
88  $result_array =& $this->object->getTestResult($active_id);
89  }
90  if (($passedonly) && ($result_array["test"]["passed"] == FALSE)) return "";
91  $passed = $result_array["test"]["passed"] ? $lng->txt("certificate_passed") : $lng->txt("certificate_failed");
92  if (!$result_array["test"]["total_max_points"])
93  {
94  $percentage = 0;
95  }
96  else
97  {
98  $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
99  }
100  $mark_obj = $this->object->mark_schema->getMatchingMark($percentage);
101  $user_id = $this->object->_getUserIdFromActiveId($active_id);
102  include_once './Services/User/classes/class.ilObjUser.php';
103  $user_data = ilObjUser::_lookupFields($user_id);
104 
105  if (strlen($userfilter))
106  {
107  if (!@preg_match("/$userfilter/i", $user_data["lastname"] . ", " . $user_data["firstname"] . " " . $user_data["title"]))
108  {
109  return "";
110  }
111  }
112 
113  require_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
114  if(ilObjUserTracking::_enabledLearningProgress() && $user_data["usr_id"] > 0)
115  {
116  $completion_date = $this->getUserCompletionDate($user_data["usr_id"]);
117  }
118  else
119  {
120  $dt = new ilDateTime($result_array['test']['result_tstamp'], IL_CAL_UNIX);
121  $completion_date = $dt->get(IL_CAL_DATETIME);
122  }
123 
124  $vars = $this->getBaseVariablesForPresentation($user_data, null, $completion_date);
125  $vars["RESULT_PASSED"] = ilUtil::prepareFormOutput($passed);
126  $vars["RESULT_POINTS"] = ilUtil::prepareFormOutput($result_array["test"]["total_reached_points"]);
127  $vars["RESULT_PERCENT"] = sprintf("%2.2f", $percentage) . "%";
128  $vars["MAX_POINTS"] = ilUtil::prepareFormOutput($result_array["test"]["total_max_points"]);
129  $vars["RESULT_MARK_SHORT"] = ilUtil::prepareFormOutput($mark_obj->getShortName());
130  $vars["RESULT_MARK_LONG"] = ilUtil::prepareFormOutput($mark_obj->getOfficialName());
131  $vars["TEST_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
132 
133  foreach($vars as $id => $caption)
134  {
135  $insert_tags["[".$id."]"] = $caption;
136  }
137 
138  return $insert_tags;
139  }
140 
148  {
149  global $lng;
150 
151  $vars = $this->getBaseVariablesDescription(false);
152  $vars["RESULT_PASSED"] = $lng->txt("certificate_ph_passed");
153  $vars["RESULT_POINTS"] = $lng->txt("certificate_ph_resultpoints");
154  $vars["RESULT_PERCENT"] = $lng->txt("certificate_ph_resultpercent");
155  $vars["MAX_POINTS"] = $lng->txt("certificate_ph_maxpoints");
156  $vars["RESULT_MARK_SHORT"] = $lng->txt("certificate_ph_markshort");
157  $vars["RESULT_MARK_LONG"] = $lng->txt("certificate_ph_marklong");
158  $vars["TEST_TITLE"] = $lng->txt("certificate_ph_testtitle");
159 
160  $template = new ilTemplate("tpl.il_as_tst_certificate_edit.html", TRUE, TRUE, "Modules/Test");
161  $template->setCurrentBlock("items");
162  foreach($vars as $id => $caption)
163  {
164  $template->setVariable("ID", $id);
165  $template->setVariable("TXT", $caption);
166  $template->parseCurrentBlock();
167  }
168 
169 
170  $template->setVariable("PH_INTRODUCTION", $lng->txt("certificate_ph_introduction"));
171 
172  return $template->get();
173  }
174 
184  public function addAdditionalFormElements(&$form, $form_fields)
185  {
186  global $lng;
187 
188  $visibility = new ilRadioGroupInputGUI($lng->txt("certificate_visibility"), "certificate_visibility");
189  $visibility->addOption(new ilRadioOption($lng->txt("certificate_visibility_always"), 0));
190  $visibility->addOption(new ilRadioOption($lng->txt("certificate_visibility_passed"), 1));
191  $visibility->addOption(new ilRadioOption($lng->txt("certificate_visibility_never"), 2));
192  $visibility->setInfo($lng->txt("certificate_visibility_introduction"));
193  $visibility->setValue($form_fields["certificate_visibility"]);
194  if (count($_POST)) $visibility->checkInput();
195  $form->addItem($visibility);
196  }
197 
206  public function addFormFieldsFromPOST(&$form_fields)
207  {
208  $form_fields["certificate_visibility"] = $_POST["certificate_visibility"];
209  }
210 
219  public function addFormFieldsFromObject(&$form_fields)
220  {
221  $form_fields["certificate_visibility"] = $this->object->getCertificateVisibility();
222  }
223 
231  public function saveFormFields(&$form_fields)
232  {
233  $this->object->saveCertificateVisibility($form_fields["certificate_visibility"]);
234  }
235 
242  public function getAdapterType()
243  {
244  return "test";
245  }
246 
253  public function getCertificateID()
254  {
255  return $this->object->getId();
256  }
257 
264  function getUserIdForParams($a_params)
265  {
266  return $this->object->_getUserIdFromActiveId($a_params["active_id"]);
267  }
268 
269 }
270 
271 ?>
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
This class represents an option in a radio group.
__construct(&$object)
ilTestCertificateAdapter contructor
getUserCompletionDate($a_user_id, $a_object_id=null)
Get completion for user.
const IL_CAL_DATETIME
saveFormFields(&$form_fields)
Allows to save additional adapter form fields This method will be called when the certificate editor ...
const IL_CAL_UNIX
addFormFieldsFromPOST(&$form_fields)
Allows to add additional form values to the array of form values evaluating a HTTP POST action...
static _enabledLearningProgress()
check wether learing progress is enabled or not
getCertificateVariablesForPresentation($params=array())
Returns an array containing all variables and values which can be exchanged in the certificate The va...
This class represents a property in a property form.
addOption($a_option)
Add Option.
special template class to simplify handling of ITX/PEAR
getBaseVariablesDescription($a_enable_last_access=true, $a_enable_completion_date=true)
Get variable descriptions.
Date and time handling
getCertificateID()
Returns a certificate ID This value will be used to generate unique file names for the certificates...
addAdditionalFormElements(&$form, $form_fields)
Allows to add additional form fields to the certificate editor form This method will be called when t...
Create styles array
The data for the language used.
addFormFieldsFromObject(&$form_fields)
Allows to add additional form values to the array of form values evaluating the associated adapter cl...
getCertificateVariablesForPreview()
Returns an array containing all variables and values which can be exchanged in the certificate...
Create new PHPExcel object
obj_idprivate
Adapter class to provide certificate data for the certificate generator.
getAdapterType()
Returns the adapter type This value will be used to generate file names for the certificates.
static _lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
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.
getCertificatePath()
Returns the certificate path (with a trailing path separator)
$_POST["username"]
$params
Definition: example_049.php:96
getUserIdForParams($a_params)
Get user id for params.
getCertificateVariablesDescription()
Returns a description of the available certificate parameters.