ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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  global $lng;
25  $this->object =& $object;
26  $lng->loadLanguageModule('certificate');
27  }
28 
34  public function getCertificatePath()
35  {
36  return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/";
37  }
38 
46  {
47  global $lng;
48 
49  $vars = $this->getBaseVariablesForPreview(false);
50  $vars["RESULT_PASSED"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_passed"));
51  $vars["RESULT_POINTS"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_points"));
52  $vars["RESULT_PERCENT"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_percent"));
53  $vars["MAX_POINTS"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_max_points"));
54  $vars["RESULT_MARK_SHORT"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_mark_short"));
55  $vars["RESULT_MARK_LONG"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_mark_long"));
56  $vars["TEST_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
57 
58  $insert_tags = array();
59  foreach($vars as $id => $caption)
60  {
61  $insert_tags["[".$id."]"] = $caption;
62  }
63 
64  return $insert_tags;
65  }
66 
75  public function getCertificateVariablesForPresentation($params = array())
76  {
77  global $lng;
78 
79  $active_id = $params["active_id"];
80  $pass = $params["pass"];
81  $userfilter = array_key_exists("userfilter", $params) ? $params["userfilter"] : "";
82  $passedonly = array_key_exists("passedonly", $params) ? $params["passedonly"] : FALSE;
83  if (strlen($pass))
84  {
85  $result_array =& $this->object->getTestResult($active_id, $pass);
86  }
87  else
88  {
89  $result_array =& $this->object->getTestResult($active_id);
90  }
91  if (($passedonly) && ($result_array["test"]["passed"] == FALSE)) return "";
92  $passed = $result_array["test"]["passed"] ? $lng->txt("certificate_passed") : $lng->txt("certificate_failed");
93  if (!$result_array["test"]["total_max_points"])
94  {
95  $percentage = 0;
96  }
97  else
98  {
99  $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
100  }
101  $mark_obj = $this->object->mark_schema->getMatchingMark($percentage);
102  $user_id = $this->object->_getUserIdFromActiveId($active_id);
103  include_once './Services/User/classes/class.ilObjUser.php';
104  $user_data = ilObjUser::_lookupFields($user_id);
105 
106  if (strlen($userfilter))
107  {
108  if (!@preg_match("/$userfilter/i", $user_data["lastname"] . ", " . $user_data["firstname"] . " " . $user_data["title"]))
109  {
110  return "";
111  }
112  }
113 
114  if($user_data["usr_id"] > 0)
115  {
116  $completion_date = $this->getUserCompletionDate($user_data["usr_id"]);
117  }
118  else
119  {
120  $completion_date = false;
121  }
122 
123  $vars = $this->getBaseVariablesForPresentation($user_data, null, $completion_date);
124  $vars["RESULT_PASSED"] = ilUtil::prepareFormOutput($passed);
125  $vars["RESULT_POINTS"] = ilUtil::prepareFormOutput($result_array["test"]["total_reached_points"]);
126  $vars["RESULT_PERCENT"] = sprintf("%2.2f", $percentage) . "%";
127  $vars["MAX_POINTS"] = ilUtil::prepareFormOutput($result_array["test"]["total_max_points"]);
128  $vars["RESULT_MARK_SHORT"] = ilUtil::prepareFormOutput($mark_obj->getShortName());
129  $vars["RESULT_MARK_LONG"] = ilUtil::prepareFormOutput($mark_obj->getOfficialName());
130  $vars["TEST_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
131 
132  foreach($vars as $id => $caption)
133  {
134  $insert_tags["[".$id."]"] = $caption;
135  }
136 
137  return $insert_tags;
138  }
139 
147  {
148  global $lng;
149 
150  $vars = $this->getBaseVariablesDescription(false);
151  $vars["RESULT_PASSED"] = $lng->txt("certificate_ph_passed");
152  $vars["RESULT_POINTS"] = $lng->txt("certificate_ph_resultpoints");
153  $vars["RESULT_PERCENT"] = $lng->txt("certificate_ph_resultpercent");
154  $vars["MAX_POINTS"] = $lng->txt("certificate_ph_maxpoints");
155  $vars["RESULT_MARK_SHORT"] = $lng->txt("certificate_ph_markshort");
156  $vars["RESULT_MARK_LONG"] = $lng->txt("certificate_ph_marklong");
157  $vars["TEST_TITLE"] = $lng->txt("certificate_ph_testtitle");
158 
159  $template = new ilTemplate("tpl.il_as_tst_certificate_edit.html", TRUE, TRUE, "Modules/Test");
160  $template->setCurrentBlock("items");
161  foreach($vars as $id => $caption)
162  {
163  $template->setVariable("ID", $id);
164  $template->setVariable("TXT", $caption);
165  $template->parseCurrentBlock();
166  }
167 
168 
169  $template->setVariable("PH_INTRODUCTION", $lng->txt("certificate_ph_introduction"));
170 
171  return $template->get();
172  }
173 
183  public function addAdditionalFormElements(&$form, $form_fields)
184  {
185  global $lng;
186 
187  $visibility = new ilRadioGroupInputGUI($lng->txt("certificate_visibility"), "certificate_visibility");
188  $visibility->addOption(new ilRadioOption($lng->txt("certificate_visibility_always"), 0));
189  $visibility->addOption(new ilRadioOption($lng->txt("certificate_visibility_passed"), 1));
190  $visibility->addOption(new ilRadioOption($lng->txt("certificate_visibility_never"), 2));
191  $visibility->setInfo($lng->txt("certificate_visibility_introduction"));
192  $visibility->setValue($form_fields["certificate_visibility"]);
193  if (count($_POST)) $visibility->checkInput();
194  $form->addItem($visibility);
195  }
196 
205  public function addFormFieldsFromPOST(&$form_fields)
206  {
207  $form_fields["certificate_visibility"] = $_POST["certificate_visibility"];
208  }
209 
218  public function addFormFieldsFromObject(&$form_fields)
219  {
220  $form_fields["certificate_visibility"] = $this->object->getCertificateVisibility();
221  }
222 
230  public function saveFormFields(&$form_fields)
231  {
232  $this->object->saveCertificateVisibility($form_fields["certificate_visibility"]);
233  }
234 
241  public function getAdapterType()
242  {
243  return "test";
244  }
245 
252  public function getCertificateID()
253  {
254  return $this->object->getId();
255  }
256 
263  function getUserIdForParams($a_params)
264  {
265  return $this->object->_getUserIdFromActiveId($a_params["active_id"]);
266  }
267 
268 }
269 
270 ?>
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.
$_POST['username']
Definition: cron.php:12
_lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
saveFormFields(&$form_fields)
Allows to save additional adapter form fields This method will be called when the certificate editor ...
addFormFieldsFromPOST(&$form_fields)
Allows to add additional form values to the array of form values evaluating a HTTP POST action...
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.
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...
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...
global $lng
Definition: privfeed.php:40
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.
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)
getUserIdForParams($a_params)
Get user id for params.
getCertificateVariablesDescription()
Returns a description of the available certificate parameters.