1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4include_once('./Services/Object/classes/class.ilObject2GUI.php'); 5 6/** 7* GUI class for test verification 8* 9* @author Jörg Lützenkirchen <luetzenkirchen@leifos.com> 10* @version $Id$ 11* 12* @ilCtrl_Calls ilObjTestVerificationGUI: ilWorkspaceAccessGUI 13* 14* @ingroup ModulesTest 15*/ 16class ilObjTestVerificationGUI extends ilObject2GUI 17{ 18 public function getType() 19 { 20 return "tstv"; 21 } 22 23 /** 24 * List all tests in which current user participated 25 */ 26 public function create() 27 { 28 global $DIC; 29 $ilTabs = $DIC['ilTabs']; 30 31 if ($this->id_type == self::WORKSPACE_NODE_ID) { 32 include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php"; 33 if (!ilDiskQuotaHandler::isUploadPossible()) { 34 $this->lng->loadLanguageModule("file"); 35 ilUtil::sendFailure($this->lng->txt("personal_resources_quota_exceeded_warning"), true); 36 $this->ctrl->redirect($this, "cancel"); 37 } 38 } 39 40 $this->lng->loadLanguageModule("tstv"); 41 42 $ilTabs->setBackTarget( 43 $this->lng->txt("back"), 44 $this->ctrl->getLinkTarget($this, "cancel") 45 ); 46 47 include_once "Modules/Test/classes/tables/class.ilTestVerificationTableGUI.php"; 48 $table = new ilTestVerificationTableGUI($this, "create"); 49 $this->tpl->setContent($table->getHTML()); 50 } 51 52 /** 53 * create new instance and save it 54 */ 55 public function save() 56 { 57 global $DIC; 58 $ilUser = $DIC['ilUser']; 59 60 $objectId = $_REQUEST["tst_id"]; 61 if ($objectId) { 62 $certificateVerificationFileService = new ilCertificateVerificationFileService( 63 $DIC->language(), 64 $DIC->database(), 65 $DIC->logger()->root(), 66 new ilCertificateVerificationClassMap() 67 ); 68 69 $userCertificateRepository = new ilUserCertificateRepository(); 70 71 $userCertificatePresentation = $userCertificateRepository->fetchActiveCertificateForPresentation( 72 (int) $ilUser->getId(), 73 (int) $objectId 74 ); 75 76 try { 77 $newObj = $certificateVerificationFileService->createFile($userCertificatePresentation); 78 } catch (\Exception $exception) { 79 ilUtil::sendFailure($this->lng->txt('error_creating_certificate_pdf')); 80 return $this->create(); 81 } 82 83 if ($newObj) { 84 $parent_id = $this->node_id; 85 $this->node_id = null; 86 $this->putObjectInTree($newObj, $parent_id); 87 88 $this->afterSave($newObj); 89 } else { 90 ilUtil::sendFailure($this->lng->txt("msg_failed")); 91 } 92 } else { 93 ilUtil::sendFailure($this->lng->txt("select_one")); 94 } 95 $this->create(); 96 } 97 98 public function deliver() 99 { 100 $file = $this->object->getFilePath(); 101 if ($file) { 102 ilUtil::deliverFile($file, $this->object->getTitle() . ".pdf"); 103 } 104 } 105 106 /** 107 * Render content 108 * 109 * @param bool $a_return 110 * @param string $a_url 111 */ 112 public function render($a_return = false, $a_url = false) 113 { 114 global $DIC; 115 $ilUser = $DIC['ilUser']; 116 $lng = $DIC['lng']; 117 118 if (!$a_return) { 119 $this->deliver(); 120 } else { 121 $tree = new ilWorkspaceTree($ilUser->getId()); 122 $wsp_id = $tree->lookupNodeId($this->object->getId()); 123 $caption = $lng->txt("wsp_type_tstv") . ' "' . $this->object->getTitle() . '"'; 124 125 $valid = true; 126 if (!file_exists($this->object->getFilePath())) { 127 $valid = false; 128 $message = $lng->txt("url_not_found"); 129 } elseif (!$a_url) { 130 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php"; 131 $access_handler = new ilWorkspaceAccessHandler($tree); 132 if (!$access_handler->checkAccess("read", "", $wsp_id)) { 133 $valid = false; 134 $message = $lng->txt("permission_denied"); 135 } 136 } 137 138 if ($valid) { 139 if (!$a_url) { 140 $a_url = $this->getAccessHandler()->getGotoLink($wsp_id, $this->object->getId()); 141 } 142 return '<div><a href="' . $a_url . '">' . $caption . '</a></div>'; 143 } else { 144 return '<div>' . $caption . ' (' . $message . ')</div>'; 145 } 146 } 147 } 148 149 public function downloadFromPortfolioPage(ilPortfolioPage $a_page) 150 { 151 global $DIC; 152 $ilErr = $DIC['ilErr']; 153 154 include_once "Services/COPage/classes/class.ilPCVerification.php"; 155 if (ilPCVerification::isInPortfolioPage($a_page, $this->object->getType(), $this->object->getId())) { 156 $this->deliver(); 157 } 158 159 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE); 160 } 161 162 public static function _goto($a_target) 163 { 164 $id = explode("_", $a_target); 165 166 $_GET["baseClass"] = "ilsharedresourceGUI"; 167 $_GET["wsp_id"] = $id[0]; 168 include("ilias.php"); 169 exit; 170 } 171} 172