ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestCertificateAdapter.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  function __construct(&$object)
43  {
44  global $lng;
45  $this->object =& $object;
46  $lng->loadLanguageModule('certificate');
47  }
48 
54  public function getCertificatePath()
55  {
56  return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/";
57  }
58 
66  {
67  global $lng;
68 
69  $vars = $this->getBaseVariablesForPreview(false);
70  $vars["RESULT_PASSED"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_passed"));
71  $vars["RESULT_POINTS"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_points"));
72  $vars["RESULT_PERCENT"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_percent"));
73  $vars["MAX_POINTS"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_max_points"));
74  $vars["RESULT_MARK_SHORT"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_mark_short"));
75  $vars["RESULT_MARK_LONG"] = ilUtil::prepareFormOutput($lng->txt("certificate_var_result_mark_long"));
76  $vars["TEST_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
77 
78  $insert_tags = array();
79  foreach($vars as $id => $caption)
80  {
81  $insert_tags["[".$id."]"] = $caption;
82  }
83  return $insert_tags;
84  }
85 
94  public function getCertificateVariablesForPresentation($params = array())
95  {
96  global $lng;
97 
98  $active_id = $params["active_id"];
99  $pass = $params["pass"];
100  $userfilter = array_key_exists("userfilter", $params) ? $params["userfilter"] : "";
101  $passedonly = array_key_exists("passedonly", $params) ? $params["passedonly"] : FALSE;
102  if (strlen($pass))
103  {
104  $result_array =& $this->object->getTestResult($active_id, $pass);
105  }
106  else
107  {
108  $result_array =& $this->object->getTestResult($active_id);
109  }
110  if (($passedonly) && ($result_array["test"]["passed"] == FALSE)) return "";
111  $passed = $result_array["test"]["passed"] ? $lng->txt("certificate_passed") : $lng->txt("certificate_failed");
112  if (!$result_array["test"]["total_max_points"])
113  {
114  $percentage = 0;
115  }
116  else
117  {
118  $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
119  }
120  $mark_obj = $this->object->mark_schema->getMatchingMark($percentage);
121  $user_id = $this->object->_getUserIdFromActiveId($active_id);
122  include_once './Services/User/classes/class.ilObjUser.php';
123  $user_data = ilObjUser::_lookupFields($user_id);
124  if (strlen($userfilter))
125  {
126  if (!@preg_match("/$userfilter/i", $user_data["lastname"] . ", " . $user_data["firstname"] . " " . $user_data["title"]))
127  {
128  return "";
129  }
130  }
131 
132  $completion_date = $this->getUserCompletionDate($user_data["usr_id"]);
133 
134  $vars = $this->getBaseVariablesForPresentation($user_data, null, $completion_date);
135  $vars["RESULT_PASSED"] = ilUtil::prepareFormOutput($passed);
136  $vars["RESULT_POINTS"] = ilUtil::prepareFormOutput($result_array["test"]["total_reached_points"]);
137  $vars["RESULT_PERCENT"] = sprintf("%2.2f", $percentage) . "%";
138  $vars["MAX_POINTS"] = ilUtil::prepareFormOutput($result_array["test"]["total_max_points"]);
139  $vars["RESULT_MARK_SHORT"] = ilUtil::prepareFormOutput($mark_obj->getShortName());
140  $vars["RESULT_MARK_LONG"] = ilUtil::prepareFormOutput($mark_obj->getOfficialName());
141  $vars["TEST_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
142 
143  foreach($vars as $id => $caption)
144  {
145  $insert_tags["[".$id."]"] = $caption;
146  }
147  return $insert_tags;
148  }
149 
157  {
158  global $lng;
159 
160  $vars = $this->getBaseVariablesDescription(false);
161  $vars["RESULT_PASSED"] = $lng->txt("certificate_ph_passed");
162  $vars["RESULT_POINTS"] = $lng->txt("certificate_ph_resultpoints");
163  $vars["RESULT_PERCENT"] = $lng->txt("certificate_ph_resultpercent");
164  $vars["MAX_POINTS"] = $lng->txt("certificate_ph_maxpoints");
165  $vars["RESULT_MARK_SHORT"] = $lng->txt("certificate_ph_markshort");
166  $vars["RESULT_MARK_LONG"] = $lng->txt("certificate_ph_marklong");
167  $vars["TEST_TITLE"] = $lng->txt("certificate_ph_testtitle");
168 
169  $template = new ilTemplate("tpl.il_as_tst_certificate_edit.html", TRUE, TRUE, "Modules/Test");
170  $template->setCurrentBlock("items");
171  foreach($vars as $id => $caption)
172  {
173  $template->setVariable("ID", $id);
174  $template->setVariable("TXT", $caption);
175  $template->parseCurrentBlock();
176  }
177 
178  $template->setVariable("PH_INTRODUCTION", $lng->txt("certificate_ph_introduction"));
179 
180  return $template->get();
181  }
182 
192  public function addAdditionalFormElements(&$form, $form_fields)
193  {
194  global $lng;
195  $visibility = new ilRadioMatrixInputGUI($lng->txt("certificate_visibility"), "certificate_visibility");
196  $options = array(
197  0 => $lng->txt("certificate_visibility_always"),
198  1 => $lng->txt("certificate_visibility_passed"),
199  2 => $lng->txt("certificate_visibility_never")
200  );
201  $visibility->setOptions($options);
202  $visibility->setInfo($lng->txt("certificate_visibility_introduction"));
203  $visibility->setValue($form_fields["certificate_visibility"]);
204  if (count($_POST)) $visibility->checkInput();
205  $form->addItem($visibility);
206  }
207 
216  public function addFormFieldsFromPOST(&$form_fields)
217  {
218  $form_fields["certificate_visibility"] = $_POST["certificate_visibility"];
219  }
220 
229  public function addFormFieldsFromObject(&$form_fields)
230  {
231  $form_fields["certificate_visibility"] = $this->object->getCertificateVisibility();
232  }
233 
241  public function saveFormFields(&$form_fields)
242  {
243  $this->object->saveCertificateVisibility($form_fields["certificate_visibility"]);
244  }
245 
252  public function getAdapterType()
253  {
254  return "test";
255  }
256 
263  public function getCertificateID()
264  {
265  return $this->object->getId();
266  }
267 }
268 
269 ?>