/** * 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(); } }
/** * 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')); }
/** * Returns the parent object of the role folder object which contains the specified role. */ function getCourseMembersObjectForRole($a_role_id) { global $rbacreview, $rbacadmin, $tree; if (array_key_exists($a_role_id . '_courseMembersObject', $this->localRoleCache)) { return $this->localRoleCache[$a_role_id . '_courseMembersObject']; } else { require_once "Modules/Course/classes/class.ilObjCourse.php"; require_once "Modules/Course/classes/class.ilCourseParticipants.php"; $rolf_refs = $rbacreview->getFoldersAssignedToRole($a_role_id, true); $course_ref = $tree->getParentId($rolf_refs[0]); $course_obj = new ilObjCourse($course_ref, true); $crsmembers_obj = ilCourseParticipants::_getInstanceByObjId($course_obj->getId()); $this->localRoleCache[$a_role_id . '_courseMembersObject'] = $crsmembers_obj; return $crsmembers_obj; } }
/** * Return all Placeholders of Learning Progress data * * @param ilObjCourse $course * @param ilObjUser $user * @return array */ protected function parseLearningProgressPlaceholders(ilObjCourse $course, ilObjUser $user) { $passed_datetime = ilCourseParticipants::getDateTimeOfPassed($course->getId(), $user->getId()); $lp_fields = array('first_access', 'last_access', 'percentage', 'status', 'read_count', 'childs_spent_seconds'); $lp_data = ilTrQuery::getObjectsDataForUser($user->getId(), $course->getId(), $course->getRefId(), '', '', 0, 9999, null, $lp_fields); $lp_avg = $this->buildAvgPercentageOfCourseObjects($lp_data); $lp_crs = array(); $max_last_access = 0; foreach ($lp_data['set'] as $v) { if ($v['type'] == 'crs') { $lp_crs = $v; $lp_crs['first_access'] = strtotime($v['first_access']); // First access is not stored as UNIX timestamp... } if ($v['last_access'] > $max_last_access) { $max_last_access = $v['last_access']; } } $lp_crs['last_access'] = $max_last_access; // calculates spent time different for scorm modules if enabled in config /** @var $cert_def srCertificateDefinition */ $cert_definition = $this->certificate->getDefinition(); if ($cert_definition->getScormTiming()) { $spent_seconds = 0; require_once './Services/Object/classes/class.ilObjectLP.php'; $ilScormLP = ilObjectLP::getInstance($course->getId()); /** * @var $ilLPCollection ilLPCollection */ $ilLPCollection = $ilScormLP->getCollectionInstance(); if ($ilLPCollection instanceof ilLPCollection) { foreach ($ilLPCollection->getItems() as $item) { $spent_seconds += $this->getSpentSeconds(ilObject::_lookupObjectId($item), $user->getId()); } } $lp_crs['childs_spent_seconds'] = $spent_seconds; } $lp_spent_time = $this->buildLpSpentTime($lp_crs); return array('DATE_COMPLETED' => $this->formatDate('DATE_COMPLETED', strtotime($passed_datetime)), 'DATETIME_COMPLETED' => $this->formatDateTime('DATETIME_COMPLETED', strtotime($passed_datetime)), 'LP_FIRST_ACCESS' => $this->formatDateTime('LP_FIRST_ACCESS', (int) $lp_crs['first_access']), 'LP_LAST_ACCESS' => $this->formatDateTime('LP_LAST_ACCESS', (int) $lp_crs['last_access']), 'LP_SPENT_TIME' => $lp_spent_time, 'LP_SPENT_SECONDS' => $lp_crs['childs_spent_seconds'], 'LP_READ_COUNT' => $lp_crs['read_count'], 'LP_STATUS' => $lp_crs['status'], 'LP_AVG_PERCENTAGE' => $lp_avg); }