ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjCourseVerification.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once ('./Services/Verification/classes/class.ilVerificationObject.php');
5 
16 {
17  protected function initType()
18  {
19  $this->type = "crsv";
20  }
21 
22  protected function getPropertyMap()
23  {
24  return array("issued_on" => self::TYPE_DATE,
25  "file" => self::TYPE_STRING
26  );
27  }
28 
35  public static function createFromCourse(ilObjCourse $a_course, $a_user_id)
36  {
37  global $lng;
38 
39  $lng->loadLanguageModule("crs");
40 
41  $newObj = new self();
42  $newObj->setTitle($a_course->getTitle());
43  $newObj->setDescription($a_course->getDescription());
44 
45  include_once "Services/Tracking/classes/class.ilLPMarks.php";
46  $lp_marks = new ilLPMarks($a_course->getId(), $a_user_id);
47  $newObj->setProperty("issued_on",
48  new ilDate($lp_marks->getStatusChanged(), IL_CAL_DATETIME));
49 
50  // create certificate
51  include_once "Services/Certificate/classes/class.ilCertificate.php";
52  include_once "Modules/Course/classes/class.ilCourseCertificateAdapter.php";
53  $certificate = new ilCertificate(new ilCourseCertificateAdapter($a_course));
54  $certificate = $certificate->outCertificate(array("user_id" => $a_user_id), false);
55 
56  // save pdf file
57  if($certificate)
58  {
59  // we need the object id for storing the certificate file
60  $newObj->create();
61 
62  $path = self::initStorage($newObj->getId(), "certificate");
63 
64  $file_name = "crs_".$a_course->getId()."_".$a_user_id.".pdf";
65  if(file_put_contents($path.$file_name, $certificate))
66  {
67  $newObj->setProperty("file", $file_name);
68  $newObj->update();
69 
70  return $newObj;
71  }
72 
73  // file creation failed, so remove to object, too
74  $newObj->delete();
75  }
76  }
77 }
78 
79 ?>