ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCourseCertificateAdapter.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
35{
36 protected $object;
37 protected static $has_certificate = array();
38
44 public function __construct($object)
45 {
46 $this->object = $object;
47 parent::__construct();
48 }
49
55 public function getCertificatePath()
56 {
57 return CLIENT_WEB_DIR . "/course/certificates/" . $this->object->getId() . "/";
58 }
59
67 {
68 $vars = $this->getBaseVariablesForPreview(false);
69 $vars["COURSE_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/User/classes/class.ilObjUser.php';
91 $user_data = ilObjUser::_lookupFields($user_id);
92
93 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
94 $completion_date = ilCourseParticipants::getDateTimeOfPassed($this->object->getId(), $user_id);
95
96 $vars = $this->getBaseVariablesForPresentation($user_data, null, $completion_date);
97 $vars["COURSE_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
98
99 $insert_tags = array();
100 foreach ($vars as $id => $caption) {
101 $insert_tags["[" . $id . "]"] = $caption;
102 }
103 return $insert_tags;
104 }
105
113 {
114 $vars = $this->getBaseVariablesDescription(false);
115 $vars["COURSE_TITLE"] = $this->lng->txt("crs_title");
116
117 $template = new ilTemplate("tpl.il_as_tst_certificate_edit.html", true, true, "Modules/Test");
118 $template->setCurrentBlock("items");
119 foreach ($vars as $id => $caption) {
120 $template->setVariable("ID", $id);
121 $template->setVariable("TXT", $caption);
122 $template->parseCurrentBlock();
123 }
124
125 $template->setVariable("PH_INTRODUCTION", $this->lng->txt("certificate_ph_introduction"));
126
127 return $template->get();
128 }
129
136 public function getAdapterType()
137 {
138 return "course";
139 }
140
147 public function getCertificateID()
148 {
149 return $this->object->getId();
150 }
151
160 public static function _preloadListData($a_usr_ids, $a_obj_ids)
161 {
162 if (!is_array($a_usr_ids)) {
163 $a_usr_ids = array($a_usr_ids);
164 }
165 if (!is_array($a_obj_ids)) {
166 $a_obj_ids = array($a_obj_ids);
167 }
168 foreach ($a_usr_ids as $usr_id) {
169 foreach ($a_obj_ids as $obj_id) {
170 self::$has_certificate[$usr_id][$obj_id] = false;
171 }
172 }
173
174 include_once "Services/Certificate/classes/class.ilCertificate.php";
176 $obj_active = ilCertificate::areObjectsActive($a_obj_ids);
177
178 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
180 foreach ($data as $rec) {
181 if ($obj_active[$rec["obj_id"]]) {
182 self::$has_certificate[$rec["usr_id"]][$rec["obj_id"]] = true;
183 }
184 }
185 }
186 }
187
197 public static function _hasUserCertificate($a_usr_id, $a_obj_id)
198 {
199 self::_preloadListData($a_usr_id, $a_obj_id);
200
201 if (isset(self::$has_certificate[$a_usr_id][$a_obj_id])) {
202 return self::$has_certificate[$a_usr_id][$a_obj_id];
203 }
204 return false;
205 }
206}
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.
getBaseVariablesDescription($a_enable_last_access=true, $a_enable_completion_date=true)
Get variable descriptions.
getCertificateVariablesDescription()
Returns a description of the available certificate parameters.
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.
getCertificateVariablesForPreview()
Returns an array containing all variables and values which can be exchanged in the certificate.
static _preloadListData($a_usr_ids, $a_obj_ids)
Get certificate/passed status for all given objects and users.
getCertificatePath()
Returns the certificate path (with a trailing path separator)
static _hasUserCertificate($a_usr_id, $a_obj_id)
Check if user has certificate for course.
__construct($object)
ilTestCertificateAdapter contructor
getCertificateID()
Returns a certificate ID This value will be used to generate unique file names for the certificates.
static getDateTimeOfPassed($a_obj_id, $a_usr_id)
static getPassedUsersForObjects(array $a_obj_ids, array $a_usr_ids)
static _lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
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
$data
Definition: bench.php:6