/** * Import relevant properties from given course * * @param ilObjCourse $a_course * @return object */ public static function createFromCourse(ilObjCourse $a_course, $a_user_id) { global $lng; $lng->loadLanguageModule("crs"); $newObj = new self(); $newObj->setTitle($a_course->getTitle()); $newObj->setDescription($a_course->getDescription()); include_once "Services/Tracking/classes/class.ilLPMarks.php"; $lp_marks = new ilLPMarks($a_course->getId(), $a_user_id); $newObj->setProperty("issued_on", new ilDate($lp_marks->getStatusChanged(), IL_CAL_DATETIME)); // create certificate include_once "Services/Certificate/classes/class.ilCertificate.php"; include_once "Modules/Course/classes/class.ilCourseCertificateAdapter.php"; $certificate = new ilCertificate(new ilCourseCertificateAdapter($a_course)); $certificate = $certificate->outCertificate(array("user_id" => $a_user_id), false); // save pdf file if ($certificate) { // we need the object id for storing the certificate file $newObj->create(); $path = self::initStorage($newObj->getId(), "certificate"); $file_name = "crs_" . $a_course->getId() . "_" . $a_user_id . ".pdf"; if (file_put_contents($path . $file_name, $certificate)) { $newObj->setProperty("file", $file_name); $newObj->update(); return $newObj; } // file creation failed, so remove to object, too $newObj->delete(); } }
public function getUserCourse($courseId) { global $ilUser, $ilObjDataCache; $this->log($courseId); $items = ilParticipants::_getMembershipByType($ilUser->getId(), 'crs'); foreach ($items as $obj_id) { $this->log($obj_id . " :: " . $courseId); if ($obj_id == $courseId) { $crs = new ilObjCourse($obj_id, false); $crs->read(); $title = $crs->getTitle(); $description = $crs->getDescription(); // $this->log($crs->getOfflineStatus()); if ($crs->getOfflineStatus() == 1) { // skip offline courses continue; } $course = array("id" => $obj_id, "title" => $title, "description" => $description); // 2 get course objects $item_references = ilObject::_getAllReferences($obj_id); reset($item_references); if (strcmp($this->iliasVersion, "4.2") === 0) { foreach ($item_references as $ref_id => $x) { // Antique Ilias // For some strange reason remains the $crs->getRefId() remains empty $crs = new ilObjCourse($ref_id); // TODO: Verify that the course is online // TODO: If the course is offline, check if the user is admin. // TODO: skip offline student courses require_once 'Modules/Course/classes/class.ilCourseItems.php'; $courseItems = new ilCourseItems($crs->getRefId(), 0, $ilUser->getId()); $courseItemList = $courseItems->getAllItems(); $course["content-type"] = $this->mapItemTypes($courseItemList, false); break; } } else { // Modern Ilias foreach ($item_references as $ref_id => $x) { $crs = new ilObjCourse($ref_id); // TODO: Verify that the course is online // TODO: If the course is offline, check if the user is admin. // TODO: skip offline student courses $courseItemList = $crs->getSubItems(); // TODO check with Ilias 4.4 and 4.3 // $this->log(">>> IL >>> " . json_encode($courseItemList["_all"])); $course["content-type"] = $this->mapItemTypes($courseItemList, true); } } return $course; } } return null; }
/** * Set Course title and icon in header * */ protected function initHeader() { $lgui = ilObjectListGUIFactory::_getListGUIByType($this->crs->getType()); $this->tpl->setTitle($this->crs->getTitle()); $this->tpl->setDescription($this->crs->getDescription()); if ($this->crs->getOfflineStatus()) { $this->tpl->setAlertProperties($lgui->getAlertProperties()); } $this->tpl->setTitleIcon(ilUtil::getTypeIconPath('crs', $this->crs->getId(), 'big')); $this->ctrl->setParameterByClass('ilrepositorygui', 'ref_id', $this->ref_id); $this->tabs->setBackTarget($this->pl->txt('back_to_course'), $this->ctrl->getLinkTargetByClass('ilrepositorygui')); }