ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExerciseCertificateAdapter.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
24include_once "./Services/Certificate/classes/class.ilCertificateAdapter.php";
25
34{
35 protected $object;
36
42 public function __construct($object)
43 {
44 $this->object = $object;
45 parent::__construct();
46 }
47
53 public function getCertificatePath()
54 {
55 return CLIENT_WEB_DIR . "/exercise/certificates/" . $this->object->getId() . "/";
56 }
57
65 {
66 $vars = $this->getBaseVariablesForPreview(false);
67 $vars["RESULT_PASSED"] = ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_passed"));
68 $vars["RESULT_MARK"] = ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_mark_short"));
69 $vars["EXERCISE_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
70
71 $insert_tags = array();
72 foreach ($vars as $id => $caption) {
73 $insert_tags["[" . $id . "]"] = $caption;
74 }
75 return $insert_tags;
76 }
77
87 {
88 $user_id = $params["user_id"];
89
90 include_once 'Services/Tracking/classes/class.ilLPMarks.php';
91 $mark = ilLPMarks::_lookupMark($user_id, $this->object->getId());
92 include_once 'Modules/Exercise/classes/class.ilExerciseMembers.php';
93 $status = ilExerciseMembers::_lookupStatus($this->object->getId(), $user_id);
94
95 $user_data = ilObjUser::_lookupFields($user_id);
96 $completion_date = $this->getUserCompletionDate($user_id);
97
98 $vars = $this->getBaseVariablesForPresentation($user_data, null, $completion_date);
99 $vars["RESULT_PASSED"] = ilUtil::prepareFormOutput($this->lng->txt("exc_" . $status));
100 $vars["RESULT_MARK"] = ilUtil::prepareFormOutput($mark);
101 $vars["EXERCISE_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
102
103 foreach ($vars as $id => $caption) {
104 $insert_tags["[" . $id . "]"] = $caption;
105 }
106 return $insert_tags;
107 }
108
116 {
117 $vars = $this->getBaseVariablesDescription(false);
118 $vars["RESULT_PASSED"] = $this->lng->txt("certificate_ph_passed_exercise");
119 $vars["RESULT_MARK"] = $this->lng->txt("certificate_ph_mark");
120 $vars["EXERCISE_TITLE"] = $this->lng->txt("certificate_ph_exercisetitle");
121
122 $template = new ilTemplate("tpl.certificate_edit.html", true, true, "Modules/Exercise");
123 $template->setCurrentBlock("items");
124 foreach ($vars as $id => $caption) {
125 $template->setVariable("ID", $id);
126 $template->setVariable("TXT", $caption);
127 $template->parseCurrentBlock();
128 }
129
130 $template->setVariable("PH_INTRODUCTION", $this->lng->txt("certificate_ph_introduction"));
131
132 return $template->get();
133 }
134
135 public function addAdditionalFormElements(&$form, $form_fields)
136 {
137 $visibility = new ilRadioGroupInputGUI($this->lng->txt("certificate_visibility"), "certificate_visibility");
138 $visibility->addOption(new ilRadioOption($this->lng->txt("certificate_visibility_always"), 0));
139 $visibility->addOption(new ilRadioOption($this->lng->txt("certificate_visibility_passed_exercise"), 1));
140 $visibility->addOption(new ilRadioOption($this->lng->txt("certificate_visibility_never"), 2));
141 $visibility->setValue($form_fields["certificate_visibility"]);
142 if (count($_POST)) {
143 $visibility->checkInput();
144 }
145 $form->addItem($visibility);
146 }
147
148 public function addFormFieldsFromPOST(&$form_fields)
149 {
150 $form_fields["certificate_visibility"] = $_POST["certificate_visibility"];
151 }
152
153 public function addFormFieldsFromObject(&$form_fields)
154 {
155 $form_fields["certificate_visibility"] = $this->object->getCertificateVisibility();
156 }
157
158 public function saveFormFields(&$form_fields)
159 {
160 $this->object->saveCertificateVisibility($form_fields["certificate_visibility"]);
161 }
162
169 public function getAdapterType()
170 {
171 return "exc";
172 }
173
180 public function getCertificateID()
181 {
182 return $this->object->getId();
183 }
184
193 public function hasUserCertificate(int $userId)
194 {
195 // show certificate?
196 if (ilCertificate::isActive() && ilCertificate::isObjectActive($this->object->getId())) {
197 $certificate_visible = $this->object->getCertificateVisibility();
198 // if not never
199 if ($certificate_visible != 2) {
200 // if passed only
201 $status = ilExerciseMembers::_lookupStatus($this->object->getId(), $userId);
202 if ($certificate_visible == 1 && $status == "passed") {
203 return true;
204 }
205
206 // always (excluding notgraded)
207 elseif ($certificate_visible == 0 && $status != "notgraded") {
208 return true;
209 }
210 }
211 }
212
213 return false;
214 }
215}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Adapter class to provide certificate data for the certificate generator.
getBaseVariablesForPresentation($a_user_data, $a_last_access=null, $a_completion_date=false)
Get variable values.
getBaseVariablesForPreview($a_enable_last_access=true, $a_enable_completion_date=true)
Get variable dummys.
getUserCompletionDate($a_user_id, $a_object_id=null)
Get completion for user.
getBaseVariablesDescription($a_enable_last_access=true, $a_enable_completion_date=true)
Get variable descriptions.
static isObjectActive($a_obj_id)
addFormFieldsFromObject(&$form_fields)
Allows to add additional form values to the array of form values evaluating the associated adapter cl...
addAdditionalFormElements(&$form, $form_fields)
Allows to add additional form fields to the certificate editor form This method will be called when t...
getCertificatePath()
Returns the certificate path (with a trailing path separator)
getCertificateVariablesForPreview()
Returns an array containing all variables and values which can be exchanged in the certificate.
saveFormFields(&$form_fields)
Allows to save additional adapter form fields This method will be called when the certificate editor ...
getCertificateVariablesDescription()
Returns a description of the available certificate parameters.
getCertificateID()
Returns a certificate ID This value will be used to generate unique file names for the certificates.
__construct($object)
ilTestCertificateAdapter contructor
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...
getAdapterType()
Returns the adapter type This value will be used to generate file names for the certificates.
hasUserCertificate(int $userId)
This code was orignaly located in ilObjExercise and has been moved here for ilCertificateMigrationJob
static _lookupStatus($a_obj_id, $a_user_id)
Lookup current status (notgraded|passed|failed)
static _lookupMark($a_usr_id, $a_obj_id)
static _lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
This class represents a property in a property form.
This class represents an option in a radio group.
special template class to simplify handling of ITX/PEAR
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$template
if(!array_key_exists('StateId', $_REQUEST)) $id
if(isset($_POST['submit'])) $form