/** * 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')); }
/** * Parse general placeholders, mostly certificate data * * @param ilObjCourse $course * @return array */ protected function parseGeneralPlaceholders(ilObjCourse $course) { $utc = ilCertificateConfig::get('time_format_utc'); $cert_valid_from = strtotime($this->certificate->getValidFrom()); $cert_valid_to = strtotime($this->certificate->getValidTo()); if ($utc) { // fix for timezone issue: when converting a mysql date into a timestamp and then into another timezone, its possible the date changes (because the start date is the first second of the day). // We now add 12*60*60 seconds to be in the middle of the day $cert_valid_to += srCertificate::TIME_ZONE_CORRECTION; $cert_valid_from += srCertificate::TIME_ZONE_CORRECTION; } $placeholder = array('DATE' => $this->formatDate('DATE'), 'DATETIME' => $this->formatDateTime('DATETIME'), 'TIMESTAMP' => $utc ? strtotime(gmdate('Y-m-d H:i:s')) : time(), 'CERT_FILE_NAME' => $this->certificate->getFilename(), 'CERT_FILE_VERSION' => $this->certificate->getFileVersion(), 'CERT_VALID_FROM' => $this->certificate->getValidFrom() == '' ? $this->pl->txt('unlimited') : $this->formatDate('CERT_VALID_FROM', $cert_valid_from), 'CERT_VALID_TO' => $this->certificate->getValidTo() == '' ? $this->pl->txt('unlimited') : $this->formatDate('CERT_VALID_TO', $cert_valid_to), 'CERT_ID' => $this->certificate->getId(), 'CERT_TEMPLATE_PATH' => $this->certificate->getDefinition()->getType()->getCertificateTemplatesPath(), 'CERT_TYPE_TITLE' => $this->certificate->getDefinition()->getType()->getTitle(), 'CERT_TYPE_DESCRIPTION' => $this->certificate->getDefinition()->getType()->getDescription(), 'COURSE_TITLE' => $course->getTitle()); return $placeholder; }