ILIAS  eassessment Revision 61809
 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  private $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  include_once "./classes/class.ilFormat.php";
69  $insert_tags = array(
70  "[USER_FULLNAME]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_fullname")),
71  "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_firstname")),
72  "[USER_LASTNAME]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_lastname")),
73  "[USER_TITLE]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_user_title")),
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  "[RESULT_PASSED]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_result_passed")),
81  "[RESULT_POINTS]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_result_points")),
82  "[RESULT_PERCENT]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_result_percent")),
83  "[MAX_POINTS]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_max_points")),
84  "[RESULT_MARK_SHORT]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_result_mark_short")),
85  "[RESULT_MARK_LONG]" => ilUtil::prepareFormOutput($lng->txt("certificate_var_result_mark_long")),
86  "[TEST_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
87  "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date", FALSE, FALSE),
88  "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE, FALSE)
89  );
90  return $insert_tags;
91  }
92 
101  public function getCertificateVariablesForPresentation($params = array())
102  {
103  global $lng;
104 
105  $active_id = $params["active_id"];
106  $pass = $params["pass"];
107  $userfilter = array_key_exists("userfilter", $params) ? $params["userfilter"] : "";
108  $passedonly = array_key_exists("passedonly", $params) ? $params["passedonly"] : FALSE;
109  if (strlen($pass))
110  {
111  $result_array =& $this->object->getTestResult($active_id, $pass);
112  }
113  else
114  {
115  $result_array =& $this->object->getTestResult($active_id);
116  }
117  if (($passedonly) && ($result_array["test"]["passed"] == FALSE)) return "";
118  $passed = $result_array["test"]["passed"] ? $lng->txt("certificate_passed") : $lng->txt("certificate_failed");
119  if (!$result_array["test"]["total_max_points"])
120  {
121  $percentage = 0;
122  }
123  else
124  {
125  $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
126  }
127  $mark_obj = $this->object->mark_schema->getMatchingMark($percentage);
128  $user_id = $this->object->_getUserIdFromActiveId($active_id);
129  include_once './Services/User/classes/class.ilObjUser.php';
130  $user_data = ilObjUser::_lookupFields($user_id);
131  if (strlen($userfilter))
132  {
133  if (!@preg_match("/$userfilter/i", $user_data["lastname"] . ", " . $user_data["firstname"] . " " . $user_data["title"]))
134  {
135  return "";
136  }
137  }
138  include_once "./classes/class.ilFormat.php";
139  $insert_tags = array(
140  "[USER_FULLNAME]" => ilUtil::prepareFormOutput(trim($user_data["title"] . " " . $user_data["firstname"] . " " . $user_data["lastname"])),
141  "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($user_data["firstname"]),
142  "[USER_LASTNAME]" => ilUtil::prepareFormOutput($user_data["lastname"]),
143  "[USER_TITLE]" => ilUtil::prepareFormOutput($user_data["title"]),
144  "[USER_INSTITUTION]" => ilUtil::prepareFormOutput($user_data["institution"]),
145  "[USER_DEPARTMENT]" => ilUtil::prepareFormOutput($user_data["department"]),
146  "[USER_STREET]" => ilUtil::prepareFormOutput($user_data["street"]),
147  "[USER_CITY]" => ilUtil::prepareFormOutput($user_data["city"]),
148  "[USER_ZIPCODE]" => ilUtil::prepareFormOutput($user_data["zipcode"]),
149  "[USER_COUNTRY]" => ilUtil::prepareFormOutput($user_data["country"]),
150  "[RESULT_PASSED]" => ilUtil::prepareFormOutput($passed),
151  "[RESULT_POINTS]" => ilUtil::prepareFormOutput($result_array["test"]["total_reached_points"]),
152  "[RESULT_PERCENT]" => sprintf("%2.2f", $percentage) . "%",
153  "[MAX_POINTS]" => ilUtil::prepareFormOutput($result_array["test"]["total_max_points"]),
154  "[RESULT_MARK_SHORT]" => ilUtil::prepareFormOutput($mark_obj->getShortName()),
155  "[RESULT_MARK_LONG]" => ilUtil::prepareFormOutput($mark_obj->getOfficialName()),
156  "[TEST_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
157  "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date", FALSE, FALSE),
158  "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE, FALSE)
159  );
160  return $insert_tags;
161  }
162 
170  {
171  global $lng;
172 
173  $template = new ilTemplate("tpl.il_as_tst_certificate_edit.html", TRUE, TRUE, "Modules/Test");
174  $template->setVariable("PH_INTRODUCTION", $lng->txt("certificate_ph_introduction"));
175  $template->setVariable("PH_USER_FULLNAME", $lng->txt("certificate_ph_fullname"));
176  $template->setVariable("PH_USER_FIRSTNAME", $lng->txt("certificate_ph_firstname"));
177  $template->setVariable("PH_USER_LASTNAME", $lng->txt("certificate_ph_lastname"));
178  $template->setVariable("PH_RESULT_PASSED", $lng->txt("certificate_ph_passed"));
179  $template->setVariable("PH_RESULT_POINTS", $lng->txt("certificate_ph_resultpoints"));
180  $template->setVariable("PH_RESULT_PERCENT", $lng->txt("certificate_ph_resultpercent"));
181  $template->setVariable("PH_USER_TITLE", $lng->txt("certificate_ph_title"));
182  $template->setVariable("PH_USER_STREET", $lng->txt("certificate_ph_street"));
183  $template->setVariable("PH_USER_INSTITUTION", $lng->txt("certificate_ph_institution"));
184  $template->setVariable("PH_USER_DEPARTMENT", $lng->txt("certificate_ph_department"));
185  $template->setVariable("PH_USER_CITY", $lng->txt("certificate_ph_city"));
186  $template->setVariable("PH_USER_ZIPCODE", $lng->txt("certificate_ph_zipcode"));
187  $template->setVariable("PH_USER_COUNTRY", $lng->txt("certificate_ph_country"));
188  $template->setVariable("PH_MAX_POINTS", $lng->txt("certificate_ph_maxpoints"));
189  $template->setVariable("PH_RESULT_MARK_SHORT", $lng->txt("certificate_ph_markshort"));
190  $template->setVariable("PH_RESULT_MARK_LONG", $lng->txt("certificate_ph_marklong"));
191  $template->setVariable("PH_TEST_TITLE", $lng->txt("certificate_ph_testtitle"));
192  $template->setVariable("PH_DATE", $lng->txt("certificate_ph_date"));
193  $template->setVariable("PH_DATETIME", $lng->txt("certificate_ph_datetime"));
194  return $template->get();
195  }
196 
206  public function addAdditionalFormElements(&$form, $form_fields)
207  {
208  global $lng;
209  $visibility = new ilRadioMatrixInputGUI($lng->txt("certificate_visibility"), "certificate_visibility");
210  $options = array(
211  0 => $lng->txt("certificate_visibility_always"),
212  1 => $lng->txt("certificate_visibility_passed"),
213  2 => $lng->txt("certificate_visibility_never")
214  );
215  $visibility->setOptions($options);
216  $visibility->setInfo($lng->txt("certificate_visibility_introduction"));
217  $visibility->setValue($form_fields["certificate_visibility"]);
218  if (count($_POST)) $visibility->checkInput();
219  $form->addItem($visibility);
220  }
221 
230  public function addFormFieldsFromPOST(&$form_fields)
231  {
232  $form_fields["certificate_visibility"] = $_POST["certificate_visibility"];
233  }
234 
243  public function addFormFieldsFromObject(&$form_fields)
244  {
245  $form_fields["certificate_visibility"] = $this->object->getCertificateVisibility();
246  }
247 
255  public function saveFormFields(&$form_fields)
256  {
257  $this->object->saveCertificateVisibility($form_fields["certificate_visibility"]);
258  }
259 
266  public function getAdapterType()
267  {
268  return "test";
269  }
270 
277  public function getCertificateID()
278  {
279  return $this->object->getId();
280  }
281 }
282 
283 ?>