function addCourse($sid, $target_id, $crs_xml) { $this->initAuth($sid); $this->initIlias(); if (!$this->__checkSession($sid)) { return $this->__raiseError($this->__getMessage(), $this->__getMessageCode()); } if (!is_numeric($target_id)) { return $this->__raiseError('No valid target id given. Please choose an existing reference id of an ILIAS category', 'Client'); } global $rbacsystem; if (!($target_obj =& ilObjectFactory::getInstanceByRefId($target_id, false))) { return $this->__raiseError('No valid target given.', 'Client'); } if (ilObject::_isInTrash($target_id)) { return $this->__raiseError("Parent with ID {$target_id} has been deleted.", 'CLIENT_OBJECT_DELETED'); } if (!$rbacsystem->checkAccess('create', $target_id, 'crs')) { return $this->__raiseError('Check access failed. No permission to create courses', 'Server'); } // Start import include_once "Modules/Course/classes/class.ilObjCourse.php"; $newObj = new ilObjCourse(); $newObj->setType('crs'); $newObj->setTitle('dummy'); $newObj->setDescription(""); $newObj->create(true); // true for upload $newObj->createReference(); $newObj->putInTree($target_id); $newObj->setPermissions($target_id); include_once 'Modules/Course/classes/class.ilCourseXMLParser.php'; $xml_parser = new ilCourseXMLParser($newObj); $xml_parser->setXMLContent($crs_xml); $xml_parser->startParsing(); return $newObj->getRefId() ? $newObj->getRefId() : "0"; }
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; }
/** * 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); }