ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
24 include_once "./Services/Certificate/classes/class.ilCertificateAdapter.php";
25 
34 {
35  protected $object;
36  protected static $has_certificate = array();
37 
43  function __construct(&$object)
44  {
45  global $lng;
46  $this->object =& $object;
47  $lng->loadLanguageModule('certificate');
48  }
49 
55  public function getCertificatePath()
56  {
57  return CLIENT_WEB_DIR . "/course/certificates/" . $this->object->getId() . "/";
58  }
59 
67  {
68  global $lng;
69 
70  $vars = $this->getBaseVariablesForPreview(false);
71  $vars["COURSE_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
72 
73  $insert_tags = array();
74  foreach($vars as $id => $caption)
75  {
76  $insert_tags["[".$id."]"] = $caption;
77  }
78  return $insert_tags;
79  }
80 
89  public function getCertificateVariablesForPresentation($params = array())
90  {
91  global $lng;
92 
93  $user_id = $params["user_id"];
94 
95  include_once './Services/User/classes/class.ilObjUser.php';
96  $user_data = ilObjUser::_lookupFields($user_id);
97 
98  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
99  $completion_date = ilCourseParticipants::getDateTimeOfPassed($this->object->getId(), $user_id);
100 
101  $vars = $this->getBaseVariablesForPresentation($user_data, null, $completion_date);
102  $vars["COURSE_TITLE"] = ilUtil::prepareFormOutput($this->object->getTitle());
103 
104  $insert_tags = array();
105  foreach($vars as $id => $caption)
106  {
107  $insert_tags["[".$id."]"] = $caption;
108  }
109  return $insert_tags;
110  }
111 
119  {
120  global $lng;
121 
122  $vars = $this->getBaseVariablesDescription(false);
123  $vars["COURSE_TITLE"] = $lng->txt("crs_title");
124 
125  $template = new ilTemplate("tpl.il_as_tst_certificate_edit.html", TRUE, TRUE, "Modules/Test");
126  $template->setCurrentBlock("items");
127  foreach($vars as $id => $caption)
128  {
129  $template->setVariable("ID", $id);
130  $template->setVariable("TXT", $caption);
131  $template->parseCurrentBlock();
132  }
133 
134  $template->setVariable("PH_INTRODUCTION", $lng->txt("certificate_ph_introduction"));
135 
136  return $template->get();
137  }
138 
145  public function getAdapterType()
146  {
147  return "course";
148  }
149 
156  public function getCertificateID()
157  {
158  return $this->object->getId();
159  }
160 
169  static function _preloadListData($a_usr_ids, $a_obj_ids)
170  {
171  global $ilDB;
172 
173  if (!is_array($a_usr_ids))
174  {
175  $a_usr_ids = array($a_usr_ids);
176  }
177  if (!is_array($a_obj_ids))
178  {
179  $a_obj_ids = array($a_obj_ids);
180  }
181  foreach ($a_usr_ids as $usr_id)
182  {
183  foreach ($a_obj_ids as $obj_id)
184  {
185  self::$has_certificate[$usr_id][$obj_id] = false;
186  }
187  }
188 
189  include_once "Services/Certificate/classes/class.ilCertificate.php";
191  {
192  $obj_active = ilCertificate::areObjectsActive($a_obj_ids);
193 
194  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
195  $data = ilCourseParticipants::getPassedUsersForObjects($a_obj_ids, $a_usr_ids);
196  foreach($data as $rec)
197  {
198  if($obj_active[$rec["obj_id"]])
199  {
200  self::$has_certificate[$rec["usr_id"]][$rec["obj_id"]] = true;
201  }
202  }
203  }
204  }
205 
215  static function _hasUserCertificate($a_usr_id, $a_obj_id)
216  {
217  if (isset(self::$has_certificate[$a_usr_id][$a_obj_id]))
218  {
219  return self::$has_certificate[$a_usr_id][$a_obj_id];
220  }
221 
222  // obsolete?
223  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
224  return ilCourseParticipants::getDateTimeOfPassed($a_obj_id, $a_usr_id);
225  }
226 }
227 
228 ?>