ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjTestVerification.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 = "tstv";
20  }
21 
22  protected function getPropertyMap()
23  {
24  return array("issued_on" => self::TYPE_DATE,
25  "file" => self::TYPE_STRING
26  /*
27  "success" => self::TYPE_BOOL,
28  "result" => self::TYPE_STRING,
29  "mark" => self::TYPE_STRING
30  */
31  );
32  }
33 
40  public static function createFromTest(ilObjTest $a_test, $a_user_id)
41  {
42  global $lng;
43 
44  $lng->loadLanguageModule("wsp");
45 
46  $newObj = new self();
47  $newObj->setTitle($lng->txt("wsp_type_tstv")." \"".$a_test->getTitle()."\"");
48  $newObj->setDescription($a_test->getDescription());
49 
50  $active_id = $a_test->getActiveIdOfUser($a_user_id);
51  $pass = ilObjTest::_getResultPass($active_id);
52 
53  $date = $a_test->getPassFinishDate($active_id, $pass);
54  $newObj->setProperty("issued_on", new ilDate($date, IL_CAL_UNIX));
55 
56  // create certificate
57  include_once "Services/Certificate/classes/class.ilCertificate.php";
58  include_once "Modules/Test/classes/class.ilTestCertificateAdapter.php";
59  $certificate = new ilCertificate(new ilTestCertificateAdapter($a_test));
60  $certificate = $certificate->outCertificate(array("active_id" => $active_id, "pass" => $pass), false);
61 
62  // save pdf file
63  if($certificate)
64  {
65  // we need the object id for storing the certificate file
66  $newObj->create();
67 
68  $path = self::initStorage($newObj->getId(), "certificate");
69 
70  $file_name = "tst_".$a_test->getId()."_".$a_user_id."_".$active_id.".pdf";
71  if(file_put_contents($path.$file_name, $certificate))
72  {
73  $newObj->setProperty("file", $file_name);
74  $newObj->update();
75 
76  return $newObj;
77  }
78 
79  // file creation failed, so remove to object, too
80  $newObj->delete();
81  }
82  }
83 }
84 
85 ?>